void Ctestdlg::onbuttonadd () {//Todo:add your control notification handler code here//dynamic Create button/*if (FALSE = = M_biscreate )//can also be statically variable by static BOOL biscreate = FALSE; {m_btn. Create ("Lee", Bs_defpushbutton | ws_visible | Ws_child, CRect (0,0,100,65), this, 111);//m_btn. ShowWindow (sw_normal);//If the previous sentence is not ws_visible, add showwindowm_biscreate = TRUE;} Else{m_btn. DestroyWindow (); m_biscreate = FALSE;} *//*//The simplest dynamic Create button if (!m_btn.m_hwnd)//window handle is not empty {m_btn. Create ("Lee", Bs_defpushbutton | ws_visible | Ws_child, CRect (0,0,100,65), this, 111);} Else{m_btn. DestroyWindow (); Automatically m_hwnd = null}*///Implementation Click the Add button, the number of edit box 1 + the number of edit box 2 into the edit box 3/*int num1, num2, Num3;char ch1[10], ch2[10], ch3[10]; GetDlgItem (IDC_EDIT1)->getwindowtext (ch1,10); Saves the text of the edit box to ch1 with a maximum of 10 characters GetDlgItem (idc_edit2)->getwindowtext (ch2,10); num1 = Atoi (CH1); Converts a string to integer num2 = atoi (CH2); num3 = Num1 + Num2;itoa (NUM3, CH3, 10); Convert integer num3 to CH3, GetDlgItem (IDC_EDIT3)->setwindowtext (CH3) in decimal mode; The CH3 character value is stored in the edit box 3 *//*//can also be int num1, num2, num3;char ch1[10], ch2[10], ch3[10]; GetDlgItemText (Idc_edit1, CH1, 10); GetDlgItemText (Idc_edit2, CH2, ten); num1 = Atoi (CH1); Converts a string to integer num2 = atoi (CH2); num3 = Num1 + Num2;itoa (NUM3, CH3, 10); Setdlgitemtext (IDC_EDIT3, CH3); *//*//can also be int num1, num2, num3;num1 = Getdlgitemint (IDC_EDIT1); Directly get the value in the edit box num2 = Getdlgitemint (idc_edit2); num3 = Num1 + num2; Setdlgitemint (Idc_edit3, num3); *//*//the simplest, with ClassWizard associated controls and member variables (with values) UpdateData (); m_num3 = m_num2 + m_num1; UpdateData (FALSE); *//*//the fifth way to associate a control with a member variable (in a control) with ClassWizard. Similar to the first type int num1, num2, Num3;char ch1[10], ch2[10], ch3[10];m_edit1. GetWindowText (CH1); m_edit2. GetWindowText (CH2, ten); num1 = Atoi (CH1); Converts a string to integer num2 = atoi (CH2); num3 = Num1 + Num2;itoa (num3, CH3, ten); m_edit3. SetWindowText (CH3); *//*//sixth way, send message int num1, num2, Num3;char ch1[10], ch2[10], Ch3[10];//::sendmessage (GetDlgItem ( IDC_EDIT1)->m_hwnd, Wm_gettext, Ten, (LPARAM) ch1);//::sendmessage (M_edit1.m_hwnd, Wm_gettext, Ten, (LPARAM) ch1);// GetDlgItem (IDC_EDIT1)->sendmessage (WM_gettext, LPARAM, CH1); m_edit1. SendMessage (Wm_gettext, ten, (LPARAM) ch1); The above four sentences are equivalent m_edit2. SendMessage (Wm_gettext, ten, (LPARAM) CH2); num1 = Atoi (CH1); Converts a string to integer num2 = atoi (CH2); num3 = Num1 + Num2;itoa (num3, CH3, ten); m_edit3. SendMessage (Wm_settext, ten, (LPARAM) CH3); *///Seventh Way int NUM1, num2, Num3;char ch1[10], ch2[10], ch3[10]; SendDlgItemMessage (Idc_edit1, Wm_gettext, Ten, (LPARAM) ch1);//Send a message directly to the child control SendDlgItemMessage (Idc_edit2, Wm_gettext, 10, (LPARAM) CH2); num1 = Atoi (CH1); Converts a string to integer num2 = atoi (CH2); num3 = Num1 + Num2;itoa (NUM3, CH3, 10); SendDlgItemMessage (Idc_edit3, Wm_settext, Ten, (LPARAM) CH3); SendDlgItemMessage (idc_edit3, Em_setsel, 0,-1); Check all text//getdlgitem (IDC_EDIT3)->setfocus (); Gather focus to edit3. or M_EDIT3. SetFocus ();}
Seven Ways to Access MFC dialog box controls