0
我無法從我的主窗口中的編輯控件中檢索任何文本。我可以設置當窗口繪製時顯示的文本,但我無法獲得我想要在MessageBox中顯示的文本。我嘗試了「SendMessage()」和「GetWindowText()」,但都做同樣的事情。看來我正在檢索的文本的長度也是無效的,所以即使我可以看到文本,編輯也沒有任何價值。無法從winapi的編輯控件中獲取文本
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HWND addCust, editCust1, editCust2;
switch (message) {
case WM_CREATE: {
addCust = CreateWindow(L"BUTTON",L"addCust",
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
140,70,100,25,hWnd,(HMENU)IDC_ADDCUST,NULL,NULL);
editCust1 = CreateWindowEx(WS_EX_CLIENTEDGE,L"EDIT",L"",
WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,
50,100,200,20,hWnd,(HMENU)IDC_EDITCUST1,NULL,NULL);
editCust2 = CreateWindowEx(WS_EX_CLIENTEDGE,L"EDIT",L"",
WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,
50,130,200,20,hWnd,(HMENU)IDC_EDITCUST2,NULL,NULL);
SendMessage(editCust1,WM_SETTEXT,NULL,(LPARAM)L"first name");
SendMessage(editCust2,WM_SETTEXT,NULL,(LPARAM)L"last name");
break;
}
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
case IDC_ADDCUST: {
TCHAR buff[64] = { '\0' };
int len = SendMessage(editCust1, WM_GETTEXTLENGTH, 0, 0);
SendMessage(editCust1, WM_GETTEXT, len+1, (LPARAM)buff);
GetWindowText(editCust1, buff, len+1);
MessageBox(NULL, buff, L"Information", MB_ICONINFORMATION);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}