掛鈎時掛鈎窗口未正確繪制

[英]Overlay Window not drawing correctly when hooking


The requirement is to draw my information in side of another application's window. To take care of z order and so forth hooking WH_GETMESSAGE and draw on WM_PAINT seem good.

要求是在另一個應用程序窗口的一側繪制我的信息。要照顧z順序等等掛鈎WH_GETMESSAGE並在WM_PAINT上繪圖似乎很好。

However some WM_PAINT are intended for the window area of my concern, but other WM_PAINT are for something completely different, like a context menu or button.

但是一些WM_PAINT用於我關注的窗口區域,但是其他WM_PAINT用於完全不同的東西,如上下文菜單或按鈕。

Example Notepad is hooked with an overlay writing "Hello" into the Notepad screen. This works fine. However when right clicking Notepad the context menu gets overlay with Hello. Basically the context menu is destroyed.

示例記事本與記事本屏幕中寫入“Hello”的疊加層掛鈎。這很好用。但是,當右鍵單擊記事本時,上下文菜單會覆蓋Hello。基本上上下文菜單被破壞了。

Is there an elegant way of determining what WM_PAINT is context menu?

是否有一種優雅的方式來確定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;
}

It is not enough to test for the draw update region, because the context menu could be anywhere and contain the area of my concern.

僅測試繪圖更新區域是不夠的,因為上下文菜單可以在任何地方並包含我關注的區域。

1 个解决方案

#1


I don't know of any elegant way to do this, but you could use GetWindowLong() to get the window's style or GetClassName() to get its class name, and then base your filtering decisions on those values.

我不知道有任何優雅的方法,但你可以使用GetWindowLong()獲取窗口的樣式或GetClassName()來獲取它的類名,然后根據這些值做出過濾決策。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/06/03/72102a7e9140f66795fcb685b64fca06.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com