Wednesday, July 03, 2013

Lock task bar in windows mobile

I had to do a kiosk mode application in windows mobile for which locking task bar was very much mandatory, as I had to block users from accessing mobile settings.
Here is a small piece of code that I had to use to achieve the same.

#region enable or disable taskbar swipe
public static bool enableTaskbar(bool bEnable)
    bool bRet = false;
    IntPtr hTaskbar = FindWindow("HHTaskBar", String.Empty);
    if (hTaskbar != IntPtr.Zero)
        bRet = EnableWindow(hTaskbar, bEnable);
    return bRet;

[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClass, string lpTitle);

[DllImportAttribute("coredll.dll", SetLastError = true)]
private static extern bool EnableWindow(IntPtr hWnd, bool bEnable);

There is a catch in this code. Every time mobile is locked and unlocked, task bar can be used. So write this piece of code in paint event of the form as below.

private void frmMain_Paint(object sender, PaintEventArgs e)

No comments: