Win32 assembly tutorial Ten timer application

zhaozj2021-02-08  237

-------------------------------------------------- ------------------------------ Download All Source Programs of this section here Overview Windows Timer is an input device. It is periodically notified the application at the specified interval. It can be used to send a WM_TIMER message to the specified window or call the specified process to execute the user's program. The timer's application mainly includes some places: clock procedures - obviously, this is the most direct application of timers. Multi-task - If the program has a large amount of data processing, in addition to multi-threaded approach, you can use the timer to process a small piece of content in each timer message. The condition of the timing display program - Timer is equivalent to the program that hooks in the INT 1Ch in the DOS programming, which can schedule the program to run, such as the amount of content sent, receive more content, etc. Wait. The use of timers in the game program can eliminate errors caused by the delay in different processors to hold speeds. For data stream processing - in the playback of audio, video, you need to process a segment of data over a period of time. In general, the only way to implement accuracy in DOS is to handle the program in the int 1ch clock interrupt, but you must comply with a lot of specifications, and in Windows Timers, you can use the setTimer function to assign more than one Timer, for example, in your text editing program, you can use a 1 second timer to display the clock in the status bar while assigning a 10-minute timer to implement the function of the timing. The timer is actually a extension of Windows to the clock interrupt. Its essence is still based on the clock interrupt, so you can't set the interval of the timer to 55 milliseconds, in addition, the accuracy of the timer is also 55 milliseconds Multiple, for example, you set a 1 second timer, which actually happened at every 989 milliseconds. And use the clock interrupt in DOS, Windows Timer has some points below: In DOS, your program may be interrupted by int 1ch at any time, and in Windows, Windows puts the timer message through the WM_TIMER message into normal. In the message queue, you don't have to worry that your program is interrupted in other processing. It is impossible to have two WM_Timer messages simultaneously, if a window is still in a message queue, the two messages will be merged into one, so the WM_TIMER message may be lost when the program is relatively busy. The level of the WM_TIMER message is very low, and the program only receives the WM_TIMER message if there is no other message in the message queue, you can verify the following horse method: Press and hold the title bar mobile window on a window set the timer. You will find that the timer stops working. When you release the mouse, the WM_TIMER message lost in this process is not added, so if you design a clock program, you can't use the timer message to count, but must Get the correct system time each time in the message.

The characteristics of so much timer are told. Below is the timer-related API, you will find these features that should be noted in use, the timer's API is really small and simple: establish the timer setTimer (hwnd hwnd, // handle of window for timer messages UINT nIDEvent, // timer identifier UINT uElapse, // time-out value TIMERPROC lpTimerFunc // address of timer procedure); hWnd WM_TIMER transmission windows of the window, the timer is nIDEvent number in the WM_TIMER In the WPARAM parameter, it is used to distinguish which timer is generated by a plurality of timers. UELAPSE is a timer interval for milliseconds. If you want to set a 1 second timer, this value is 1000, and lptimerfunc is the process of processing timer messages. If this parameter is not null, Windows will call lptimerfunc specified after the time. Procedure, the parameter called is called Callback TimerProc (HWND, WM_TIMER, ITIMERID, DWTIME), and itimerid is the timer ID, DWTIME is a system time; if the lptimerfunc parameter is null, Windows puts the WM_TIMER message into the message loop, the message hWnd is The HWnd specified in the first parameter, that is, the WM_TIMER message is sent to this window. Also, if your program is not window, you can also use this method to establish Timers: Invoke SetTimer, Null, Null, UELAPSE, TIMERPROC, and functions return a system-defined Timerid for you to use in KillTimer. Cance the timer KillTimer (HWND HWND, // Handle Of WINDOW THAT INSTALLED TIMER UIDEVENT / / TIMER Identifier); Canceling Timer Simply call the killtimer function when you have the hWnd and UidEvent when SetTimer. In the example program in this section, I use setTimer to build two timers in the WM_INIT message in the dialog, and the time is 500ms and 200ms, and then replace the picture on the button in a fixed timer message at a distance of 0.5 seconds, at the interval To replace the small icon on the title bar in a timer message, you can see the animation.

Source program - assembly source file; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Yunbin, Bigluo@telekbird.com.cn; Website: http://asm.yeah.net; Luoyunbin's Win32 ASM Page (Luo Yunbin's programming park); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>. 386.Model flat, stdcalloption casemap: none; Case Sensitive; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>

include windows.incinclude user32.incinclude kernel32.incinclude comctl32.incinclude comdlg32.incincludelib user32.libincludelib kernel32.libincludelib comctl32.libincludelib comdlg32.lib; >>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder ; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>> IDI_MAIN equ 1IDI_MOON1 equ 2IDI_MOON2 equ 3IDI_MOON3 equ 4IDI_MOON4 equ 5IDI_MOON5 equ 6IDI_MOON6 equ 7IDI_MOON7 equ 8IDI_MOON8 equ 9DLG_MAIN equ 1000ID_MOON equ 1001ID_TIMER1 equ 1ID_TIMER2 equ 2; >>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DD? dwcounter2 DD? Hicon1 ? dd hIcon2 dd hIcon3 dd hIcon4 dd hIcon5 dd hIcon6 dd hIcon7 dd hIcon8 dd szBuffer db 256 dup data??????? (?);. >>>>>>>>>>>>>>>>> >>>>>>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>> Folder; ***************************** ******************************************************** _ ProCDLGMAIN Proc Uses EBX EDI ESI, / HWND: DWORD, WMSG: DWORD, WPARAM: DWORD, LPARAM: DWORDMOV EAX, WMSG; ********************************************* ************************. if eax == wm_closeinvoke killtimer, hwnd, id_timer1invoke killtimer, hwnd, id_timer2invoke enddialog , hwnd, null; **************************************************** ***********************. Elseif EAX == WM_INITDIALOGMOV EDI, OFFSET HICON1MOV EBX, IDI_MOON1MOV ECX, 8 @@: push ecxinvoke loading, hinstance, ebxcldstosdinc EBXPOP ECXLOOP @binvoke settimer, hwnd, id_timer1,500, nullinvoke settimer, hwnd, id_timer2,200, nullinvoke sendmessage, hwnd, wm_seticon, icon_small, hicon1; *************************** *********************************************************. Elseif EAX == WM_TIMER.IF WPARAM == id_timer1inc dwcounter1.if dwcounter1 == 8MOV DWCOUNTER1, 0.ENDIFMOV EAX, DWCOUNTER1SHL eax, 2add eax, offset hIcon1mov eax, [eax] invoke SendMessage, hWnd, WM_SETICON, ICON_SMALL, eax.elseinc dwCounter2.if dwCounter2 == 8mov dwCounter2,0.endifmov eax, dwCounter2shl eax, 2add eax, offset hIcon1mov eax, [eax ] Invoke Senddlgitemmessage, HWnd, ID_Moon, BM_SetImage, Image_ICON, EAX.Endif;

转载请注明原文地址:https://www.9cbs.com/read-1432.html

New Post(0)