Windows program Design gets text box (window, dialog box) text

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.