No mode dialog

xiaoxiao2021-03-06  172

The Mode dialog box is different from the mode dialog box that can continue to receive user input after the other window is created, so there is a pop-up window similar to the Mode dialog. Create a modeless dialog box to call Bool CDialog :: Create (uint nidTemplate, CWnd * pParentWnd = null); then you need to call Bool CDialog :: ShowWindow (SW_SHOW); display, otherwise the Mode dialog will be invisible. The relevant code is as follows:

Void CyourView :: On Whumview: {/ * Assume IDD_test_dlg for the ID number * / ctestdlg * DLG = New Ctestdlg * DLG = New Ctestdlg; DLG-> Crete (IDD_TEST_DLG, NULL); DLG-> ShowWindows (SW_SHOW); / * Do not call DELETE DLG; * /}

In the above code we have newly generated a dialog object, and the object is not destroyed when exiting the function. Because if the object is destroyed (the window is destroyed when the object is destroyed), the dialog is still incorrect. Then this will put a question: When is it destroyed? There are two methods that I often use: destroy yourself when the dialog exits: In the dialog box, the ONOK is called with the oncancel to call the same name function of the parent class in the function, then call DESTROYWINDOW () to force the destruction window, map in the dialog WM_DESTROY message, call Delete this in the message processing function; forcibly delete its own object. The relevant code is as follows: void ctestdlg1 :: onok () {cdialog :: onok (); destroywindow ();}

Void ctestdlg1 :: oncancel () {cdialog :: oncancel (); destroyWindow ();

Void ctestdlg1 :: ONDESTROY () {cdialog :: overdestroy (); afXMESSAGEBOX ("Call Delete this"; delete this;}

This method is to delete its own object when the window is destroyed. So you can call DESTROYWINDOW () at any time to achieve the role of completely destroying your own object. (DESTROYWINDOW () calls can cause the call of ONDSTROY () to send messages to the father window: First need to define a message to make a notification, then map WM_DESTROY message in the dialog box, in the message The call message send function in the processing function notifies other windows. Use the ON_MESSAGE mapping to process the function in the window to remove the dialog object in the message processing function. The relevant code is as follows: / * Change dialog information * / ctestdlg2 :: ctestdlg2 (cDial * pParent / * = null * /): cdialog (ctestdlg2 :: idd, pparent) {/ * m_pparent is a member variable, used for Save the pointer to the notification window, so the pointer cannot be a temporary pointer * / assert (pParent); m_pparent = pParent; // {{AFX_DATA_INIT (CTESTDLG2) // Note: The classwizard will address // Note: The classwizard will add member initialization here //}} AFX_DATA_INIT} Void ctestdlg2 :: onok () {cdialog :: onok (); destroyWindow ();

Void ctestdlg2 :: oncancel () {cdialog :: oncancel (); destroyWindow ();

Void ctestdlg2 :: ONDESTROY () {cDialog :: ONDESTROY (); / * Send a message to another window, send its own pointer as a parameter * / m_pparent-> postmessage (wm_delete_dlg, (wparam);} / * in the message Add message mapping in the receiving window * // * Add a function definition in the header file * / AFX_MSG long OnDeldlg (WPARAM WP, LPARAM LP); / * Add Message Map Code * / ON_MESSAGE (WM_DELETE_DLG, ONDLGMSG) End_Message_MAP () / * Implementation Message handler * / long cmy53_s1view :: Ondeldlgmsg (WPARAM WP, LPARAM LP) {delete (ctestdlg2 *) wp; return 0;} / * Create dialog * / void cmy53_s1view :: ontest2 () {ctestdlg2 * dlg = new ctestdlg2 (this); DLG-> CREATE (IDD_TEST_DLG_2); DLG-> showwindow (sw_show);

In this method, we use a message to notify, and use messages in the Window system to notify and deliver data. Another role of the same non-Mode dialog can also be used to reflect other windows in time when the user changes in the dialog box. The following code demonstrates the input of a paragraph in the dialog, and then updates it to the display area of ​​the view, the same also utilizes messages to notify and data delivery.

/ * Remove the data in the dialog box, send messages and data to other windows, send the data pointer as a parameter * / void ctestdlg2 :: oncomMBTN () {char Szout [30]; getdlgitemtext (IDC_OUT, SZOUT, 30); m_pparent-> sendMessage (wm_dlg_notify, (wparam) szout);

/ * In the message receiving window * // * mapping message processing function * / on_MESSAGE (WM_DLG_NOTIFY, ONDLGNOTIFYMSG)

/ * Draw a string m_szout * / void cmy53_s1view :: overdraw (CDC * PDC) {CMY53_S1DOC * PDOC = getDocument (); assert_valid (pdoc); // Todo: add draw code for native data here PDC-> Textout (0, 0, "Display String"); PDC-> TextOut (0, 20, m_szout);} / * Processing Notification Message, save information and update display * / long cmy53_s1view :: OndlGnotifyMSG (WPARAM WP, LPARAM LP) {M_szout = (char *) wp; invalidate (); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-128291.html

New Post(0)