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;
}
我知道我选择了正确的控件。它的标识符是 IDC_EDIT2,我知道这是对的。但是每当我尝试检索编辑控件的长度并将其保存到变量 PortLength 时,当我调试它时该值始终为 0。我已经尝试将 GetWindowTextLength 与 IP 控件一起使用,但当我将它与编辑控件一起使用时,无论我在框中输入多长的字符串,长度始终为 0。