2
我正在嘗試使用編程Windows第五版來學習win32 API。 當我與一些標識符嘗試我發現我不能夠理解爲什麼是happening.I`會更具體的東西,這裏是我的代碼:當將GetStockObject(WHITE_BRUSH)更改爲GetStockObject(GREY_BRUSH)時鬆動鼠標光標
#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);
光標圖標丟失的背景,僅visisbl e在我使用drawText()的小行 中。讓我困惑的是當我的背景是白色(WHITE_BRUSH)時,這不會發生。
有人可以解釋爲什麼嗎? PS:如果這種行爲在本書後面解釋(我正在完成第3章當前),只需鍵入閱讀更多,所以我不會浪費你的時間。
預先感謝您。
你是對的。當將光標標識符改回IDC_ARROW(默認白色箭頭窗口光標)時,我可以再次看到光標。謝謝。 – strax 2015-02-06 11:23:37
很高興能有所幫助。請接受答案(如果你願意的話可以加票) – 2015-02-06 11:26:36
我試着去註冊,但我需要更多的信譽。一旦我達到15我會回來upvote – strax 2015-02-06 11:27:57