1
要求是將我的信息繪製在另一個應用程序的窗口中。 爲了照顧z順序等,掛鉤WH_GETMESSAGE並在WM_PAINT上繪製看起來不錯。掛鉤窗口掛鉤時不能正確繪製
但是有些WM_PAINT是用於我關心的窗口區域,但其他WM_PAINT用於完全不同的東西,如上下文菜單或按鈕。
示例記事本與寫入「Hello」的疊加層掛鉤在記事本屏幕中。這工作正常。但是,當右鍵單擊記事本時,上下文菜單會與Hello進行疊加。基本上,上下文菜單被銷燬。
是否有確定WM_PAINT是上下文菜單的優雅方式?
LRESULT CALLBACK overlayHook(int code, WPARAM wParam, LPARAM lParam) {
//Try and be the LAST responder to WM_PAINT messages;
LRESULT retCode = CallNextHookEx(hhk, code, wParam, lParam);
//Per GetMsgProc documentation, don't do anything fancy
if(code < 0) {
return retCode;
}
//Assumes that target application only draws when WM_PAINT message is
//removed from input queue.
if(wParam == PM_NOREMOVE) {
return retCode;
}
MSG* message = (MSG*)lParam;
if(message->message != WM_PAINT) {
//Ignore everything that isn't a paint request
return retCode;
}
PAINTSTRUCT psPaint;
BeginPaint(message->hwnd, &psPaint);
HDC hdc = psPaint.hdc;
RECT r = psPaint.rcPaint;
TextOut(hdc, 10, 10, "Hello", 4);
EndPaint(message->hwnd, &psPaint);
return retCode;
}
僅對繪製更新區域進行測試是不夠的,因爲上下文菜單可能在任何地方並且包含我關心的區域。
GetClassName是有用的。其他建議是歡迎。 – s5804 2009-06-05 14:03:23