Form2.Show 1后,form1的窗体在任务上的状态怎么保持凹下去的感觉呀。

解决方案 »

  1.   

    很麻烦,需要用钩子截获form2的wm_create消息,在此加上窗口的owner的句柄。
    先简单的实现一下:
    form1代码: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 Const GWL_STYLE = (-16)
    Private Const WS_CHILD = &H40000000Private Sub Command1_Click()
        Load Form2
        SetWindowLong Form2.hwnd, GWL_STYLE, GetWindowLong(Form2.hwnd, GWL_STYLE) Or WS_CHILD
        Form2.Show
        Me.Enabled = False
    End Sub
    form2代码:Private Sub Form_Unload(Cancel As Integer)
        Form1.Enabled = True
    End Sub
      

  2.   

    设计时form2的ShowInTaskbar属性为False。
      

  3.   

    form2的标题栏变成灰色的了。
      

  4.   

    form1的代码修改如下:
    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 Const GWL_STYLE = (-16)
    Private Const WS_CHILD = &H40000000
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_NCACTIVATE = &H86Private Sub Command1_Click()
        Load Form2
        SetWindowLong Form2.hwnd, GWL_STYLE, GetWindowLong(Form2.hwnd, GWL_STYLE) Or WS_CHILD
        Form2.Show
        Me.Enabled = False
        Call Timer1_Timer
        
        Me.Timer1.Interval = 100
        Me.Timer1.Enabled = True
    End SubPrivate Sub Timer1_Timer()
        Dim frm As Form
        
        SendMessage Me.hwnd, WM_NCACTIVATE, 1, ByVal 0&
        For Each frm In Forms
            If frm.Name = "Form2" Then
                SendMessage frm.hwnd, WM_NCACTIVATE, 1, ByVal 0&
            End If
        Next
    End Sub
    form2的代码修改如下:Private Sub Form_Unload(Cancel As Integer)
        Form1.Enabled = True
        Form1.Timer1.Enabled = False
    End Sub还是别忘了设置ShowInTaskbar属性。
      

  5.   

    还是没太完美。form2鼠标拖动标题栏移动时没有虚线框。