I believe all of you have heard many things about WndProc or the sub method of this. This time I will use it in my Project. Below is the source code to make hook to application with the WndProc. The code will make the application cannot be moved or closed by user
private const int WM_SYSCOMMAND = 0x0112;
private const int SC_MOVE = 0xF010;
private const int SC_CLOSE = 0xF060;
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
// Handle messages...
if (msg == WM_SYSCOMMAND)
{
//if ((wParam.ToInt32() & 0xFFFF0) == SC_MOVE) handled = true; ;
//if ((wParam.ToInt32() & 0xFFFF0) == SC_CLOSE) handled = true; ;
}
return IntPtr.Zero;
}
#endregion
Those codes will be called by the initialization event of application. Below is the source code of hooking Windows Message activation in Source Initialization.
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
By those two code your application cannot be moved and closed !!!! How enjoy.....
Tidak ada komentar:
Posting Komentar