Function: Implements communication between two dialogs. In the parent window, click the opensubdlg button (idc_btn_open) to bring up the subdialog box (non-modal). Click the send button (idc_btn_send) to edit the box (idc_edit_send) the content is sent to the edit box (idc_edit_receive) in the subdialog box. Similarly, in the subdialog box, you can click the send button (idc_btn_send) to send the content in the edit box to the edit box of the parent dialog box.
Implementation Method: for the parent dialog box, locate the sub-Dialog Box handle using the: findwindow () method, and find the edit box control handle in the sub-dialog box through the: getd item () method, finally, the content of the parent editing box is sent to the subediting box through the: setwindowtext () method. And vice versa.
Code:
1. Set the dialog box title in oninitdialog (or oncreate () to locate the handle through: findwindow. Set the parent dialog box title to parent, and the subdialog box title to subdialog. Parent dialog box: 2. double-click the opensubdlg button to add and click the Event Response: void csendmessagedemodlg: onbtnopen () {// todo: add your control notification handler code herecsubdlg * subdlg = new csubdlg; bool flag = subdlg-> Create (idd_subdialog1, null); If (! Flag) {MessageBox ("Open subdlg failed");} subdlg-> showwindow (sw_shownormal);} 3. double-click send to add and Click Event Response: void csendmessagedemodlg: onbtnsend () {// todo: add your control notification handler code herecstring STR; getdlgitemtext (idc_edit_send, STR ); hwnd hsub =: findwindow (null, "subdialog"); If (hsub = NULL) {MessageBox ("failed to find subdialog"); return;} hwnd hedit = :: getdlgitem (hsub, idc_edit_receive); If (hedit = NULL) {MessageBox ("failed to find subdialog's control"); Return ;}: setwindowtext (hedit, str);} subdialog box 4. double-click send to add and Click Event Response: void csubdlg: onbtnsend () {// todo: add your control notification handler code herecstring STR; getdlgitemtext (idc_edit_receive, STR ); hwnd hparent =: findwindow (null, "parent"); If (hparent = NULL) {MessageBox ("fail to find parent's handle"); return ;} hwnd hedit =: getdlgitem (hparent, idc_edit_send); If (hedit = NULL) {MessageBox ("fail to search the control"); return; }:: setwindowtext (hedit, str );}
Running effect:
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4C/9E/wKioL1RBQHTgqLCNAACpppqQhA0949.jpg "Title =" ptoc.png "alt =" wkiol1rbqhtgqlcnaacpppqqha0949.jpg "/>
650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/4C/9D/wKiom1RBQEWBxohKAAC0YM3ydtc774.jpg "Title =" ctop.png "alt =" wkiom1rbqewbxohkaac0ym3ydtc774.jpg "/>
This article is from the "whatever957" blog, please be sure to keep this source http://whatever957.blog.51cto.com/6835003/1565349
Implement communication between two dialogs