Processing Windows messages in WinForm by overriding the WndProc method
The system.windows is used in WPF. Sytem.Windows.Controls and other namespaces, no WndProc function
In WPF, processing a message first to get the window handle, creating a HwndSource object to add a message-handling callback function through the HwndSource object.
In addition, WPF does not have a handle property and cannot directly get a handle to a window
You can specify a callback function for message processing in the constructor, or it can be specified after the resource is initialized, and can be specified in many places.
The following is specified after the resource is initialized
protected override void Onsourceinitialized (EventArgs e)
{
Base. Onsourceinitialized (e);
HwndSource HwndSource = presentationsource.fromvisual (this) as HwndSource;
if (HwndSource! = null)
Hwndsource.addhook (New HwndSourceHook (this. WndProc));
}
Note To use the System.Windows.Interop namespace, the above adds a callback delegate
Protected virtual INTPTR WndProc (IntPtr hwnd, int msg, IntPtr wParam, IntPtr LParam, ref BOOL handled)
{
Switch (msg)
{
Case Win32.wm_nchittest:
{
Point mousescreenpoint = new Point (Lparam.toint32 () & 0xFFFF, Lparam.toint32 () >> 16);
Point mousewindowpoint = this. Pointfromscreen (Mousescreenpoint);
if (Mousewindowpoint.x < && Mousewindowpoint.y < 10)
{
handled = TRUE;
Return (INTPTR) Win32.httopleft;
}
Break
}
}
return IntPtr.Zero;
}
Here is a reference to pass the parameter handled, after processing the message set to True tells the system that the message has been processed.
Working with Windows messages in WPF