Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Determine if user is moving a window

I am going to be checking if the user is moving any window around (my application does not have an interface) and respond accordingly. What do you think is the best way to do this? Can I determine if the user is clicking on a titlebar? Can I determine if a window is being moved? I then need to grab the hWnd of the window after I know it's being moved.

like image 592
Luke Avatar asked Nov 21 '09 22:11

Luke


2 Answers

To get notifications for all windows, not just Windows Forms ones, you'll need to use a hook set by the SetWindowsHookEx() API function. You'll need a WH_CALLWNDPROC hook so you can see the WM_MOVE message that Windows sends to the window.

Unfortunately, that's a global hook. The code that implements the hook callback needs to be packaged into a DLL so that it can be injected into all target processes. That shoots a hole into your plans to use C# for this, you can't inject the CLR. The DLL must be written in unmanaged code.

This code project offers an approach, including the unmanaged injectable DLL you'll need.

like image 137
Hans Passant Avatar answered Oct 20 '22 20:10

Hans Passant


here is a technique to spy on window handles. You can inspect all the handles which are open and wait for the move messages.

EDIT

.NET spy code.

like image 42
Andrew Keith Avatar answered Oct 20 '22 21:10

Andrew Keith