The modal dialog box is used when I write a login box today. It is similar to QQ login. I used to think that if the user name or password entered by the user is wrong, I will send an error message to MessageBox, tell it that the input is incorrect. Now it's annoying to think about it. It's better to get a static box and write a red word on it to prompt. So I followed this idea. In the two edit boxes, the corresponding CEdit variables are m_teacherno_ctrl and m_teachaerpassword_ctrl. They are dumbfounded and run
Logindlg. m_teacherno_ctrl.GetWindowText (teacherno );
Logindlg. m_teacherpassword_ctrl.GetWindowText (password)
An error occurs.
Logindlg is a dialog box object, which corresponds to the modal dialog box resource.
After debugging and running, I found that this dialog box and the hWnd variable corresponding to all the preceding controls are empty. I am dizzy. This means that the GetDlgItem (), GetWindowText, functions such as SetWindowText cannot be used.
Why? Now I have no time to investigate and implement more important functions. Modal dialogs are intended to do some simple work, and there may be no need to store those values. The functions I want to implement can be fully implemented using non-modal dialogs.
In addition, how can we retrieve the values of the two edit boxes in the modal dialog box? We can bind them with CString variables. After OnOK (), we can get the values entered in the edit box.
Now we know why. To generate a modal dialog box, let's write:
CDiaolg mydlg;
If (mydlg. DoModal () = IDOK)
{
..............
}
The condition that if is true is that onok () is called, that is, the default OK button is clicked. Think about it, then the dialog box is closed! Although the mydlg class may still exist, the m_hwnd value is empty. This may be because the framework has done some work for us, it also shows the connection and difference between the window class and the window, and the window is no longer used. It is reasonable to release the window resource handle.
If you want to do something when you click the OK button, you can go to the member function of mydlg, instead of at the position of "..." above.