Results 1 to 3 of 3

Thread: Minimizing to task tray

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I’m making a program that will usually be open for a long time running in the background of the computer. So having the program minimized on the taskbar sometimes gets in the way. I would like to be able to minimize my program to the task tray instead. Is there anybody here how knows how this is done and if so would you please tell me?

    Thanks

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    This tip will get you started.

    ------------------
    Marty

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Add an Invisible Picturebox to your Form and set the ShowInTaskbar Property to False..
    Code:
    Private 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 Type
    
    Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    
    Private Const NIF_ICON = &H2
    Private Const NIF_MESSAGE = &H1
    Private Const NIF_TIP = &H4
    Private Const NIM_ADD = &H0
    Private Const NIM_DELETE = &H2
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_RBUTTONUP = &H205
    Private Const WM_LBUTTONDBLCLK = &H203
    
    Private tTrayIcon As NOTIFYICONDATA
    
    Private Sub Form_Load()
        With tTrayIcon
            .hIcon = Icon
            .hwnd = Picture1.hwnd
            .szTip = Caption & Chr(0)
            .uCallbackMessage = WM_MOUSEMOVE
            .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
            .uID = 1
            .cbSize = Len(tTrayIcon)
        End With
        Shell_NotifyIcon NIM_ADD, tTrayIcon
    End Sub
    
    Private Sub Form_Resize()
        If WindowState = vbMinimized Then
            Hide
            WindowState = vbNormal
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Select Case ScaleX(X, vbTwips, vbPixels)
        Case WM_RBUTTONUP
            'Used for Displaying a Popup Menu
        Case WM_LBUTTONDBLCLK
            'Double Click on SysTray Icon to Show Form
            Show
        End Select
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


    [This message has been edited by Aaron Young (edited 12-09-1999).]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width