Forcing the Icon

Shortly before entering the message loop in WinMain, most Windows applications execute the function:

ShowWindow (hwnd, nCmdShow) ;

The nCmdShow variable is passed to the program as a parameter to WinMain.

If you run a program from the File Manager (by selecting Run from the File menu, pressing Enter when the cursor is on the program name, or double-clicking the program), nCmdShow is set equal to SW_SHOWNORMAL. If you load an application as an icon (by selecting Load from the File menu or pressing Shift-Enter with the cursor on the program name), nCmdShow is set equal to SW_SHOWMINNOACTIVE. Your application usually doesn't have to figure this out but simply passes this parameter to ShowWindow.

However, you aren't required to use the nCmdShow variable with ShowWindow. Instead, FREEMEM uses the line:

ShowWindow (hwnd, SW_SHOWMINNOACTIVE) ;

This forces the window to appear as an icon regardless of the value of nCmdShow. The active program remains active.

You can perform other tricks with this technique. If you always want a particular application to appear first as a maximized full-screen display, you can use:

ShowWindow (hwnd, SW_SHOWMAXIMIZED) ;

You can even force FREEMEM to occupy a particular icon position at the bottom of the display. If you replace the existing ShowWindow call in FREEMEM with:

ShowWindow (hwnd, (int) 0xFF8F) ;

the icon will be positioned in icon slot 15. This syntax is a little obscure but is documented in the Programmer's Reference.