简体   繁体   English

Switch语句中未初始化的局部变量-Win32 API

[英]Uninitialized Local Variable in Switch Statement - Win32 API

Alright here is my code I will just provide one function sense the rest of it would not be any helpful. 好了,这是我的代码,我将只提供一个函数,其余的代码将无济于事。 I have been searching for the problem and can not seem to figure it out. 我一直在寻找问题,似乎无法解决。

Error: uninitialized local variable 'hTextBox' used Win32Project2 错误:使用了Win32Project2的未初始化的局部变量'hTextBox'

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);
}

它不是静态的,因此它不会记住WM_CREATE中发生的情况

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM