The c ++ console program implements the timer and the console implements the timer

Source: Internet
Author: User

The c ++ console program implements the timer and the console implements the timer

# Include "stdafx. h "# include <iostream> # include <Windows. h> using namespace std; void CALLBACK TimeProc (HWND hwnd, UINT message, UINT idTimer, DWORD dwTime); int _ tmain (int argc, _ TCHAR * argv []) {SetTimer (NULL, TimeProc); MSG msg; while (GetMessage (& msg, NULL,) {if (msg. message = WM_TIMER) {DispatchMessage (& msg) ;}return 0 ;}int ncount = 0; void CALLBACK TimeProc (HWND hwnd, UINT message, UINT idTimer, DWORD dwTime) {cout <ncount ++ <endl;}/* hovertree.com */
# Include "stdafx. h "# include <ctime> # include <Windows. h> # include <conio. h> # include <stdio. h> int ncount = 0; void CALLBACK TimerProc (HWND hWnd, UINT nMsg, UINT_PTR idEvent, DWORD dwTime) {ncount ++;} dword callback Thread (PVOID pvoid) {MSG msg; peekMessage (& msg, NULL, WM_USER, WM_USER, PM_NOREMOVE); UINT timerid = SetTimer (NULL, 1,10000, TimerProc); BOOL bRet; while (bRet = GetMessage (& msg, NULL, 0, 0 ))! = 0) {if (bRet =-1) {printf ("Error: the thread will quit, error id is % d/n", GetLastError (); break ;} else {TranslateMessage (& msg); DispatchMessage (& msg) ;}} KillTimer (NULL, timerid); printf ("thread end here/n"); return 0 ;} int _ tmain (int argc, _ TCHAR * argv []) {HANDLE hThread = CreateThread (NULL, 0, Thread, NULL, 0, NULL); _ getch (); return 0;}/* asked hovertree.com */

Recommended: http://www.cnblogs.com/roucheng/p/cppjy.html

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.