8

According to MS when you show a modal form in VB6 it does not show in the taskbar 'by design'

But is there any way to make a VB6 Modal form to be shown in the taskbar (the ShowInTaskbar property has no effect when it is modal)

In one of our apps we have a modal login form that is the first form to be shown in the application after the splash screen unloads so if the user moves another window over the top you don't know it is loaded.

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143

3 Answers3

8

You can use something like this in the modal form

Private Const WS_EX_APPWINDOW               As Long = &H40000
Private Const GWL_EXSTYLE                   As Long = (-20)
Private Const SW_HIDE                       As Long = 0
Private Const SW_SHOW                       As Long = 5

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
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 ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Private m_bActivated As Boolean

Private Sub Form_Activate()
    If Not m_bActivated Then
        m_bActivated = True
        Call SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW)
        Call ShowWindow(hwnd, SW_HIDE)
        Call ShowWindow(hwnd, SW_SHOW)
    End If
End Sub
wqw
  • 11,771
  • 1
  • 33
  • 41
5

Put this code in your modal window:


    Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

    Private Sub Form_Activate()
        Call ShowWindow(Me.hWnd, vbHide)
        Me.Caption = Me.Caption
        Call ShowWindow(Me.hWnd, vbNormalFocus)
    End Sub

Kavian K.
  • 59
  • 1
  • 1
  • This worked for me and is much easier than subclassing. Could someone explain what `Me.Caption = Me.Caption` is for? – Felix Dombek Jul 30 '15 at 17:35
  • As far as I can tell it causes Windows to update some of the window's properties so that it re-evaluates whether the window should appear in the task bar when you show it again. By using the vbNormalFocus flag with ShowWindow, windows will treat it as though it is the first time the window is being displayed as long as you have "changed" some of the window's properties. – cjc Nov 16 '16 at 23:21
1

You will have to do subclassing, something like this from VBAccelerator.

Disclaimer - adapted from PM2's answer to this question which is probably a duplicate, but we can't tell because the original poster never told us whether their form was modal.

Community
  • 1
  • 1
MarkJ
  • 30,070
  • 5
  • 68
  • 111