我有WM_PAINT問題。基本上我希望WM_PAINT在用戶WM_COMMAND之後被調用,但由於某種原因它在主函數中被調用。win32:WM_PAINT調用但不應該是!
case WM_PAINT:
{
createFont();
PAINTSTRUCT ps;
HBRUSH hbruzh = CreateSolidBrush(RGB(0,0,0));
HDC hdz = BeginPaint(hWnd,&ps);
string s = "Memory Address";
SelectBrush(hdz,hbruzh);
SelectFont(hdz,hf);
TextOut(hdz,0,0,s.c_str(),s.length());
EndPaint(hWnd,&ps);
DeleteObject(hbruzh);
DeleteObject(hdz);
break;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
hThisInstance = hInstance;
LoadLibrary("Riched20.dll");
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
if(!(wc.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON)))) {
HRESULT res = GetLastError();
}
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = TEXT("Testcpp");
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
wc.lpszClassName,
TEXT("uTest"),
WS_OVERLAPPEDWINDOW,
300,
200,
450,
300,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nCmdShow);
MSG msg;
while (GetMessage(&msg, NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
根據MSDN,WM_PAINT僅自動之後調用任一UpdateWindow()或ReDrawWindow()時,或者當與SendMessage消息作爲消息你。然而,我沒有做任何事。我基本上只想在用戶交互後調用WM_PAINT,而不是之前...有什麼方法可以解決這個問題嗎?這是什麼造成的? (我想它的一些bizare副作用,我找不到文檔> <)
如果你想讓窗口不被繪畫,直到你得到一個特定的命令,使窗口不可見,並將其改變爲在命令處理程序中可見。 – 2010-12-22 21:22:03