I'm not able to retrieve any text from the edit control I have on my main window. I can set the text, which does show up when the window is drawn, but I can not get the text, which I would like to display in a MessageBox. I tried both "SendMessage()" and "GetWindowText()" but both do the same thing. It appears the length of text I'm retrieving is also invalid, so the edit has no value even though I can see text in it.
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;
}