绘画后,winapi窗口不刷新

时间:2013-08-30 12:07:51

标签: c++ c windows winapi

您好我创建了一个窗口:

WNDCLASSEX WndClass = {0};

if (WndClass.cbSize == 0)
{
    WndClass.cbSize = sizeof(WNDCLASSEX);
    WndClass.style = CS_DBLCLKS;
    WndClass.lpfnWndProc = WindowProcedure;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = GetModuleHandle(NULL);
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = HBRUSH(COLOR_WINDOW+1);
    WndClass.lpszMenuName = NULL;
    WndClass.lpszClassName = ClassName.c_str();
    WndClass.hIconSm = LoadIcon( NULL, IDI_APPLICATION);
}

if (RegisterClassEx(&WndClass))
{

    WindowHandle = CreateWindowEx(0, ClassName.c_str(), WindowName.c_str(), WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_HSCROLL,
        CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, GetModuleHandle(NULL), NULL);
    if(WindowHandle)
    {
        ShowWindow(WindowHandle, SW_SHOWDEFAULT);
    }
}

尝试添加按钮。使用此:

HWND child = CreateWindowEx(0, L"BUTTON", NULL, WS_CHILD | WS_VISIBLE, n * CHILDS_OFSET, posY, GetWidth(), h, window, NULL, NULL, NULL);

代码执行后,我的窗口保持清晰,但是如果我移动它或调整它的大小,按钮变得可见,问题可能是什么?

我试过了:

RECT rc;
GetClientRect(window, &rc);
InvalidateRect(window, &rc, TRUE);

尝试window处理主窗口和按钮。

2 个答案:

答案 0 :(得分:1)

如果您的窗口过程无法正确处理WM_PAINT,则可能会发生这种情况。你必须拥有的最小的东西是

...
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        BeginPaint( wnd, &ps );
        EndPaint( wnd, &ps );
        return 0;
    }

答案 1 :(得分:0)

我认为您需要在ShowWindow之后致电UpdateWindow,请参阅here