Listening to another window resize events in C#

后端 未结 4 697
Happy的楠姐
Happy的楠姐 2020-12-04 20:01

I am implementing a small application (observer) that needs to \"attach\" itself to the bottom of another window (observed). The latter is not a window inside the applicatio

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 20:32

    A WH_CALLWNDPROC hook would probably suffice, this will allow you to monitor all messages destined for the window of interest.

    Are you asking how to create a global hook using C# or are you happy to create the hook in C++ and then interop with that from .NET? The second option is the route I would go.

    Basically off the top of my head, what I would do is the following

    1- Create global hook in C, and export functions to InstallHook and UninstallHook, which can be called from your C# app using Interop. InstallHook take an hwnd of the window in your C# application.

    2- Have the installed hook function post a custom message to the C# window provided in the call to InstallHook when ever there is a message you are interested in like WM_SIZE in your case.

    3- In the C# application your window that receives the posted messages from the hook will override WndProc to handle the custom message.

    That is an outline of one approach.

提交回复
热议问题