[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode
void CExample2Dlg::OnButton1() 
{
        // TODO: Add your control notification handler code here3
        sum =0;
        uiTimer = SetTimer(1,10,NULL);
        AfxBeginThread(MyThread1,this);
}
UINT CExample2Dlg::MyThread1(void *param)
{
        CExample2Dlg *Dlg=(CExample2Dlg *)param;
        Sleep(105);
        CString tmp;
        tmp.Format("%d",Dlg->sum);
        AfxMessageBox(tmp);
        return 0;
}
void CExample2Dlg::OnTimer(UINT nIDEvent) 
{
        // TODO: Add your message handler code here and/or call default
        sum++;
        CDialog::OnTimer(nIDEvent);
}
[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode
void CExample2Dlg::OnButton1() 
{
        // TODO: Add your control notification handler code here3
        AfxBeginThread(MyThread1,this);
}
UINT CExample2Dlg::MyThread1(void *param)
{
        CExample2Dlg *Dlg=(CExample2Dlg *)param;
        Dlg->start();
        Sleep(110);
        CString tmp;
        tmp.Format("%d",Dlg->sum);
        AfxMessageBox(tmp);
        return 0;
}
void CExample2Dlg::OnTimer(UINT nIDEvent) 
{
        // TODO: Add your message handler code here and/or call default
        sum++;
        CDialog::OnTimer(nIDEvent);
}
void CExample2Dlg::start()
{
        sum =0;
        uiTimer = SetTimer(1,10,NULL);
}
[C++] syntaxhighlighter_viewsource syntaxhighlighter_copycode
#include <windows.h>
static int g_nCount = 0;
#define Timer_Once_Time (1000/18)
DWORD WINAPI threadFunc (LPVOID pArg)
{
        Sleep(100*Timer_Once_Time);
        printf("%d",*((int*)pArg));
        return 0;
}
void CALLBACK TimerProc(HWND hwnd, UINT message, UINT timerID, DWORD time) 
{ 
        g_nCount++;
        printf("%d\n",g_nCount);
}
int _tmain(int argc, _TCHAR* argv[])
{
        HANDLE hThread;
        hThread = CreateThread (NULL, 0, threadFunc, &g_nCount, 0, NULL );
        
        SetTimer(NULL, 0, 10*Timer_Once_Time, TimerProc); 
        // 主消息循环:
        MSG msg;
        while (GetMessage(&msg, NULL, 0, 0))
        {
                //if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }
        return (int) msg.wParam;
}