I have a WPF application that opens a new process (Notepad.exe) using the Process.Start() method. I wrote code that prevents the user from moving the Notepad window where the Top property of the window cannot be less that 130 pixels. I used info from this SO question where I eventually used the following code to manage this movement
Here is the windows event delegate that I defined when the target window is moved:
protected void TargetMoved(IntPtr hWinEventHook, Hook.SWEH_Events eventType, IntPtr hWnd, Hook.SWEH_ObjectId idObject, long idChild, uint dwEventThread, uint dwmsEventTime)
{
if (hWnd == targethWnd &&
eventType == Hook.SWEH_Events.EVENT_OBJECT_LOCATIONCHANGE &&
idObject == (Hook.SWEH_ObjectId)Hook.SWEH_CHILDID_SELF)
{
rect = Hook.GetWindowRect(hWnd);
int x = rect.Left;
int y = rect.Top;
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
if (rect.Left <= 0)
x = 0;
if (rect.Top <= 130)
y = 130;
UnsafeNativeMethods.MoveWindow(targethWnd, x, y, width, height, true);
}
}
This code works fine, it keeps that window within the boundaries, but there is an annoying issue: While the window is being dragged above the 130 pixel mark (when Top becomes less than 130), the window flickers back and forth between where I am dragging it, and where it is being stopped.
How can I remove this flickering?