Senin, 13 Februari 2012

Immovable WPF Application (Wnd Message)

In several project, sometimes we have to build immovable application. Actually, I got that problem now. If I build application using VS 2003 or older the feature for making the immovable application is provided but in this time, I use VS 2008 which doesn’t gives that feature. So I have use the Windows message as tool for making the application to be immovable.

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