HOWTO: Cover the Taskbar with a Window in Visual Basic
ID: Q197585
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
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.
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.
REFERENCES
For information on how to do this in C/C++, please see the following
article in the Microsoft Knowledge Base:
Q179363
: HOWTO: Cover the Task Bar with a Window
The code in this article can easily be adapted to work with the sample code
found in the following article in the Microsoft Knowledge Base:
Q161299
: HOWTO: Capture and Print the Screen, a Form, or any Window
Additional query words:
tray auto hide autohide properties
Keywords : kbAPI kbGrpUser kbVBp400 kbVBp500 kbVBp600 kbGrpVB
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
|