MFC Edit Box: Get Value Guide

To retrieve the value in an Edit Control, you can use the GetWindowText() function. The prototype of this function is as follows:

int GetWindowText(
  HWND   hWnd,
  LPTSTR lpString,
  int    nMaxCount
);

In this case, hWnd is the handle of the edit box, lpString is the buffer used to store the text content of the edit box, and nMaxCount is the size of the buffer.

Here is an example code demonstrating how to get the value from an edit box.

// 获取编辑框的句柄
HWND hEdit = GetDlgItem(hWndDlg, IDC_EDIT);

// 定义一个缓冲区用来存储编辑框的值
TCHAR szText[256];

// 获取编辑框的文本内容
GetWindowText(hEdit, szText, sizeof(szText)/sizeof(TCHAR));

// 输出编辑框的值
MessageBox(hWndDlg, szText, TEXT("编辑框内容"), MB_OK);

In this example, the GetDlgItem() function is used to retrieve the handle of the control with the specified ID (IDC_EDIT) in the specified dialog (hWndDlg). The value of the edit box will be stored in the buffer szText and displayed using the MessageBox() function.

Please note that the above code is an example based on the Windows platform. If you are using a different platform or framework, you may need to use corresponding functions to retrieve the value of the edit box.

bannerAds