#include <afxmt.h>
//---------- g_var
UINT ThreadProc(LPVOID pParam);
CEvent g_eBusy;
BOOL CPicFileDlg::OnInitDialog() 
{
CFileDialog::OnInitDialog();

// TODO: Add extra initialization here
SetTimer(1, 500, NULL);
g_eBusy.SetEvent(); return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}
UINT ThreadProc(LPVOID pParam)
{
g_eBusy.ResetEvent(); CWnd hWnd;
hWnd.Attach((HWND)pParam);
ASSERT(hWnd); CRect m_Rect;
CDC *m_pDC;
hWnd.GetClientRect(&m_Rect);
m_pDC=hWnd.GetDC(); PreViewPic(g_sFileName, m_pDC, m_Rect);

hWnd.Detach();

g_eBusy.SetEvent();
return 0;
}

解决方案 »

  1.   

    那WaitForSingalObject()到哪里去了?例如:我的这段代码如何用CEvent类改写?
    void CEventTestDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here m_hEvent = CreateEvent(
    NULL,         // no security attributes
            TRUE,         // manual-reset event
            TRUE,         // initial state is signaled
            "TestEvent"  // object name
            );

    ResetEvent(m_hEvent);
    AfxBeginThread(SimProc,m_hEvent);
    DWORD dwWaitResult=0;
    dwWaitResult = WaitForSingleObject(m_hEvent,5000);
    switch(dwWaitResult)
    {
    case WAIT_ABANDONED:

    break;
    case WAIT_OBJECT_0: 
    MessageBox("proc finish!");
    break;
    case WAIT_TIMEOUT:
    MessageBox("Time Out");
    break;
    default:
    break;
    }
    CloseHandle(m_hEvent);

    }UINT SimProc(LPVOID pParam)
    {//Process.......
    .......//
    HANDLE hEvent = (HANDLE)pParam;
    if (!hEvent) 
    {
    ASSERT(FALSE);
    return -1;
    }
    SetEvent(hEvent);
    return 0;
    }
      

  2.   

    俺不过少贴了2段代码而已,如下:void CPicFileDlg::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    CString sName=GetFileName(), sExt=GetFileExt(); if (sName=="" && sExt.CompareNoCase("bmp") && sExt.CompareNoCase("gif") && sExt.CompareNoCase("jpg"))
    return; if (g_sFileName.CompareNoCase(sName) && WaitForSingleObject(g_eBusy, 0)==WAIT_OBJECT_0)
    {
    g_sFileName=sName;
    AfxBeginThread(ThreadProc,m_hPicView.GetSafeHwnd());
    }

    CFileDialog::OnTimer(nIDEvent);
    }void CPicFileDlg::OnDestroy() 
    {
    // TODO: Add your message handler code here
    KillTimer(1);
    WaitForSingleObject(g_eBusy, INFINITE); CFileDialog::OnDestroy();
    }