Results 1 to 5 of 5

Thread: Mini to task bar???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    B.C. CANADA!!
    Posts
    109

    Question Mini to task bar???

    any one know how to make it do that in vb 5
    and how to make the menu
    is it an invisible menu that i make for the menu at the task???
    Last edited by RoBskEwL; Aug 30th, 2001 at 12:46 PM.

  2. #2
    assbeef
    Guest
    You need to get your terminology straight here.
    I think I know what you want, (unlike 32 other people who have viewed this but never replied). When you say Mini (minimized) you mean show your program in the System Tray (beside the Time Display) right? And that menu you speak of is a popup menu when your icon is right clicked ?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    B.C. CANADA!!
    Posts
    109

    Question Minimize to system tray or start up on system tray???

    Yea thats exactly wat i'm talking about do you got any codes i could get??? for vb 5 enterprize!

  4. #4
    assbeef
    Guest
    I can, but i don't know about VB 5, the code works in VB6. Are there any differences in standard code in VB5? Well whatever, i will give you some code to do this. First make a Module with the following code in it:

    Option Explicit

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

    Public 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

    Public Const NIM_ADD As Long = &H0
    Public Const NIM_DELETE As Long = &H2
    Public Const NIM_MODIFY As Long = &H1
    Public Const NIF_MESSAGE As Long = &H1
    Public Const NIF_ICON As Long = &H2
    Public Const NIF_TIP As Long = &H4
    Public Const WM_LBUTTONDOWN As Long = &H201
    Public Const WM_LBUTTONDBLCLK As Long = &H203
    Public Const WM_RBUTTONUP As Long = &H205

    Public nidIcon As NOTIFYICONDATA

    Public Sub IniTrayIcon(MenuForm As Form, TrayIcon As Image, ToolTip As String)
    With nidIcon
    'add the size of the struct
    .cbSize = Len(nidIcon)
    'add the handle to the window that the function will send messages to
    .hWnd = MenuForm.hWnd
    'set up the valid members of the struct
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    'this is the message that will be sent to the hWnd above
    .uCallbackMessage = WM_LBUTTONDOWN
    'handle to the icon to add to the tray
    .hIcon = TrayIcon.Picture.Handle
    'tool tip (always add a vbNullChar to the end)
    .szTip = ToolTip & vbNullChar
    End With
    End Sub

    Public Sub ModifyTrayIcon(TrayIcon As Image, ToolTip As String)
    With nidIcon
    'add the size of the struct
    .cbSize = Len(nidIcon)
    'set up the valid members of the struct
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    'this is the message that will be sent to the hWnd above
    .uCallbackMessage = WM_LBUTTONDOWN
    'handle to the icon to add to the tray
    .hIcon = TrayIcon.Picture.Handle
    'tool tip (always add a vbNullChar to the end)
    .szTip = ToolTip & vbNullChar
    End With
    Shell_NotifyIcon NIM_MODIFY, nidIcon
    End Sub

    Public Sub ShowTrayIcon()
    Shell_NotifyIcon NIM_ADD, nidIcon
    End Sub

    Public Sub HideTrayIcon()
    Shell_NotifyIcon NIM_DELETE, nidIcon
    End Sub

    Now lets say you make a form called frmTrayTest
    Put either a picture box or image box on it named whatever you want. (for example purposes lets just call it picIcon, make sure you have a icon loaded into it!) Now, you wanted the icno to show when you minimized that form? First we must Initialize it, put this code in frmTrayTest:

    Private Sub Form_Load()
    'The following code initializes it
    IniTrayIcon(Me, picIcon, "Tray Test Application!")
    End Sub

    Private Sub Form_Resize()
    If Me.WindowsState = 1 Then
    'Show icon if minimized
    ShowTrayIcon()
    Else
    'Hide icon otherwise
    HideTrayIcon
    End If

    Now for the right clicking part of your icon. First setup a new popupmenu in the Menu Editor for frmTrayTest (name it TrayMenu, and uncheck the visible option) Add this code to your form:

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    Select Case CLng(x \ Screen.TwipsPerPixelX)
    Case WM_LBUTTONDBLCLK
    'if double clicked restore window
    Me.WindowState = 0
    Case WM_RBUTTONUP
    'if right clicked show menu
    PopUpMenu TrayMenu
    End Select
    End Sub


    And there you have it! I hope it works for you in VB5.

  5. #5
    Junior Member
    Join Date
    Nov 2002
    Posts
    19
    But I we will have some problem with the menu. When we click on the icon, it will apear a menu but when we click out of the menu, it will not disapear...

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