强制模态窗体显示在任务栏中

时间:2012-01-05 16:48:53

标签: vb6 modal-dialog user-experience taskbar vb6-migration

According to MS当您在VB6中显示模态表单时,它不会在任务栏中“按设计”显示

但有没有办法让VB6 Modal表单显示在任务栏中(ShowInTaskbar属性在模态时没有效果)

在我们的一个应用程序中,我们有一个模式登录表单,它是在启动屏幕卸载后在应用程序中显示的第一个表单,因此如果用户在顶部移动另一个窗口,则您不知道它已加载。< / p>

3 个答案:

答案 0 :(得分:6)

你可以在模态形式中使用这样的东西

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

答案 1 :(得分:3)

将此代码放入模态窗口中:


    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

答案 2 :(得分:1)

您必须从VBAccelerator进行子类化,例如this

免责声明 - 改编自PM2对this question的答案,其中可能重复,但我们无法分辨,因为原始海报从未告诉我们他们的表格是否是模态的。