For some asynchronous execution, in order to operate simple, you need to change the synchronous mode, you have written a test code. #Include
#define map_event std :: map
Class CEVENTTSTDLG: Public CDialog {// Constructionpublic: CEVENTTESTDLG (CWND * PParent = NULL); // Standard Constructionor
// Dialog data // {{AFX_DATA (CEVENTTSTDLG) ENUM {IDD = IDD_EVENTTEST_DIALOG}; // Note: The classwizard will add data members here //}} AFX_DATA
// ClassWizard generated Virtual function overrides // {{AFX_VIRTUAL (CEVENTTSTDLG) protected: Virtual Void DodataExchange (CDATAEXCHANGE * PDX); // DDX / DDV Support ///}} AFX_VIRTUAL
// ImplementationProtace: hicon m_hicon;
// Generated message map functions // {{AFX_MSG (CEventTestDlg) virtual BOOL OnInitDialog (); afx_msg void OnSysCommand (UINT nID, LPARAM lParam); afx_msg void OnPaint (); afx_msg HCURSOR OnQueryDragIcon (); virtual void OnOK (); afx_msg Void ONDNOVER (); Virtual void oncancel (); afx_msg void onbutton2 (); //}} AFX_MSG DECLARE_MESSAGE_MAP ()
Std :: Map
#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF
/// Caboutdlg Dialog Used for App About
Class Caboutdlg: public cdialog {public: capoutdlg ();
// Dialog Data // {{AFX_DATA (Caboutdlg) Enum {IDD = IDD_ABOUTBOX}; //}} AFX_DATA
// ClassWizard generated virtual function overrides // {{AFX_VIRTUAL (CAboutDlg) protected: virtual void DoDataExchange (CDataExchange * pDX); // DDX / DDV support //}} AFX_VIRTUAL // Implementationprotected: // {{AFX_MSG (CAboutDlg) / /}} AFX_MSG DECLARE_MESSAGE_MAP ()};
Caboutdlg :: Caboutdlg (): cdialog (caboutdlg :: IDD) {/ {{AFX_DATA_INIT (Caboutdlg) //}} AFX_DATA_INIT}
Void Caboutdlg :: DODATAEXCHANGE (CDataExchange * PDX) {cdialog :: DODATAEXCHANGE (PDX); // {{AFX_DATA_MAP (CaboutDLG) //}} AFX_DATA_MAP}
Begin_MESSAGE_MAP (Caboutdlg, cdialog) // {{AFX_MSG_MAP (Caboutdlg) // No Message Handlers //}} AFX_MSG_MAPEND_MESSAGE_MAP ()
Unsigned long __stdcall downnthread (void * phwnd) // download thread {hwnd hwnd = * (hwnd *) phWnd; // simulation operation SLEEP (1000 * 5);
SendNotifyMessage (hwnd, wm_user 0x122, 0, 0);
Sleep (1000 * 5); SendNotifyMessage (HWND, WM_USER 0X123, 0, 0); // PostMessage (hwnd, wm_user 0x123, 0, 0); Return 0;}
/// CEVENTTESTDLG DIALOG
CEventTestDlg :: CEventTestDlg (CWnd * pParent / * = NULL * /): CDialog (CEventTestDlg :: IDD, pParent) {// {{AFX_DATA_INIT (CEventTestDlg) // NOTE: the ClassWizard will add member initialization here //}} AFX_DATA_INIT // Note That Loadicon Does Not Require A Subsequent Destroyicon in Win32 M_HICON = AFXGetApp () -> loadicon (iDR_mainframe);
void CEventTestDlg :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CEventTestDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}} AFX_DATA_MAP}
BEGIN_MESSAGE_MAP (CEventTestDlg, CDialog) // {{AFX_MSG_MAP (CEventTestDlg) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () ON_MESSAGE (WM_USER 0x122, OnButton2) ON_MESSAGE (WM_USER 0x123, OnDownOver) //}} AFX_MSG_MAPEND_MESSAGE_MAP ()
/// CEVENTTESTDLG Message Handlers
Bool CEVENTSTDLG :: OnItDialog () {cdialog :: oninitdialog (); // add "about ..." Menu Item to System Menu.
// IDM_ABOUTBOX MUST BE IN THE SYSTEM Command Range. Assert ((idm_aboutbox & 0xff0) == idm_aboutbox; assert (idm_aboutbox <0xf000);
CMenu * pSysMenu = GetSystemMenu (FALSE); if (pSysMenu = NULL!) {CString strAboutMenu; strAboutMenu.LoadString (IDS_ABOUTBOX); if {pSysMenu-> AppendMenu (MF_SEPARATOR) (strAboutMenu.IsEmpty ()!); PSysMenu-> AppendMenu ( MF_String, IDM_AboutBox, Straboutmenu);}}
// set the icon for this dialog. The framework does this automatic or //en the application's main window is not a dialog seticon (m_hicon, true); // set big icon seticon (m_hicon, false); // set small icon / / TODO: ADD Extra Initialization Here Return True; // Return True Unless 1 The focus to a control}
void CEventTestDlg :: OnSysCommand (UINT nID, LPARAM lParam) {if ((nID & 0xFFF0) == IDM_ABOUTBOX) {CAboutDlg dlgAbout; dlgAbout.DoModal ();} else {CDialog :: OnSysCommand (nID, lParam);}}
// if you add a minimize button to your dialog, you will need the code Below // to draw the icon. For mfc Applications Using the document / view model, // this is automaticly done for you by the framework.
Void CEVENTTSTDLG :: OnPaint () {if (isiconic ()) {CPAINTDC DC (this); // Device Context for Painting
SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0);
// Center icon in client rectangle int cxIcon = GetSystemMetrics (SM_CXICON); int cyIcon = GetSystemMetrics (SM_CYICON); CRect rect; GetClientRect (& rect); int x = (rect.Width () - cxIcon 1) / 2; int y = (Rect.height () - Cyicon 1) / 2;
// Draw the icon dc.drawicon (x, y, m_hicon);} else {cdialog :: onpaint ();}} // the system calls this to obtain the cursor to display while the user medics // The minimized window. Hcursor CEVENTTSTDLG :: ONQUERYDRAGICON () {Return (hcursor) m_hicon;}
Void CEVENTSTDLG :: Onok () {handle henok () {handle; m_strevent = "file or folder guid";
HEVENT = CREATEEVENT (NULL, FALSE, FALSE, M_STREVENT.C_STR ()); m_mapevent [m_strevent] = hEvent;
Unsigned long Tid1; CreateThread (Null, 0, & DownThread, (void *) & m_hwnd, null, & tid1);
DWORD DWWAITRESULT; While (True) {dwwaitResult = WaitForsingleObject (HEVENT, 50 / * Infinite * /); if (wait_Object_0 == dwaitresult) {// Event complete processing Break;}
Msg msg; int nexitcode = 0; while (: PeekMessage (& MSG, NULL, 0, 0, PM_Remove) {if (msg.Message == WM_QUIT) {: postquitMessage (nexitcode); Break;}
IF (GetMessage (& MSG, NULL, 0)) {:: TranslateMessage (& MSG); :: DispatchMessage (& msg);}}
}
:: MessageBox (NULL, "OK", "Test", MB_OK); // CDIALOG :: Onok ();}
void CEventTestDlg :: OnDownOver () {MAP_EVENT :: iterator itHandle = m_mapEvent.find (m_strEvent); if (itHandle = m_mapEvent.end ()!) {if (itHandle-> second) {SetEvent (itHandle-> second);} }
Void CEVENTSTDLG :: ONCANCEL () {// Todo: Add extra cleanup here cdialog :: oncancel ();
Void CEVENTSTDLG :: Onbutton2 () {:: MessageBox (null, "progress bar change", "", mb_ok);