如何获取用户输入编辑框中的内容/
我建立了一个编辑框,但是获取不了编辑框中的内容,注意,输入内容可以是任意的。
程序很简单
有兴趣的可以看一下我的程序
case WM_CREATE:
{
/* The window is being created. Create our button
* window now. */
TEXTMETRIC tm;
/* First we use the system fixed font size to choose
* a nice button size. */
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);
/* Now create the button */
hwndButton = CreateWindow (
"button",/* Builtin button class */
"Click Here",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,/* Parent is this window. */
(HMENU) 1,/* Control ID: 1 */
((LPCREATESTRUCT) lParam)->hInstance,
NULL);
/*创建一个编辑框 */
hwndEdit = CreateWindow(TEXT("Edit"),
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
0,0,100,20,
hwnd,
(HMENU)ID_EDIT,
((LPCREATESTRUCT)lParam)->hInstance,
NULL);
//PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
break;
return 0;
break;
}
case WM_COMMAND:
{
/* Check the control ID, notification code and
* control handle to see if this is a button click
* message from our child button. */
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
char *pBuf = "Connecting...";
/* 取出来编辑框里面的内容 */
/*CHAR strText[1024]= " ";
GetWindowText(hwndEdit, strText, 100);
MessageBox(NULL, strText, "文本框里的内容是: ",0);*/
TCHAR szText[MAX_PATH] = {0};
SendMessage(hwndEdit, WM_GETTEXT, MAX_PATH, (LPARAM)szText);
//SendMessage(hwndEdit, EM_GETLINE, 0, (LPARAM)szText);
MessageBox(NULL, szText, "文本框里的内容是2: ",0);
memcpy(g_Databuf, szText, 100);
//GetDlgItemText(hwndEdit, ID_EDIT, szText, MAX_PATH);
//MessageBox(NULL, szText, "文本框里的内容是2: ",0);
//memcpy(g_Databuf, pBuf, strlen(pBuf));
InvalidateRect(hwnd,NULL,TRUE);
UpdateWindow(hwnd);
}
return 0;
break;
}