本文介绍了WM_ACTIVATE行为异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个困扰我很长时间的难题.这是一个简单的小程序,可突出显示我在说什么:
Here's a puzzle that's baffled me for quite some time. Here's a simple little program to highlight what I'm talking about:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_ACTIVATE:
if(wParam == WA_INACTIVE)
SetWindowText(hwnd, "Inactive");
else
SetWindowText(hwnd, "Active");
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Delay the start of the program by five seconds to highlight odd WM_ACTIVATE behaviour.
Sleep(5000);
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "myWindow";
RegisterClass(&wc);
HWND hwnd = CreateWindow("myWindow", "Default Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, 500, 100, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0) > 0)
DispatchMessage(&Msg);
return Msg.wParam;
}
推荐答案
这篇关于WM_ACTIVATE行为异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!