June 04 2009
Code by sealplusplus
640 K ought to be enought for everybody
------- Bill Gates
Timer
The timer does not depend on the CPU clock speed (it should have its own clock crystal shock )..
Cwnd: settimer ();
Generate the wm_timer. Message. In the properties of the dialog box, there are several icons at the top. Vs2005 is the 5th icon, and then select. Wm_timer message, which automatically generates the ontimer () function. You can also manually add the message. Note that the function header contains afx_msg and function declaration. One is. cpp function definition. Another is to define the message. In the message loop of. cpp, add on_wm_timer (). Because it is included in the system, it is relatively simple.
Note that the parameter is set to a period in milliseconds.
Then, wm_timer is sent to the window until cwnd: killtimer () or the window is closed.
When multiple timers are used, the cycle between timers may be inaccurate when the cycle is less than 100 milliseconds.
Wm_timer can be blocked by other handler functions in the program, and wm_timer messages are not accumulated.
More detail:
Msnd, mspress VC 6.0 technical insider ...........
1. Set the timer Call the settimer () function where you want to set the time timer. The function prototype is uint settimer (uint nidevent, uint nelapse, void (callback * Lpfntimer) (hwnd, uint, uint, DWORD )) The first parameter nidevent is the ID of the time timer, and the second parameter is the time interval, that is, the execution Interval The third parameter is the function pointer, which calls processing every time. When it is set to null, the default Ontimer () function For example: Settimer (1, 1, null ); Settimer (2,500, null); // 500 means 1/2 second, 100 means 1/10 second 2. Timer Processing If the third parameter is not null, the custom function is called. Otherwise Void cpickcolordlg: ontimer (uint nidevent) { // Todo: add your message handler code here and/or call default If (nidevent = 1) { Cpoint pt; Getcursorpos (& pt );
HDC =: getdc (null ); Colorref CLR =: getpixel (HDC, Pt. X, Pt. y );
M_red.format ("% d", getrvalue (CLR )); M_green.format ("% d", getgvalue (CLR )); M_blue.format ("% d", getbvalue (CLR )); Updatedata (false );
: Releasedc (null, HDC ); } Else if (nidevent = 2) { Static int I = 1; If (I> 20) { I = 1; } M_progress.setpos (I ); M_progresstext.setpos (I ); I ++; } Cdialog: ontimer (nidevent ); } 3. stop the timer. Call the killtimer () function. Function prototype: bool killtimer (INT nidevent) The nidevent parameter is the ID of the time timer. For example: Killtimer (1 ); Killtimer (2 ); |
P.s
It can be seen that the message is the essence of MFC or the current operating system. If you use a timer to determine whether the function is fully executed, send a message instead. However, the timer has a timing effect and cannot be ignored. For example, 1000000000000 second is shut down after the instance is started.