Windows simple presentation

Source: Internet
Author: User
//************************************** **************************************** * ***** // This program uses two timer implementation methods, all are based on APIs, rather than MFC // 1. is to use the thread timed sleep method, start the thread threadproc, output in the thread, and then sleep 1000 ms /// 2. use the timer method to set a Ms timer (settimer), capture the message, call the callback function // timerproc, and output def in this function. Note, settimer can directly write the callback function address without capturing messages. // 3. This example is very detailed. // 4. Good luck. ////************************************ **************************************** * ******* # Include "stdafx. H "# include <windows. h> DWORD winapi threadproc (lpvoid lpparameter) // method 1 {static DWORD tick = 0; dword tmp = gettickcount (); While (1) {tick = gettickcount ()-TMP; // obtain the number of MS from start to present. tmp = gettickcount (); printf ("thread_proc: ABC % d, tickcount: % d \ n", tick, TMP ); // The interval of milliseconds between printing ABC and the last printing to the current printing. Sleep (1000); // print ABC} void timerproc () Every Ms // method 2 {static DWORD tick = 0; static dword tmp = gettickcount (); tick = gettickcount ()-TMP; TMP = gettickcount (); printf ("timerproc ____________ def % d \ n", tick);} int main () {DWORD dwthread ;:: createthread (null, 0, threadproc, (lpvoid), & dwthread); // generate a thread that outputs an "ABC" Every ms, and then sleepsettimer,, 0); // set a timer. The timer callback function is 0. Only the timer message is generated and the MSG is captured in the main function; Bool flag; while (1) // This loop captures timer messages and prevents the main function from exiting {peekmessage (& MSG, null, wm_user, wm_user, pm_noremove ); while (flag = getmessage (& MSG, null, 0, 0 ))! = 0) {If (flag =-1) {// handle the error and possibly exit} else if (MSG. message = wm_timer) {timerproc (); // if it is a timer message, call timerproc} else {translatemessage (& MSG); dispatchmessage (& MSG );}}}}
Related Article

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.