Global window motion switching

I am having problems connecting the global system to work. I want to receive notifications when the window moves as early as possible and to resize the window. This means that the CBT hook HCBT_MOVESIZE will not cut it, it will only happen after moving the window. I want to bind the actual movement of the window and be able to resize the window while moving.

Hooks are specified from the DLL, and the callback function is inside this DLL. This is what I tried.

  • WH_CALLWNDPROC . It warns me when a window is moved ( WM_MOVING received for windows from other applications), but I cannot change the contents of the message.
  • WH_CALLWNDPROCRET Same as WH_CALLWNDPROC .
  • CBT hook HCBT_MOVESIZE . The event takes place until late.
  • WH_GETMESSAGE . Never accept WM_MOVE , WM_MOVING or WM_WINDOWPOSCHANGING . This hook will allow me to change posts.

Update : Windows event interceptors seem to allow me to capture it:

 hWinEventHook = SetWinEventHook(EVENT_SYSTEM_MOVESIZESTART, EVENT_SYSTEM_MOVESIZEEND, NULL, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); 

However, this creates another problem: resizing a window using SetWindowPos() does not work (it SetWindowPos() in order, but immediately returns to its previous size), although I use SWP_NOSENDCHANGING . Ideas?

Update 2 . The subclass seems to work, but Visual Studio crashes after each program (like so many other windows). It works well if I put breakpoints and go through unsubclassing, but not when I let the program run on its own. Ideas?

I have a CBT hook (it was there before), and whenever HCBT_ACTIVATE sent for a new window, I delete any previous subclass using SetWindowLongPtr() (this should also be done on the 64-bit version) and then subclass the new window. If I put a breakpoint anywhere and immediately resume the session when it breaks, everything works fine. However, when I have no breakpoints, Visual Studio crashes when the program exits.

+6
c ++ winapi
source share
2 answers

Hm, I would have thought that HCBT_MOVESIZE is exactly what you want, given that MSDN is talking about this with 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 are taken from http://msdn.microsoft.com/en-us/library/ms644977%28VS.85%29.aspx )

... so I would think that you would receive the HCBT_MOVESIZE call on time. The hook function that processes HCBT_MOVESIZE can also return an integer so that the system can determine whether the operation is allowed or should be allowed. Therefore, given that the HCBT_MOVESIZE hook should be able to prevent the operation, I would say that it called before the move event occurred.

Are you really sure that the hook function is called after the move event? If you call GetWindowRect for a specific handle in your hook function, does the rectangle return the rectangle that is passed to the hook function?

+1
source share

The hooks are pretty heavy. You only want to use them when you absolutely need to.

However, you can use one of the main hooks just as a way to penetrate this process. After that, you can subclass the window you are interested in and process the size messages in your subclass of proc, rather than trying to catch everything at the hook level.

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

+1
source share

All Articles