Globally intercept window movement

前端 未结 2 1992
青春惊慌失措
青春惊慌失措 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?

提交回复
热议问题