Because the program you write is automatically get the desktop real-time image, so the modal dialog box causes the program error, the current coarse understanding is that the modal dialog box will allow the dialog to pause the thread, when the dialog box can be closed to continue the operation, and the Non-modal dialog box without having to let the program pause.
The following document creates the non-modal dialog box:
1 Create a new dialog resource in a single document and generate a dialog box class Cradiusdlg
2 Add the header file of the dialog box to the view class C**view.cpp and add a pointer variable to the dialog class Cradiusdlg *pmodalessdlg;
3 Add a menu item in the menu bar to display the dialog box, and in response to the event, add the event-handling code:
if (pmodalessdlg==null) { pmodalessdlg=new cradiusdlg;//pmodalessdlg->m_nradius= ""; Pmodalessdlg->create (idd_dialog1,null);//Create Non-modal dialog Pmodalessdlg->showwindow (sw_show); } else
After the above steps, you can pop up the modal dialog box when you click on the menu item.
The next step is to set the feature:
A adds a # define Wm_dialog wm_user+1 to the header file of the dialog class
B Declare the message in the header file of the view class:
afx_msg LRESULT ondialog (WPARAM wparam,lparam LPARAM);
To add a message response in the view class's CPP file:
On_message (Wm_dialog,ondialog)
C Add the message handler function for the button in the dialog box, respectively.
The Wm_dialog message is sent when any button is clicked, and the response Ondialog function is processed accordingly.
voidCradiusdlg::onok () {//todo:add Extra Validation hereUpdateData (true); CFrameWnd* Pframe=getparentframe ();//get the parent window framecview* Pview=pframe->getactiveview ();//Get Current ViewPview->postmessage (Wm_dialog,idok);//send a message to the diagram with the parameter IdokCdialog::onok ();}voidCradiusdlg::oncancel () {//Todo:add Extra Cleanup here//Cancel does not update the data and delivers the message directlycframewnd* pframe=GetParentFrame (); CView* pview=pframe->GetActiveView (); PView-PostMessage (Wm_dialog,idcancel); Cdialog::oncancel (); }
D to edit the response function wm_dialog the message handler function in View.cpp
LRESULT cthreadview::ondialog (WPARAM wparam,lparam LPARAM) {Switch(wParam) { CaseIdok:m_para1=pmodalessdlg->m_nradius;//gets the value of the dialog box edit Control member variablePmodalessdlg->destroywindow ();//Destroying the dialog box windowDeletePmodalessdlg;//deletes the current non-modal dialog box object PPmodalessdlg=null;//setting a non-modal dialog box does not exist flag Break; CaseIdcancel:pmodalessdlg-DestroyWindow (); DeletePmodalessdlg; Pmodalessdlg=NULL; //Break ; Case Idapply://preserve the non-modal dialog box//m_para1=pmodalessdlg->m_nradius; //Break ; } //Invalidate (); //Refresh Viewreturn 0;} }
After the above steps, you can pass the value of the Editcontrl variable to the global variable M_PARA1. This enables the operation of removing the control values of the non-modal dialog box.
Using the Non-modal dialog box under MFC Single document