好的,这是我的代码我将只提供一个功能感,其余部分将没有任何帮助。我一直在寻找这个问题,似乎无法弄明白。
错误:未初始化的本地变量' hTextBox'使用Win32Project2
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
HDC hdc;
RECT rect;
PAINTSTRUCT ps;
HWND hTextBox;
switch (message)
{
case WM_CREATE:
hTextBox = CreateWindow(L"edit", L"", WS_CHILD|WS_VISIBLE|WS_BORDER, 5, 5, 200, 25, hwnd, NULL, NULL, NULL);
CreateWindow(L"button", L"Click me!", WS_CHILD | WS_VISIBLE, 20, 40, 75, 25, hwnd, (HMENU)1, NULL, NULL);
break;
case WM_COMMAND:
switch (LOWORD(wparam))
{
case 1:
int returnedCharacters = 0;
returnedCharacters = GetWindowText(hTextBox, &szTextSaved[0], 20);
break;
}
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, L"This is a text message!", -1, &rect, DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
答案 0 :(得分:2)
它不是静态的,因此它不会记住WM_CREATE中发生的事情