在网上下载了一个系统托盘的例子,当窗口最小化的时候,任务栏右小角已经有托盘图标了,但是在桌面上的左下角还有一个标题栏,怎么隐藏?

解决方案 »

  1.   

    在设计时将窗体的ShowInTaskbar 属性改成 False 啊。在程序运行时好像不能修改ShowInTaskbar属性
      

  2.   

    ShowInTaskbar的属性已经是False了,但还是不行啊。
      

  3.   

    Form_Resize 事件中判断是否是最小化,然后设置窗口 Visible =False
      

  4.   

    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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Const WS_POPUP = &H80000000
    Private Const GWL_STYLE = (-16)
    Private Const WS_EX_APPWINDOW = &H40000
    Private Const GWL_EXSTYLE = (-20)
    Private Const SW_HIDE = 0
    Private Const SW_SHOW = 5
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As LongPrivate Sub Command1_Click()
        Dim winstyle As Long
        Dim hwndParent As Long
        Dim childhwnd As Long
        childhwnd = FindWindow(vbNullString, "Form1")
        winstyle = GetWindowLong(childhwnd, GWL_EXSTYLE)
        winstyle = winstyle And Not WS_EX_APPWINDOW
        ShowWindow childhwnd, SW_HIDE                   ' 一定要先隐藏然后显示
        SetWindowLong childhwnd, GWL_EXSTYLE, winstyle
        ShowWindow childhwnd, SW_SHOW
    End Sub
      

  5.   

    对窗口Form_Resize 事件进行处理:
    Private Sub Form_Resize()
        Me.Visible =not (Me.WindowState =1)   '最小化时隐藏。
    End Sub
      

  6.   

    Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
      

  7.   

    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPublic Type NOTIFYICONDATA
        cbSize As Long
        hwnd As Long
        uID As Long
        uFlags As Long
        uCallbackMessage As Long
        hIcon As Long
        szTip As String * 64
    End TypePrivate TheData As NOTIFYICONDATAPublic Sub AddToTray(frm As Form, mnu As Menu)    Set TheForm = frm
        Set TheMenu = mnu
        
        OldWindowProc = SetWindowLong(frm.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
        
        With TheData
            .uID = 0
            .hwnd = frm.hwnd
            .cbSize = Len(TheData)
            .hIcon = frm.Icon.Handle
            .uFlags = NIF_ICON
            .uCallbackMessage = TRAY_CALLBACK
            .uFlags = .uFlags Or NIF_MESSAGE
            .cbSize = Len(TheData)
        End With
        Shell_NotifyIcon NIM_ADD, TheData
    End Sub