Luke
Luke

Reputation: 71

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.

Upvotes: 6

Views: 2213

Answers (2)

Hans Passant
Hans Passant

Reputation: 942438

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.

Upvotes: 6

Andrew Keith
Andrew Keith

Reputation: 7563

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.

Upvotes: 4

Related Questions