如何意识到WM_DEVICECHANGE
到来?
WndProc
的覆盖。我抓住了一大堆消息,但没有一个是 type 的WM_DEVICECHANGE
。RegisterDeviceNotification
让链接器抱怨它找不到函数!所以我被这个巫毒魔法困住了。请帮忙。
PS:当然,我已经用谷歌搜索和stackoverflowing(lol)所有这些东西大约8个小时了。
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
LPTSTR lolclassname = "lolclass";
WNDCLASS lolclass;
HWND lolwindow;
MSG lolmsg;
UINT msgstatus;
lolclass.style = CS_VREDRAW;
lolclass.lpfnWndProc = &lol_wnd_proc;
lolclass.cbClsExtra = 0;
lolclass.cbWndExtra = 0;
lolclass.hInstance = hInstance;
lolclass.hIcon = NULL;
lolclass.hCursor = NULL;
lolclass.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
lolclass.lpszMenuName = NULL;
lolclass.lpszClassName = lolclassname;
if(!RegisterClass(&lolclass)) fail("RegisterClassEx");
lolwindow = CreateWindow("lolclass", NULL, WS_MINIMIZE, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_MESSAGE, NULL, hInstance, NULL);
if(lolwindow == NULL) fail("CreateWindowEx");
/*ShowWindow(lolwindow, nCmdShow);
UpdateWindow(lolwindow);*/
do {
/* if(!SetWindowPos(lolwindow, HWND_TOPMOST, 1, 1, 1, 1,
SWP_HIDEWINDOW))
fail("SetWindowPos");*/
msgstatus = GetMessage(&lolmsg, lolwindow, 0, 0);
if(!msgstatus) break;
if(msgstatus == - 1) fail("GetMessage");
TranslateMessage(&lolmsg);
DispatchMessage(&lolmsg);
Sleep(1000);
} while(1);
return lolmsg.wParam;
}
lol_wnd_pro
c 被执行但从未在它应该执行的时候执行(当然是在设备更改时,我清楚吗?)