Search code examples
vb6modal-dialoguser-experiencetaskbarvb6-migration

Force Modal Form to be Shown in Taskbar


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.


Solution

  • 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