Programmatically Minimize an Application in .NET CF 2.0

I once made a solution that runs on full screen. The solution was written completely in managed code (except for the CE Setup and other small stuff..). Since I took over the screen completely, I don't have access to the (X) button in the upper right corner of the screen. I wanted the application running at all times, but I also wanted the user to be able to get in and out of the application. Since the user won't be able to access the Start button, I added a "Close" button to my application. This "Close" button won't exit the application, instead it will just Minimize the application.

In the .NET Compact Framework 2.0, you can't just set the form's WindowState to WindowState.Minimized since the WindowState enum only contains Normal and Maximized. Currently, the only way you can programmatically minimize an application is by doing a P/Invoke to ShowWindow and passing SW_MINIMIZE to specify how the window will be displayed. It is also required that your Form has the Taskbar visible, this is done by setting the following properties:

  FormBorderStyle = FormBorderStyle.FixedDialog;
  WindowState = FormWindowState.Normal;
  ControlBox = true;
  MinimizeBox = true;
  MaximizeBox = true;

Here's a small code snippet of how to minimize your application

static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_MINIMIZED = 6;

void Minimize() {
  // The Taskbar must be enabled to be able to do a Smart Minimize
  this.FormBorderStyle = FormBorderStyle.FixedDialog;
  this.WindowState = FormWindowState.Normal;
  this.ControlBox = true;
  this.MinimizeBox = true;
  this.MaximizeBox = true;

  // Since there is no WindowState.Minimize, we have to P/Invoke ShowWindow
  ShowWindow(this.Handle, SW_MINIMIZED);

Programmatically Refreshing the Today Screen

A simple trick for forcing the today screen to re-read from the registry (or refresh) is by sending the message WM_WININICHANGE with the parameter 0x000000F2 to a window called the DesktopExplorerWindow.

Here's a small code snippet on how to accomplish this programmatically:

void RefreshTodayScreen() {
  HWND hWnd = FindWindow(_T("DesktopExplorerWindow"), _T("Desktop"));
  SendMessage(hWnd, WM_WININICHANGE, 0x000000F2, 0);

and in managed code...

static extern IntPtr FindWindow(string class_name, string caption);

static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

const uint WM_WININICHANGE = 0x1a;

void RefreshTodayScreen() {
  IntPtr hWnd = FindWindow("DesktopExplorerWindow", "Desktop");
  SendMessage(hWnd, WM_WININICHANGE, 0x000000F2, 0);

Querying Overridden Check-in Policies

In the Team Foundation Server, you can enable certain policies for checking in files. The default install will contain policies that can verify that the check-in is associated with a work item, or that unit tests were created for the changes made, etc etc. But even though certain rules were made for checking in, the user is still given the possibility to override these policies, if the user decides to override the policy then the user is prompted with a dialog, where the user can input their "reason" for ignoring such policies. This action is logged to the TFS databases.

In this article I will show you how to query the database "TfsVersionControl" and "TfsWarehouse" to get more information for the overridden check-in policy.

let's start off with openning a query to the database server that TFS uses then type in the following query:

    'Changeset ID'=p.ChangeSetId,
    'Creation Date'=cs.CreationDate,
    'Check-in Comment'=cs.Comment,
    'Override Reason'=p.Comment,
    TfsVersionControl..tbl_PolicyOverride p
    TfsVersionControl..tbl_ChangeSet cs ON p.ChangeSetId=cs.ChangeSetId
    TfsVersionControl..tbl_Identity i ON cs.OwnerId=i.IdentityId
    TfsWarehouse..Person pr ON i.DisplayName=(pr.Domain+'\'+pr.Alias)
    cs.ChangeSetId DESC

This query will provide you with the change set number, date, check-in comment, override reason, change set owner and email address for every overridden check-in policy.

My first ever blog post

After being asked numerous times why I don't have a blog, I finally decided that maybe I should have one.

For a short introduction:

My name is Christian Resma Helle, I was born and raised in the Philippines. I currently reside and work in Copenhagen, Denmark. I work as a Developer/Consultant specializing in Windows Mobile based solutions and have taken an interest in the Visual Studio Team System.

My blog would probably contain technical articles regarding Windows Mobile development and the VSTS.