将 GetStockObject(WHITE_BRUSH) 更改为 GetStockObject(GREY_BRUSH) 时松开鼠标光标

Loosing mouse cursor when changing GetStockObject(WHITE_BRUSH) to GetStockObject(GREY_BRUSH)

我正在尝试使用编程 Windows 第五版学习 win32 API。 当我尝试使用一些标识符时,我注意到一些我无法理解的东西,为什么 happening.I` 会更具体,这是我的代码:

#include<Windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int 
WINAPI 
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT("HELLOWIN");
    HWND hwnd;
    MSG msg;
    WNDCLASS wndclass;

    wndclass.style         = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc   = WndProc;
    wndclass.cbClsExtra    = 0;
    wndclass.cbWndExtra    = 0;
    wndclass.hInstance     = hInstance;
    wndclass.hIcon         = LoadIcon(NULL, IDI_SHIELD);
    wndclass.hCursor       = LoadCursor(NULL, IDC_CROSS);
    wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName  = NULL;
    wndclass.lpszClassName = szAppName;

    if (!RegisterClass(&wndclass))
    {
        MessageBox(0, TEXT("This Programm Requires WINNT!"), szAppName, MB_ICONERROR);
        return(0);
    }

    hwnd = CreateWindow(szAppName,   //window class name
        TEXT("The Hello Program"),   //window caption
        WS_OVERLAPPEDWINDOW,         //window style
        CW_USEDEFAULT,               //initial x position
        CW_USEDEFAULT,               //initial y position   
        CW_USEDEFAULT,               //initial x size
        CW_USEDEFAULT,               //initial y size
        NULL,                        //parent window handle(we have top-level window)
        NULL,                        //window menu handle
        hInstance,                   //programm instances handle    
        NULL);                       //creation parameters                          

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;


}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    RECT rect;

    switch (message)
    {

        case WM_CREATE:
        {
            PlaySound(TEXT("D:\mp3\aywy._&_EphRem_-_Adderall.wav"), NULL, SND_FILENAME | SND_ASYNC);
            return 0;
        } break;

        case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            GetClientRect(hwnd, &rect);

            DrawText(hdc, TEXT("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
            EndPaint(hwnd, &ps);
            return 0;
        } break;

        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        } break;

    }
    return DefWindowProc(hwnd, message, wParam, lParam);
}

使用此代码,一切正常,如预期的那样,但是... 当我改变时:

wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);

wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);

光标图标消失在背景中,仅在小行中可见 我在其中使用 drawText()。令我困惑的是,当我的背景为白色时,这不会发生 (WHITE_BRUSH)。

有人可以解释为什么吗?

PS:如果本书后面解释了这种行为(我目前正在完成第 3 章),只需键入阅读更多,这样我就不会浪费你的时间。

提前谢谢你。

可能发生的情况是,您正在使用的 'cross' 光标是一个非常细的光标(由 windows 或硬件实现),它通过取消底层像素而不是在上面绘制他们。这适用于除 0x808080 灰色之外的所有颜色,因为否定 0x808080 仍然会得到 0x808080,因此光标是不可见的。尝试使用浅灰色、深灰色或其他不太细的光标。