We all know that in the 8086 Assembly, we can directly use the Int 8 h interrupt to achieve the timing purpose. Obviously, Win32
Programming will not directly interrupt user operations. Windows provides a timer for the same purpose.
When you need to use a timer, you need to apply to Windows. When settimer ends, you need to release killtmer.
It should be noted that the windows timer is still based on clock interruption, so the accuracy is 55 ms. If you set
If an interruption occurs at any time, a certain error may exist.
For usage, see the code:
I. Resource file Definition
# Include <resource. h> # definedlg_main1 # defineico_11 # defineico_22 # define "1.ico" ico_2icon" 2.ico" success, 50,113, fail | ws_popup | ws_visible | ws_caption | timer "timer example" font 9, "icon "{icon ico_1, idc_seticon, 8, 9, 18, 21 ltext "count:",-, 16, 25, 10 ltext "", idc_count, 40, 10}
Ii. Subject Code
.386.modelflat,stdcalloptioncasemap:noneincludewindows.incincludeuser32.incincludelibuser32.libincludekernel32.incincludelibkernel32.libID_TIMER1equ1ID_TIMER2equ2ICO_1equ1ICO_2equ2DLG_MAINequ1IDC_SETICONequ100IDC_COUNTequ101.datahInstancedd?hWinMaindd?dwCountdd?idTimerdd?.code_ProcTimerproc_hWnd,uMsg,_idEvent,_dwTimepushadinvokeGetDlgItemInt,hWinMain,IDC_COUNT,NULL,FALSEinceaxinvokeSetDlgItemInt,hWinMain,IDC_COUNT,eax,FALSEpopadret_ProcTimerendp_ProcDlgMainprocusesebx edi esi,hWnd,uMsg,wParam,lParammoveax,uMsg.ifeax == WM_TIMERmoveax,wParam.ifeax == ID_TIMER1incdwCountmoveax,dwCountandeax,1inceaxinvokeLoadIcon,hInstance,eaxinvokeSendDlgItemMessage,hWnd,\IDC_SETICON,STM_SETIMAGE,\IMAGE_ICON,eax.elseifeax == ID_TIMER2invokeMessageBeep,-1.endif.elseifeax == WM_INITDIALOGpushhWndpophWinMaininvokeSetTimer,hWnd,ID_TIMER1,250,NULLinvokeSetTimer,hWnd,ID_TIMER2,2000,NULLinvokeSetTimer,NULL,NULL,1000,addr _ProcTimermovidTimer,eax.elseifeax == WM_CLOSEinvokeKillTimer,hWnd,ID_TIMER1invokeKillTimer,hWnd,ID_TIMER2invokeKillTimer,NULL,idTimerinvokeEndDialog,hWnd,NULL.elsemoveax,FALSEret.endifmoveax,TRUEret_ProcDlgMainendpstart:invokeGetModuleHandle,NULLmovhInstance,eaxinvokeDialogBoxParam,hInstance,DLG_MAIN,\NULL,offset _ProcDlgMain,NULLinvokeExitProcess,NULLendstart
Iii. Running
4. Download resource files
1. ICO 2.ico