Results 1 to 5 of 5

Thread: [RESOLVED] Minimize to tray

  1. #1

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Resolved [RESOLVED] Minimize to tray

    how can i use this code http://vbforums.com/showpost.php?p=2273373
    on a command button instead of minimize. this is because i dont want my form to be resizable therefore i'm using a fixed single boreder on the form and it doesnt show the minimize button

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Minimize to tray

    Just move this part from the resize event of the form to ur click event of the button
    VB Code:
    1. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    2. 'declaration for putting the application to system tray
    3. Private Type NOTIFYICONDATA
    4.     cbSize As Long
    5.     hwnd As Long
    6.     uId As Long
    7.     uFlags As Long
    8.     uCallBackMessage As Long
    9.     hIcon As Long
    10.     szTip As String * 64
    11. End Type
    12.  
    13.     'declare constants
    14. Private Const NIM_ADD = &H0
    15. Private Const NIM_MODIFY = &H1
    16. Private Const NIM_DELETE = &H2
    17. Private Const WM_MOUSEMOVE = &H200
    18. Private Const NIF_MESSAGE = &H1
    19. Private Const NIF_ICON = &H2
    20. Private Const NIF_TIP = &H4
    21.  
    22. 'The following constants are used to determine the mouse input on the
    23.  
    24.     'Left-click
    25. Private Const WM_LBUTTONDBLCLK = &H203   'Double click
    26. Private Const WM_LBUTTONDOWN = &H201     'down
    27. Private Const WM_LBUTTONUP = &H202       'up
    28.  
    29.     'Right-click
    30. Private Const WM_RBUTTONDBLCLK = &H206   'Double click
    31. Private Const WM_RBUTTONDOWN = &H204     'down
    32. Private Const WM_RBUTTONUP = &H205       'up
    33.  
    34. 'Dimension a variable as the user-defined data type.
    35. Dim nid As NOTIFYICONDATA
    36.  
    37.  
    38. Private Sub Ex_Click()
    39. Unload Me
    40. Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
    41. End Sub
    42. '   one main menu by Caption"Menu" name "TrayMenu"
    43. '   one sub menu by name caption "Exit" name "Ex"
    44. '   one sub menu by name caption "Show" name "Show"
    45.  
    46. Private Sub Command1_Click()
    47. [B]    Me.Hide
    48.     nid.cbSize = Len(nid)
    49.         nid.hwnd = Me.hwnd
    50.         nid.uId = vbNull
    51.         nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    52.         nid.uCallBackMessage = WM_MOUSEMOVE
    53.         nid.hIcon = Me.Icon
    54.         'u can give a tool tip text here
    55.         nid.szTip = "My System Tray Message" & vbNullChar
    56.        'Call the Shell_NotifyIcon function to add the icon to the System Tray, defulte form's icon
    57.  
    58.         Shell_NotifyIcon NIM_ADD, nid
    59. [/B]End Sub
    60.  
    61. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    62. Dim msg As Long
    63. Dim sFilter As String
    64. msg = X / Screen.TwipsPerPixelX
    65.     Select Case msg
    66.         Case WM_LBUTTONDOWN
    67.             MsgBox "you clicked me!"
    68.         '      Me.PopupMenu TrayMenu   'if u want u can call the popup menu
    69.         Case WM_LBUTTONUP
    70.         Case WM_LBUTTONDBLCLK
    71.         Case WM_RBUTTONDOWN
    72.         Case WM_RBUTTONUP
    73.             Me.PopupMenu TrayMenu  'call the popup menu
    74.         Case WM_RBUTTONDBLCLK
    75.     End Select
    76. End Sub
    77.  
    78. Private Sub Show_Click()
    79. Me.WindowState = 0
    80. Me.Show
    81. Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
    82. End Sub

  3. #3

    Thread Starter
    Addicted Member MoE70's Avatar
    Join Date
    May 2006
    Posts
    185

    Re: Minimize to tray

    cool it works now thanks. i was moving the if part as well before.

  4. #4
    Member
    Join Date
    Jun 2010
    Posts
    41

    Re: [RESOLVED] Minimize to tray

    this is gr8

    but how can i open menu form on clicking the icon

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: [RESOLVED] Minimize to tray

    If you have a question it's general practice to open your own thread, not hijack other threads, especially those as old as this one.

    And the code in post #2 already opens a menu when the icon is clicked (right click):

    Me.PopupMenu TrayMenu

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