Windows/MFC

쓰레드 사용하기 (CWinThread )

aucd29 2013. 10. 2. 17:37
[code]void Ctest2Dlg::OnBnClickedButton1()
{
    CWinThread *th = AfxBeginThread( RUN, this );

    DWORD dwExitCode;
    MSG msg;

    do
    {
        GetExitCodeThread(th->m_hThread ,&dwExitCode);
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    while (dwExitCode == STILL_ACTIVE);

    delete th;
}

UINT Ctest2Dlg::RUN(LPVOID pParam)
{
    Ctest2Dlg *c2 = (Ctest2Dlg*)pParam;

    CString nows;
    int now = 0;
    while( now < 1000 )
    {
        nows.Format( _T("%d"), now );
        c2->prog1.SetPos( now );
        c2->edit1.SetWindowTextW( nows );
        now++;
    }
    AfxEndThread( 0, 0 );
    return 0;
}
[/code]