Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Dim task As Long
Dim win As Long
Dim bswap As BooleanPrivate Sub Command1_Click()
    If Not bswap Then
        SetParent win, Me.hwnd
        ShowWindow win, 0
    Else
        SetParent win, task
        ShowWindow win, 1
    End If
    bswap = Not bswap
End SubPrivate Sub Form_Load()
    task = FindWindow("Shell_TrayWnd", vbNullString)
    If task Then
        win = FindWindowEx(task, 0, "Button", vbNullString)
        If win Then
        Else
            MsgBox "没有找到开始按钮"
            Unload Me
        End If
    Else
        MsgBox "没有找到任务栏"
        Unload Me
    End If
End SubPrivate Sub Form_Unload(Cancel As Integer)
    If bswap Then
        SetParent win, task
        ShowWindow win, 1
    End If
End Sub怎么去掉那个判断啊,因为本人对API不是很熟!

解决方案 »

  1.   

    '是不是这个意思:
    Private Sub Command1_Click()
        SetParent win, Me.hwnd
        ShowWindow win, 0
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        SetParent win, task
        ShowWindow win, 1
    End Sub
      

  2.   

    去掉这个:     Private Sub Form_Load()
        task = FindWindow("Shell_TrayWnd", vbNullString)
        If task Then
            win = FindWindowEx(task, 0, "Button", vbNullString)
            If win Then
            Else
                MsgBox "没有找到开始按钮"
                Unload Me
            End If
        Else
            MsgBox "没有找到任务栏"
            Unload Me
        End If
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        If bswap Then
            SetParent win, task
            ShowWindow win, 1
        End If
    End Sub
    把它做成一个模块!!    不要上面的那个判断!
      

  3.   

    API都改成PUBLICsub main()
    SetParent 开始按钮.Hwnd, 窗体名.hwnd
    ShowWindow 开始按钮.Hwnd, 0
    end sub
      

  4.   

    你应该是这个意思吧
    '把那些声明和变量移到模块中去就可以
    '改变父窗体(hwnd:要改变的窗体的句柄)
    Public Function  ChangeParent(hwnd as long) as boolean
        On Error goto Errhandle
        task = FindWindow("Shell_TrayWnd", vbNullString)
        win = FindWindowEx(task, 0, "Button", vbNullString)
        if win<>0 then
            SetParent win,hwnd
            ShowWindow win, 0
        else
            exit Function
        end if
        changeParent=true
        exit function
    ErrHandle:
        changeParent=false
    End Function
    '恢复父窗体
    Public sub ResumeParent(hwnd as long ) 
         SetParent win, task
         ShowWindow win, 1
    end sub
      

  5.   

    这是一个屏蔽win键的程序~~~我想去掉::  If task Then
            win = FindWindowEx(task, 0, "Button", vbNullString)
            If win Then
            Else
                MsgBox "没有找到开始按钮"
                Unload Me
            End If
        Else
            MsgBox "没有找到任务栏"
            Unload Me
        End If
    这个判断!!! 把它改成一个模块来用!!!!