I have subscribed to the BeforeMove
event for explorer and inspector windows to know when it is being moved. When this event is fired I set a global variable to true. Now I need to know how to detect when BeforeMove
stops so I can set the same global variable back to false when explorer/inspector window stops moving. How can I do it?

- 47,483
- 3
- 24
- 45

- 9,848
- 22
- 141
- 284
-
Why do you need to do that? Are you overlapping a window (which is not a child on top)? If it is a child, it will move along with the explorer/inspector. – Dmitry Streblechenko Feb 22 '23 at 22:07
-
@DmitryStreblechenko Hello, well it is a use case very difficult to explain but i will try. Basically i have a custom task pane (ctp) and i don't allow user to close or resize it instead i show a popup alert when user tries to do it and then reset the ctp height to its default or make the ctp visible again depending on the case (resize/close). The problem i have is with the resize event of the ctp. When the Outlook explorer is moved between monitors with different screen resolutions and/or scale factor, the resize event of the wpf control embedded within the ctp is fired. – Willy Feb 22 '23 at 22:44
-
@DmitryStreblechenko [continuation] So I need to distinguish if the resize event come from it or from a user explicit resize action. So i have subscribed to BeforeMove event from the explorer window. When this event is fired i set a global variable to true indicating that window is moving so if the resize event is fired when moving window I know that user are moving Outlook window between monitors and simply i don't show the popup alert. But what if the user resizes ctp explicitly, how can i differenciate it? – Willy Feb 22 '23 at 22:49
-
@DmitryStreblechenko [continuation] I can differenciate it by consulting the global variable, if true, indicates that window is moving between monitors so i don't show the popup alert, otherwise, if it is false, then it indicates the user has explicitly resized the ctp so i show the popup alert. In order this to work, i need to set the global variable back to false once user stops dragging/moving the outlook window, otherwise i cannot differenciate the resize event from which use case comes from. This is why i need to detect when user stops moving/dragging the Outlook window. – Willy Feb 22 '23 at 22:52
2 Answers
The Outlook object model doesn't provide any event for that. You can check out the window location (see the Left
, Top
properties of the Explorer
and Inspector
class) periodically (set a timer, for example) to detect changes or when the action is completed. However, it doesn't give a definitive knowledge when the action is completed.
This is only detectable if you understand the user actions that trigger a drag, and can detect them as you're going to have to distinguish between a drag operation and normal keyboard/mouse actions. The hook in question is the WH_CALLWNDPROC
hook, registered with SetWindowsHookEx. Basically, you define a WndProc
procedure which gets all the messages the applications window does (including mouse movement) and its up to you to determine when a drag operation starts and when it stops.

- 47,483
- 3
- 24
- 45
Based on your comments - when BeforeMove event fires, record the values of the Top/Bottom/Width/Height
properties. When WPF control reside event fires, look at the current values of the Top/Bottom/Width/Height
properties - if they are different from the ones saved before, it is the Exporter/Inspector moving, and not your CTP being resided, so you can ignore it.

- 62,942
- 4
- 53
- 78
-
Yep, but i think it would not work, you need to update those values Top/Left/Width/Height when user stops moving window, otherwise it will not work. Imagine the following scenario: User starts moving window from one monitor to another, so BeforMove fires and you record those values (e.g. let's say Top=0, Left=0, Width=100, Height=100). User stops moving window and window is now placed in the another monitor (but you don't update those values). – Willy Feb 22 '23 at 23:52
-
[Continuation} Now user resizes explicitly the ctp height, so the wpf user control resize event fires, then you get the new values (Top, Left, Width and Height), you proceed to compare them with the stored ones which continue being the same (Top=0, Left=0, Width=100, Height=100) as you didn't update them once window stopped moving so when comparing the stored ones with the current ones they are different so you don't show the popup alert but you should show it. – Willy Feb 22 '23 at 23:52
-
It is the same problem as using the boolean global variable, you need to update those values once window stops moving. And the problem is this: how to detect when window stops moving and then update those values. The thing is that not always the wpf user control resize event fires when you move window from one monitor to another, it only fires sometimes. – Willy Feb 22 '23 at 23:56