代碼如下:為為什麼N的值不是從編輯框中輸入的值呢??
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int N;
static HWND hEdit,hButton;
char szBuffer[10];
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
hEdit = CreateWindow(TEXT("edit"),
NULL, WS_CHILD | WS_VISIBLE|WS_BORDER,
0,0,0,0,
hwnd, (HMENU)ID_EDIT, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
hButton = CreateWindow(TEXT("Button"),
TEXT("Button"), WS_CHILD | WS_VISIBLE,
500, 300,
7* cxChar, 2 * cyChar,
hwnd, (HMENU)ID_Button,((LPCREATESTRUCT)lParam)->hInstance, NULL);
return 0;
case WM_SIZE:
MoveWindow(hEdit, cxClient - 100, 2 * cyChar,
10 * cxChar, 2* cyChar, TRUE);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case 1:
//SetFocus(hEdit);
GetDlgItemText(hwnd, ID_EDIT, szBuffer, TRUE);
N=atof(szBuffer);
break;
case 2:
InvalidateRect(hwnd, NULL, TRUE);
break;
}
return 0;
CWnd::GetDlgItemInt
http://msdn.microsoft.com/zh-cn/library/c7t43w0s.aspx
它將指定控件的文本在特定對話框的轉換為整數值通過去除所有多余空格在該文本的開頭和轉換十進制數字。 在到達結尾的文本或遇到任何非數值字符時,終止平移。