Globally intercept window movement

前端 未结 2 1991
青春惊慌失措
青春惊慌失措 2021-02-09 16:27

I am having trouble getting a global system hook to work. I want to be notified whenever a window is moving, as early as possible, and change the window size. This means the CBT

相关标签:
2条回答
  • 2021-02-09 16:54

    Hm, I would've thought that HCBT_MOVESIZE is precisely what you want, given that the MSDN says this about CBT hooks:

    The system calls this function before activating, creating, destroying,
    minimizing, maximizing, moving, or sizing a window.

    and in particular:

    HCBT_MOVESIZE
        A window is about to be moved or sized.

    (these quotes were taken from http://msdn.microsoft.com/en-us/library/ms644977%28VS.85%29.aspx)

    ...so I'd have thought that you get the HCBT_MOVESIZE call in time. The hook function which handles HCBT_MOVESIZE is also allowed to return an integer so that the system can determine whether the operation is allowed or should be prevented. Hence, given that the HCBT_MOVESIZE hook should get an option to prevent the operation, I'd say it's called before the move event occurred.

    Are you really sure the hook function is called after the move event? If you do a GetWindowRect call on the particular handle within your hook function, does the returned rect equal the rectangle which is passed to the hook function?

    0 讨论(0)
  • 2021-02-09 16:56

    Hooks are pretty heavy. You only want to use them when you absolutely have to.

    That said, you could use one of the basic hooks simply as a way to get into the process. Once in the process, you could subclass the window you're interested in and handle the sizing messages in your subclass proc rather than trying to catch everything at the hook level.

    Depending on what you want to do in response to the resize, you might need some interprocess communication.

    0 讨论(0)
提交回复
热议问题