This is a simple interface that redraws the dialog box on the window (this is a reference to my previous blog post):
All you need to do is click OK to get the contents of the text box.
//Handling dialog box messagesint_ptr CALLBACK Newdlgproc (HWND hdlg, UINT msg, WPARAM WPARAM, LPARAM LPARAM) {intRet_num; HWND hwnd; WCHAR buff[ +]; Switch(msg) { Casewm_command: {Switch(LoWord (WParam)) { CaseIdc_button3:ret_num= GetDlgItemText (Hdlg,idc_edit1,buff, +); //The comment section is another way to get the text of the textboxhwnd =GetDlgItem (HDLG,IDC_EDIT1); Ret_num= GetWindowText (hwnd, Buff, + ); MessageBox (hdlg, buff, L"Tips", MB_OK |mb_iconinformation); Break; default: Break; } } return 0; } return(INT_PTR) FALSE; }
Add code to the button response event in the handler function of the dialog message.
Two ways of writing, one is GetDlgItemText
One is GetWindowText
GetDlgItemText requires a parameter dialog handle, text box ID, character store buffer, length.
It is important to note that the character stores the buffer parameter, which is required to lpwstr this type in the function declaration. At first I declared a variable such as LPWSTR str to be passed in, and the result was not obtained.
Later I found that this actually refers to the type of WCHAR. DECLARE WCHAR buff[32] it's OK.
GetWindowText to get the text of the input box, you need to take the handle of the input box (the control) as a parameter.
Getting the handle of the control requires this notation, hwnd = GetDlgItem (HDLG,IDC_EDIT1); Hdlg is a window (dialog box) handle.
Effect:
Windows program Design gets text box (window, dialog box) text