Results 1 to 7 of 7

Thread: Making a menu pop up when you click on a sstem ytay icon.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Making a menu pop up when you click on a sstem ytay icon.

    Hey guys I have a system tray icon, but when I click on it I would like my menu that is already on my menu bar to show.


    Dooes anyone know how to do thaT?

    I tried to integrate this code into my project.,,


    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 Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    47. Dim msg As Long
    48. Dim sFilter As String
    49. msg = X / Screen.TwipsPerPixelX
    50.     Select Case msg
    51.         Case WM_LBUTTONDOWN
    52.             MsgBox "you clicked me!"
    53.       Me.PopupMenu TrayMenu   'if u want u can call the popup menu
    54.         Case WM_LBUTTONUP
    55.         Case WM_LBUTTONDBLCLK
    56.         Case WM_RBUTTONDOWN
    57.         Case WM_RBUTTONUP
    58.             Me.PopupMenu TrayMenu  'call the popup menu
    59.         Case WM_RBUTTONDBLCLK
    60.     End Select
    61. End Sub
    62.  
    63.  
    64. Private Sub Form_Resize()
    65. If Me.WindowState = 1 Then
    66.  
    67.     Me.Hide
    68.     nid.cbSize = Len(nid)
    69.         nid.hwnd = Me.hwnd
    70.         nid.uId = vbNull
    71.         nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    72.         nid.uCallBackMessage = WM_MOUSEMOVE
    73.         nid.hIcon = Me.Icon
    74.         'u can give a tool tip text here
    75.         nid.szTip = "My System Tray Message" & vbNullChar
    76.        'Call the Shell_NotifyIcon function to add the icon to the System Tray, defulte form's icon
    77.  
    78.         Shell_NotifyIcon NIM_ADD, nid
    79.         Else
    80. End If
    81. End Sub
    82.  
    83. Private Sub Show_Click()
    84. Me.WindowState = 0
    85. Me.Show
    86. Shell_NotifyIcon NIM_DELETE, nid 'Delete the form's icon from the sys tray
    87. End Sub

    so the icon will show up in my app, but no menu, and the menu is made.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Making a menu pop up when you click on a sstem ytay icon.

    Providing your top level menu is called TrayMenu, the code you have should work.

    What happens when you run it?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Making a menu pop up when you click on a sstem ytay icon.

    What is the location of "TrayMenu"? Is it a top level hidden menu item with subitems as visible?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Making a menu pop up when you click on a sstem ytay icon.

    @ Hack: I am pretty sure all of the code is integrated into my own with the same names and etc. And when it runs I can minamize the icon to the system tray , but I can't get no menu to pop up on the icon.
    @ Robdog: Yes its a top level men, but I don't think it is hidden, as I can access the menu from the form as well if i do not minimize it.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Making a menu pop up when you click on a sstem ytay icon.

    One possible problem I see is the code assumes the form is in Twips mode.

    msg = X / Screen.TwipsPerPixelX

    Might try this,

    Code:
        If Me.ScaleMode = vbPixels Then
            msg = X
        Else
            msg = X / Screen.TwipsPerPixelX
       End If

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Making a menu pop up when you click on a sstem ytay icon.

    ok would that go in the Private Sub Form_MouseMove??


    I notice my general delcarations have more than one refernces to shell32

    like this...

    VB Code:
    1. '''Code for shutting down stuff
    2. Option Explicit
    3. '' Code for opening webpages ''
    4.  
    5. 'Private Const LB_FINDSTRINGEXACT = &H1A2
    6. 'Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    7. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    8. ByVal hwnd As Long, _
    9. ByVal lpOperation As String, _
    10. ByVal lpFile As String, _
    11. ByVal lpParameters As String, _
    12. ByVal lpDirectory As String, _
    13. ByVal nShowCmd As Long) As Long
    14.  
    15. Private Const SW_HIDE As Long = 0
    16. Private Const SW_SHOWNORMAL As Long = 1
    17.  
    18. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    19. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    20. Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
    21. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    22. Private Const WM_CLOSE = &H10
    23. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    24. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    25.  
    26. '--Music
    27. Private Const SND_APPLICATION = &H80         '  look for application specific association
    28. Private Const SND_ALIAS = &H10000     '  name is a WIN.INI [sounds] entry
    29. Private Const SND_ALIAS_ID = &H110000    '  name is a WIN.INI [sounds] entry identifier
    30. Private Const SND_ASYNC = &H1         '  play asynchronously
    31. Private Const SND_FILENAME = &H20000     '  name is a file name
    32. Private Const SND_LOOP = &H8         '  loop the sound until next sndPlaySound
    33. Private Const SND_MEMORY = &H4         '  lpszSoundName points to a memory file
    34. Private Const SND_NODEFAULT = &H2         '  silence not default, if sound not found
    35. Private Const SND_NOSTOP = &H10        '  don't stop any currently playing sound
    36. Private Const SND_NOWAIT = &H2000      '  don't wait if the driver is busy
    37. Private Const SND_PURGE = &H40               '  purge non-static events for task
    38. Private Const SND_RESOURCE = &H40004     '  name is a resource name or atom
    39. Private Const SND_SYNC = &H0         '  play synchronously (default)
    40.  
    41.  
    42. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    43. 'declaration for putting the application to system tray
    44. Private Type NOTIFYICONDATA
    45.     cbSize As Long
    46.     hwnd As Long
    47.     uId As Long
    48.     uFlags As Long
    49.     uCallBackMessage As Long
    50.     hIcon As Long
    51.     szTip As String * 64
    52. End Type
    53.  
    54.     'declare constants
    55. Private Const NIM_ADD = &H0
    56. Private Const NIM_MODIFY = &H1
    57. Private Const NIM_DELETE = &H2
    58. Private Const WM_MOUSEMOVE = &H200
    59. Private Const NIF_MESSAGE = &H1
    60. Private Const NIF_ICON = &H2
    61. Private Const NIF_TIP = &H4
    62.  
    63. 'The following constants are used to determine the mouse input on the
    64.  
    65.     'Left-click
    66. Private Const WM_LBUTTONDBLCLK = &H203   'Double click
    67. Private Const WM_LBUTTONDOWN = &H201     'down
    68. Private Const WM_LBUTTONUP = &H202       'up
    69.  
    70.     'Right-click
    71. Private Const WM_RBUTTONDBLCLK = &H206   'Double click
    72. Private Const WM_RBUTTONDOWN = &H204     'down
    73. Private Const WM_RBUTTONUP = &H205       'up
    74.  
    75. 'Dimension a variable as the user-defined data type.
    76. Dim nid As NOTIFYICONDATA
    77.  
    78. Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" ( _
    79.                     ByVal lpszSoundName As String, _
    80.                     ByVal uFlags As Long) As Long
    81.  
    82. Const MAX_PATH = 260
    83. Const MAXDWORD = &HFFFF
    84. Const INVALID_HANDLE_VALUE = -1
    85. Const FILE_ATTRIBUTE_ARCHIVE = &H20
    86. Const FILE_ATTRIBUTE_DIRECTORY = &H10
    87. Const FILE_ATTRIBUTE_HIDDEN = &H2
    88. Const FILE_ATTRIBUTE_NORMAL = &H80
    89. Const FILE_ATTRIBUTE_READONLY = &H1
    90. Const FILE_ATTRIBUTE_SYSTEM = &H4
    91. Const FILE_ATTRIBUTE_TEMPORARY = &H100
    92.  
    93. Private Type FILETIME
    94.     dwLowDateTime As Long
    95.     dwHighDateTime As Long
    96. End Type
    97. Private boAbort As Boolean
    98.  
    99. Private Type WIN32_FIND_DATA
    100.     dwFileAttributes As Long
    101.     ftCreationTime As FILETIME
    102.     ftLastAccessTime As FILETIME
    103.     ftLastWriteTime As FILETIME
    104.     nFileSizeHigh As Long
    105.     nFileSizeLow As Long
    106.     dwReserved0 As Long
    107.     dwReserved1 As Long
    108.     cFileName As String * MAX_PATH
    109.      'Label7.Caption = cFileName
    110.     cAlternate As String * 14
    111. End Type
    112.  
    113. 'Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    114.                ' (ByVal hWnd As Long, _
    115.                '  ByVal wMsg As Long, _
    116.                '  ByVal wParam As Long, _
    117.                '  lParam As Any) As Long
    118.                  
    119. Private Const LB_FINDSTRINGEXACT = &H1A2
    120. Private Const LB_ERR = (-1)
    121. Private Declare Function GetTcpTable Lib "iphlpapi.dll" _
    122.                 (ByRef pTcpTable As Any, _
    123.                  ByRef pdwSize As Long, _
    124.                  ByVal bOrder As Long) As Long
    125.                  
    126. Private Declare Function SetTcpEntry Lib "iphlpapi.dll" _
    127.                 (pTcpTableEx As MIB_TCPROW) As Long
    128.                  
    129. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    130.                 (ByRef pDest As Any, _
    131.                  ByRef pSource As Any, _
    132.                  ByVal Length As Long)
    133.  
    134. Private Declare Function RtlIpv4AddressToString Lib "ntdll.dll" Alias "RtlIpv4AddressToStringA" _
    135.                 (ByRef lngAddr As Long, ByVal strAddr As String) As Long
    136.                
    137. Private Const ERROR_SUCCESS = 0&
    138. Private Const ERROR_INSUFFICIENT_BUFFER = 122
    139.  
    140. Private Type MIB_TCPROW
    141.     dwState As Long
    142.     dwLocalAddr As Long
    143.     dwLocalPort As Long
    144.     dwRemoteAddr As Long
    145.     dwRemotePort As Long
    146. End Type
    147.  
    148. Private udtTCP() As MIB_TCPROW
    149. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Making a menu pop up when you click on a sstem ytay icon.

    wait nevermind, i dont think its that.

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