INT_PTR CALLBACK ConnectDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc = GetDC(hDlg);
int wmId, wmEvent;
static HWND hIpControl;
static HWND hPort;
static LPWSTR lpIPAddress = (LPWSTR)malloc(sizeof(LPWSTR));
static LPWSTR lpPort = (LPWSTR)malloc(sizeof(LPWSTR));
static char* IPArgtoFn;
static size_t IPAddressLength;
static size_t PortLength;
static POINT pt;
hIpControl = GetDlgItem(hDlg, IDC_IPADDRESS1);
hPort = GetDlgItem(hPort, IDC_EDIT2);
switch (message)
{
case WM_INITDIALOG:
{
return (INT_PTR)TRUE;
break;
}
case WM_COMMAND:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDCANCEL:
EndDialog(hDlg, wmId);
break;
case IDCONNECT:
IPAddressLength = GetWindowTextLength(hIpControl) + 1;
PortLength = SendMessage(hPort, WM_GETTEXTLENGTH, 0, 0);
GetWindowText(hIpControl, lpIPAddress, IPAddressLength);
pt.x = 10; pt.y = 10;
wcstombs(IPArgtoFn, lpIPAddress, IPAddressLength);
//TextOut(hdc, 10, 10, lpIPAddress , IPAddressLength);
mySocket.ConnectToServer(IPArgtoFn, (int)lpPort, hdc, pt);
return (INT_PTR)FALSE;
break;
default:
return DefWindowProc(hDlg, message, wParam, lParam);
break;
}
}
}
return (INT_PTR)FALSE;
}
I know I have the right control selected. Its identifier is IDC_EDIT2 and I know that is right. But whenever I try to retrieve the length of the edit control and save it to the variable PortLength, the value is always 0 when I debug it. I have already tried using GetWindowTextLength with works fine with the IP control but when I use it with the edit control, the length is always 0 no matter how long of a string I enter in the box.
GetDlgItem(hPort, ...) should be GetDlgItem(hDlg,...) for retrieving any child control handles.
Allocate your memory correctly.
Return FALSE only when you do NOT handle the message when using a dialog proc. This tells the invoker to forward to DefDlgProc() so you dont' have to. Dialog callbacks are different than Window callbacks on this regard.
Almost/All of the local vars in this don't need to be statics. Not saving anything there really. Ironically, the child control handles are actually decent candidates to be statics, ironic in the sense that they're somewhat the heart of the issue to begin with.