Microsoft KB Archive/197585

= How To Cover the Taskbar with a Window in Visual Basic =

Article ID: 197585

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q197585



SUMMARY
The Windows taskbar has an AutoHide property that allows it to hide at the very edge of the screen, taking up very little space, until the mouse is positioned directly over it, which causes it reappear at it's normal size. When you set the AutoHide property, a maximized window covers the entire screen. If you do not set the AutoHide property, a maximized window covers the entire screen except for the area occupied by the taskbar.



MORE INFORMATION
There is no programmatic way to change the AutoHide property in Microsoft Windows. To size a Visual Basic form so that it fills the entire screen, including covering the taskbar if it is showing, you must explicitly set the height and width of the window.

In the following sample code, the SetWindowPos API enables the specified window to cover the entire screen, including covering all taskbars. This or any similar approach only works if the window is not already maximized. If the window is currently maximized, you must first set the window to a restored/normal state prior to using the SetWindowPos API.

Step-by-Step Procedures
 Create a new Standard EXE project. Form1 is created by default. Add a CommandButton to Form1.  Paste the following code into Form1's code window:

Private Sub Command1_Click Dim cx As Long Dim cy As Long Dim RetVal As Long

' Determine if screen is already maximized. If Me.WindowState = vbMaximized Then ' Set window to normal size Me.WindowState = vbNormal End If

' Get full screen width. cx = GetSystemMetrics(SM_CXSCREEN)

' Get full screen height. cy = GetSystemMetrics(SM_CYSCREEN)

' Call API to set new size of window. RetVal = SetWindowPos(Me.hwnd, HWND_TOP, 0, 0, cx, cy, _           SWP_SHOWWINDOW) End Sub

 Add a standard module to the Project menu.  Paste the following code into the module:

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _        ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _         ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long

Public Const SM_CXSCREEN = 0 Public Const SM_CYSCREEN = 1 Public Const HWND_TOP = 0 Public Const SWP_SHOWWINDOW = &H40

 Run the project. Click the CommandButton.</li></ol>

RESULT: The form will cover the entire screen, including any taskbars.

This works for all taskbars on the primary monitor, including the shell's taskbar and any other taskbars (such as the Microsoft Office taskbar) that are written to use the standard Desktop Application Toolbar interface.

<div class="references_section">