Created: March 1, 1995
Many Windows®-based applications can be written so that, when executed, they are shown on the desktop simply as an icon. These type of programs usually perform some kind of background task and are never maximized because no user input is required. Double-clicking an icon automatically tells Windows to maximize the application's window to a full-screen display. This article tells you how to create iconized applications in Visual Basic® that cannot be maximized.
When running an application as an icon, you must intercept the form's resize event to prevent the user from maximizing its window. The WindowState property of a form controls how a form is displayed. WindowState provides three possibilities:
If we want to make a program appear as an icon on the desktop, we set the WindowState property to a value of 1. This should be done in the Form_Load event for the startup form in Visual Basic.
When a user double-clicks on a program's icon, Windows® automatically sets its WindowState property to normal. The double-clicking triggers the Form_Resize event, which in turn maximizes the program's window. Because we don't want our program's window to be maximized at any time, we set the WindowState property to a value of 1 in the Form_Resize event. Every time our program is double-clicked, the WindowState property is always reset to "minimized." Thus, the program is never seen in a maximized state.
The following program creates a Visual Basic application that is minimized to an icon when it is executed. To terminate the program, double-click its icon.
WindowState = 1
End Sub
Sub Form_Resize()
If WindowState <> 1 Then
WindowState = 1
End
End If
End Sub