The new vbAccelerator Site - more VB and .NET Code and Controls
Source Code
3 Code Libraries Source Code &nbsp
&nbsp

Set the Show In Taskbar property at run time

VB provides a ShowInTask bar property for forms which allows you to choose whether a form is shown in the Alt-Tab sequence and the shell's task bar. However there are two limitations to this:
  • The property can't be set at run-time.
  • It doesn't seem to work at all for modal forms under NT4.0
Often it is rather handy to put a modal form in the task bar - say for example a login dialog which shows before your main form - otherwise the user can 'lose' this window behind other ones.

The rules the taskbar uses to decide whether a button should be shown for a window aren't very well documented. Here is how it is done:
'When you create a window, the taskbar examines the window’s extended style to see if either the WS_EX_APPWINDOW (&H40000) or WS_EX_TOOLWINDOW (defined as &H80) style is turned on. If WS_EX_APPWINDOW is turned on, the taskbar shows a button for the window, and if WS_EX_ TOOLWINDOW is turned on, the taskbar does not show a button for the window. A window should never have both of these extended styles. If the window doesn't have either of these styles, the taskbar decides to create a button if the window is unowned and does not create a button if the window is owned.'
Incidentally, VB forms seem to have neither of these extended styles.

Here is some code which allows you to set the WS_EX_APPWINDOW style at run time:

' Declares:
Private Const WS_EX_APPWINDOW = &H40000
Private Const WS_EX_TOOLWINDOW = &H80&
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = (-20)

Public Sub RTShowInTaskBar(ByVal hWnd As Long, ByVal bState As Boolean)
Dim lS As Long
&nbsp &nbsp lS = GetWindowLong(hWnd, GWL_EXSTYLE)
&nbsp &nbsp If (bState) Then
&nbsp &nbsp &nbsp &nbsp lS = lS Or WS_EX_APPWINDOW
&nbsp &nbsp &nbsp &nbsp lS = lS And Not WS_EX_TOOLWINDOW
&nbsp &nbsp Else
&nbsp &nbsp &nbsp &nbsp lS = lS And Not WS_EX_APPWINDOW
&nbsp &nbsp End If
&nbsp &nbsp SetWindowLong hWnd, GWL_EXSTYLE, lS
&nbsp &nbsp End Sub

You should call this code once your window has a valid hWnd and is visible, for example, in the Form_Activate event.



Back to top

Back to Source Code Overview

&nbsp
 

About  Contribute  Send Feedback  Privacy

Copyright © 1998-1999, Steve McMahon ( steve@vbaccelerator.com). All Rights Reserved.
Last updated: 15 June 1998