News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Alarmclock

Started by six_L, January 16, 2005, 07:44:23 AM

Previous topic - Next topic

six_L

hello, all.
Newbie question .
I'm learning a simple alarmclock written by Ranma_at. Alarmclock: when alarm is reached it displays a messagebox and plays a sound. You can set up hour and minutes. Very basic.
I modified a little. when i first setted, it is fine. but second setting, it can't work.
help me.

regards.

.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
include \masm32\include\comctl32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\winmm.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\comctl32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\winmm.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.const
IDM_FILE_EXIT equ 10001
IDM_HELP_ABOUT equ 10101

IDC_IMG1 equ 1001
IDC_ICON2 equ 501
IDC_BTN1 equ 1002

;/* Alarm clock dialog */
IDD_DLG1 equ 2000
IDC_EDT1 equ 2002
IDC_EDT2 equ 2004
IDC_BTN2 equ 2005
IDC_BTN3 equ 2006
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
ClassName db 'DLGCLASS',0
MenuName db 'MyMenu',0
DlgName db 'MyDialog',0
AppName db 'Dialog as main',0
AboutMsg db 'MASM32 RadASM Dialog as main',13,10,'Copyright ?MASM32 2001',0

;/* Alarm clock variables */
setHour db 25d
setMinute db 61d
AlarmMessage db 'Time is Over !!!',0
AlarmCaption db 'Alarm successfull!',0

