Article 6 windows Timer

Source: Internet
Author: User

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.