Windows Mobile makes a powerful business tool, however in an application where we just want our users to use the application for their job and not start playing Bubble Breaker we need to protect our application to stop them quitting or messing with settings.
I do this in a number of ways, firstly I password protect any vital settings away so they cannot be changed by our end user fiddling, i.e
| Notice the password box and the bottom, which is required before any changes can be made. |
I use something I have coined called Protected Mode. I store a value in the registry that sets whether my application needs to be locked down or not. Once again this is set on or off in the password protected settings form as shown above.
I password protect the quitting of the application as shown below.
| Protected mode stopping our user quitting our application without entering a password. |
Having this protected mode switch allows deployment of the same application to both power users who need the full functionality of their phone et. or to users who simply need the device to run one application.
If our application is running in protected mode, I hide the standard form titles to prevent the user launching other applications. I use my own user control to achieve this -
Very simply this control is just a text-box control placed on a user control object. I call the following in the Load object of any of my forms.
if (Settings.Protected) Core.FormTitle(this);
This checking that we are in protected mode changes the forms title bar. Here's the code to-do this -
public static void FormTitle(Form form)
{
form.ControlBox = false;
form.MaximizeBox = false;
form.MinimizeBox = false;
form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Maximized;
if (form.Text == "")
{
return;
}
int taskbarHeight = Screen.PrimaryScreen.Bounds.Height - Screen.PrimaryScreen.WorkingArea.Height;
System.Windows.Forms.Control.ControlCollection c = form.Controls;
form.SuspendLayout();
foreach (Control conts in c)
{
conts.Top += taskbarHeight;
}
Controls.TitleBar t = new Controls.TitleBar();
t.Width = Screen.PrimaryScreen.WorkingArea.Width;
t.Height = taskbarHeight;
t.Top = 0;
t.Text = form.Text;
form.Controls.Add(t);
form.ResumeLayout();
}
So its not perfect but this deters users from being able to run other programs or change settings without requiring other tools. It has made my warehouse and field service applications less error prone and keeps the devices deployed and running for longer. This has to be a good thing...