;/* Display system data and time setup */
time SYSTEMTIME<>
timeformat db "HH:mm:ss",0
dateformat db "yyyy.MM.dd",0
sbuffer db 100 dup (0)
dbuffer db 100 dup (0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
CommandLine dd ?
hWnd dd ?
hIcon dd ?
hImage dd ?
hIcon2 dd ?
;setHour db ?
;setMinute db ?

ThreadID DWORD ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
start:
invoke GetModuleHandle,NULL
mov    hInstance,eax
invoke GetCommandLine
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,DLGWINDOWEXTRA
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,500
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx,addr wc
invoke CreateDialogParam,hInstance,addr DlgName,NULL,addr WndProc,NULL
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
.while TRUE
invoke GetMessage,addr msg,NULL,0,0
.BREAK .if !eax
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
.endw
mov eax,msg.wParam
ret
WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ThreadProc PROC USES ecx Param:DWORD
local pCount:dword

push 0
pop pCount
Restart: invoke GetLocalTime,offset time
mov ax,time.wHour
.if al==setHour
mov ax,time.wMinute
.if al==setMinute
mov ax,time.wSecond
.if al<2    ; prohibitting PlaySound again in the minute
xyz:                             .if pCount < 3  ;PlaySound three times
;invoke MessageBox,NULL,offset AlarmMessage,offset AlarmCaption,MB_ICONINFORMATION
;couldnt test the soundplay feature, cause no soundcard here :-( in my office
invoke PlaySound,502,hInstance,SND_RESOURCE
inc pCount
jmp xyz
.endif
.endif
ret
.endif
.endif
jmp Restart

ThreadProc ENDP
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SetTimeProc proc hSetTime:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

.if uMsg==WM_CLOSE
invoke EndDialog,hSetTime,NULL
ret
.elseif uMsg==WM_INITDIALOG
invoke SendDlgItemMessage,hSetTime,IDC_EDT1,EM_LIMITTEXT,2,0
invoke SendDlgItemMessage,hSetTime,IDC_EDT2,EM_LIMITTEXT,2,0

.elseif uMsg==WM_COMMAND
mov eax,wParam
.if ax==IDC_BTN2
invoke GetDlgItemInt,hSetTime,IDC_EDT1,NULL,FALSE
mov setHour,al
invoke GetDlgItemInt,hSetTime,IDC_EDT2,NULL,FALSE
mov setMinute,al
invoke SendMessage,hSetTime,WM_CLOSE,NULL,NULL
.elseif ax==IDC_BTN3
invoke SendMessage,hSetTime,WM_CLOSE,NULL,NULL
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
SetTimeProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,uMsg
.if eax==WM_INITDIALOG
push hWin
pop hWnd
invoke LoadIcon,hInstance,500
mov hIcon,eax
invoke SendMessage,hWin,WM_SETICON,NULL,hIcon

;/* setup Image on our form */
invoke GetDlgItem,hWin,1001
mov hImage, eax
invoke LoadIcon,hInstance,IDC_ICON2
mov hIcon2, eax
invoke SendMessage,hImage,STM_SETIMAGE,IMAGE_ICON,hIcon2

;/* Here is what we need to display date and time */
invoke SetTimer,hWin,0,1000, 0  ;Timer setup (in milliseconds)
;/* END of what we need to display date and time */

;/* Here is what we need to display date and time */
.elseif eax==WM_TIMER
invoke GetLocalTime, offset time
invoke GetDateFormat, LOCALE_USER_DEFAULT, NULL,offset time,offset dateformat, offset dbuffer, sizeof dbuffer
invoke GetTimeFormat, LOCALE_USER_DEFAULT,NULL,offset time, offset timeformat, offset sbuffer, sizeof sbuffer

invoke SendDlgItemMessage,hWin,1003,WM_SETTEXT,0,offset sbuffer
invoke SendDlgItemMessage,hWin,1004,WM_SETTEXT,0,offset dbuffer
;/* END of what we need to display date and time */

.elseif eax==WM_COMMAND
mov eax,wParam
and eax,0FFFFh
.if eax==IDM_FILE_EXIT
invoke SendMessage,hWin,WM_CLOSE,0,0
.elseif eax==IDM_HELP_ABOUT
invoke ShellAbout,hWin,addr AppName,addr AboutMsg,hIcon
.elseif eax==IDC_BTN1
invoke CreateDialogParam,hInstance,IDD_DLG1,hWin,offset SetTimeProc,FALSE
;mov  eax,OFFSET ThreadProc
invoke CreateThread,NULL,NULL,addr ThreadProc,\
                                        NULL,IDLE_PRIORITY_CLASS,\
                                        ADDR ThreadID
invoke SetThreadPriority,eax,THREAD_PRIORITY_LOWEST
invoke CloseHandle,eax
.endif

.elseif eax==WM_CLOSE
;*/ we could kill the timer here... */
invoke KillTimer,hWin,0 ;cancel the 400ms timer for updating ICO.
invoke DestroyWindow,hWin
.elseif uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.endif
xor    eax,eax
ret
WndProc endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

end start

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



[attachment deleted by admin]
regards

Robert Collins

I copied your source code, assembled it. I can't see that it does anything-----it doesn't show it's window. 

pbrennick

#2
Robert,
In order to see the window you will need to build an RC file.  Since he doesn't include it, you can extract the resources from his EXE and then build the complete project.   I am including a zip file with the resources so you can play with it.

Paul


[attachment deleted by admin]

Robert Collins

Thanks Paul.

That's OK for you but I don't have the slightest clue how to do that.

pbrennick

Robert,
I modified the previous post and included a working zip for you.

Paul

Robert Collins

Paul,

Thanks alot. I didn't even see it when I read your post (duh).

six_L

#6
thanks all who responded it.
I'm glad for you doing, since the alarm_clock still isn't a vapid subject.

i modify old alarm_clock some :
1. added the second  restricting which  forbided the ringin wav again in the same minute, when you click "set new alarm" button.
2. added the alarm ringin playing three times.
;=======================================
Robert Collins,
you may extract the resources from almt_1.EXE with the eYe software, i tested almt_1.EXE on windows xp sp2. its working isn't fine which I think.

;=======================================
pbrennick,

  • when i set a breakpoint in the Thread of almt_1.exe, the OLLYDBG can't go on. that's why?
  • the question of your alarm clock is existing.


best regards.
regards