;-timer.asm------------------------------------------------------------------ ; x86 - Dos & Win32 - Assembly Language Programming ; ; ; ; Written by: John A Lyons ; ; Email : sysop@megablast.8k.com ; ; Page : http://www.asmsource.8k.com/ ; ; Compiler : Masm32 v6.13 Microsoft Macro Assembler ; ; Date : 10-Feb-2001 ; ; Purpose : Creates a timer event, that invokes a WM_TIMER message ; ; every so often. This program also changes the title of the ; ; program, so that count is indicated in the taskbar ; ; ; ;---------------------------------------------------------------------------- ; Compile with nmake ; .386 .MODEL FLAT , STDCALL include windows.inc include user32.inc include kernel32.inc include gdi32.inc includelib user32.lib includelib kernel32.lib includelib gdi32.lib EXTRN wsprintfA:PROC .const ID_TIMER equ 400 IDI_ICON1 equ 5 .data ClassName db "SimpleWinClass",0 AppName db "Timer!",0 message db "Timer has begun",0 mmem db "Count %lu",0 count DWORD 0 hInstance HINSTANCE ? CommandLine LPSTR ? hwnd HWND ? temp db 100 dup(0) .code WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD LOCAL wc:WNDCLASSEX LOCAL msg:MSG mov wc.cbSize,SIZEOF WNDCLASSEX mov wc.style, CS_BYTEALIGNWINDOW mov wc.lpfnWndProc, OFFSET WndProc mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL push hInstance pop wc.hInstance mov wc.hbrBackground,COLOR_WINDOW+1 mov wc.lpszMenuName,NULL mov wc.lpszClassName,OFFSET ClassName ;invoke LoadIcon,NULL,IDI_APPLICATION invoke LoadIcon, hInstance, IDI_ICON1 mov wc.hIcon,eax mov wc.hIconSm,0 invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax invoke RegisterClassEx, addr wc INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT, 150,50, ;size NULL,NULL,\ hInst,NULL mov hwnd,eax 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 WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM LOCAL hdc:HDC LOCAL ps:PAINTSTRUCT mov eax,uMsg .IF eax==WM_DESTROY invoke KillTimer, hWnd, ID_TIMER invoke PostQuitMessage,NULL .ELSEIF eax==WM_PAINT invoke BeginPaint,hWnd, ADDR ps mov hdc,eax invoke TextOut,hdc,0,0,ADDR message,SIZEOF message-1 invoke EndPaint,hWnd, ADDR ps invoke SetTimer, hWnd, ID_TIMER, 100, 0 .ELSEIF eax==WM_TIMER mov eax,[count] inc count push eax push offset mmem lea eax,temp push eax mov ebx,0 call wsprintfA invoke SetWindowText,hWnd,ADDR temp .ELSE invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .ENDIF xor eax,eax ret WndProc endp start: invoke GetModuleHandle, NULL mov hInstance,eax invoke GetCommandLine invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT invoke ExitProcess,eax end start