SetTimer and CreateWaitableTimer example (static function set to callback function, Swiss web page, sort of Meaning)

Source: Internet
Author: User

Timers (settimer and Createwaitabletimer) in Windows
Settimerthe following example creates a timer (that isn't attached to a window) whose timer Procedure creates Boxes
#include <windows.h>class foo_class {  static int counter;public:  static void  __stdcall Timer_proc ( hwnd,unsigned int, unsigned int, unsigned long) {    if (counter++ <)      MessageBox (0, "Hello", "messagebox", 0); C7/>else      postquitmessage (0);  }; int foo_class::counter=0; WINAPI WinMain (hinstance,hinstance,lpstr,int) {int itimerid = settimer (0, 0, +, foo_class::timer_proc);  MSG m;  While (GetMessage (&m,0,0,0)) {    translatemessage (&m);    DispatchMessage (&m);   }  Return 1;}
Createwaitabletimerthis example demonstrates how to use timers in Windows. A timer'll be set That's signalled for the first time 2 seconds after the first call to CreateWaitableTimer and then are Signalled every 3/4th of a second.
#define _WIN32_WINNT 0x0400#include <windows.h> #include <process.h> #include <stdio.h>unsigned __ stdcall TF (void* arg) {  HANDLE timer= (HANDLE) arg;  While (1) {    WaitForSingleObject (timer,infinite);    printf (".");}  } int main (int argc, char* argv[]) {  HANDLE timer = createwaitabletimer (    0,    false,//false=>will be Automati Cally Reset    0);    Name  large_integer li;  const INT unitspersecond=10*1000*1000; Nano seconds  //Set The event the first time 2 seconds  //after calling SetWaitableTimer  li. quadpart=-(2*unitspersecond);  SetWaitableTimer (    timer,    &li, up    ,   //Set the event every Milli Seconds    0,    0,    false);  _beginthreadex (0,0,tf, (void*) timer,0,0);  Wait forever, while   (1);  Return 0;}

Http://www.adp-gmbh.ch/win/misc/timer.html

SetTimer and CreateWaitableTimer example (static function set to callback function, Swiss web page, sort of Meaning)

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.