我正在尝试学习Windows使用编程win32第五版。当我在试验一些标识符时,我注意到一些我无法理解为什么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()的小行中才能看到,.What使我感到困惑的是,当我的背景是白色的(WHITE_BRUSH)时,不会出现这种情况。
谁能解释一下原因吗?
PS:如果这本书后面对这种行为进行了解释(我目前正在完成第三章),只需键入更多的内容,这样我就不会浪费你的时间。
提前谢谢你。
发布于 2015-02-06 11:14:25
可能发生的情况是,您所使用的“交叉”游标是一个非常薄的游标(由窗口或硬件实现),由NEGating (底层像素)实现,而不是绘制在它们上面。这对于除0x808080灰色之外的所有颜色都很好,因为忽略0x808080仍然会给出0x808080,因此光标是不可见的。尝试使用浅灰,深灰色,或其他游标不是那么薄。
https://stackoverflow.com/questions/28364415
复制相似问题