How to Hide a VB App from the Task List and ALT+TAB OrderID: Q114776
|
This article demonstrates how to create an application that is invisible to the Windows Task List and to the fast ALT+TAB switching order.
All Visual Basic applications have a background window that handles all
messages for the application and all calls to the VBRUN300.DLL. This
background window is also the owner and parent of all non-MDI child forms.
You can use the GetWindow and ShowWindow Windows API functions to hide
this background window.
To be eligible for removal from the ALT+TAB order, an application cannot
have any visible forms. The background window is visible, but you can
use GetWindow to return the background or owner window's handle, and then
use the handle and ShowWindow to make the window invisible.
' Enter each of the following Declare statements as one, single line:
Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer,
ByVal nCmdShow As Integer) As Integer
Declare Function GetWindow Lib "User" (ByVal hWnd As Integer,
ByVal wCmd As Integer) As Integer
Const SW_HIDE = 0
Const GW_OWNER = 4
Sub Form_Load ()
Dim OwnerhWnd As Integer
Dim ret As Integer
' Make sure the form is invisible:
form1.Visible = False
' Set interval for timer for 5 seconds, and make sure it is enabled:
timer1.Interval = 5000
timer1.Enabled = True
' Grab the background or owner window:
OwnerhWnd = GetWindow(Me.hWnd, GW_OWNER)
' Hide from task list:
ret = ShowWindow(OwnerhWnd, SW_HIDE)
End Sub
Sub Timer1_Timer ()
Dim ret As Integer
' Display a message box:
ret = MsgBox("Visible by Alt+Tab. Cancel to Quit", 1, "Invisible Form")
' If cancel clicked, end the program:
If ret = 2 Then
timer1.Enabled = False
Unload Me
End
End If
End Sub
Additional query words: 2.00 3.00 hide invisable
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 2, 1999