|
-
Nov 5th, 2007, 02:17 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] System Tray Menu
Well here is my third and hopefully last thread of the night.
I have searched for the last hour or so on google and here on the forum for a way to add an icon to the system tray that works as a menu. I have been unsuccessful. I'm looking for a nice easy way to do this. If anyone can help me it would be great. Thanks!!
-
Nov 5th, 2007, 02:22 PM
#2
-
Nov 5th, 2007, 02:24 PM
#3
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 5th, 2007, 02:33 PM
#4
Thread Starter
Frenzied Member
Re: System Tray Menu
I'm using the code that static suggested. But how do I give it a menu now. I know how to have a drop down menu at the top of the form. How do I do it for the tray icon though? Thanks.
-
Nov 5th, 2007, 02:39 PM
#5
Re: System Tray Menu
do you know how to make a popup menu?
basically create a menu with the top level visible = false
then call popupmenu "MenuName" from the mousedown event of the form (I think it was the form)
do a search here.. many examples are kickin around. Systray Popup menu
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 5th, 2007, 02:50 PM
#6
Thread Starter
Frenzied Member
Re: System Tray Menu
Yeah I can do a popup menu.
-
Nov 5th, 2007, 05:24 PM
#7
Re: System Tray Menu
In the Form_Mousedown event you would detect if the Button = 2 (right click) and if so then just popup your menu.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2007, 02:23 AM
#8
Thread Starter
Frenzied Member
Re: System Tray Menu
How do I get it to pop up if I right click on the icon on the tray though?
-
Nov 6th, 2007, 03:22 AM
#9
Re: System Tray Menu
As mentioned...
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Me.PopupMenu "MyMenu"
End If
End Sub
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2007, 07:15 AM
#10
Re: System Tray Menu
Which event you should write the code that shows the popup menu depends on what you've set the hWnd and uCallbackMessage members of the NOTIFYICONDATA structure to. For example, if you've set the hWnd member to the hWnd of your main Form and the uCallbackMessage to WM_MOUSEMOVE (which is the message I would recommend you to use). In that case the Form_MouseMove event will be fired everytime an event has happened on the icon. Which event that is (WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_RBUTTONDOWN and so on) will then be stored in the X parameter of the event. If the ScaleMode of your Form is set to Twips you need to divide X with Screen.TwipsPerPixelX to get the correct value. So the code should look simular to this:
Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim nMsg As Long
nMsg = X \ Screen.TwipsPerPixelX
Select Case nMsg
Case WM_RBUTTONDOWN
'the right mouse button was pressed show the popup menu
Me.PopupMenu mnuPop
End Select
End Sub
-
Nov 6th, 2007, 11:32 AM
#11
Thread Starter
Frenzied Member
Re: System Tray Menu
 Originally Posted by RobDog888
As mentioned...
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Me.PopupMenu "MyMenu"
End If
End Sub
That only works if I right click on the form? It does nothing at all if I right click on the icon.
-
Nov 6th, 2007, 11:38 AM
#12
Re: System Tray Menu
Like Joacim posted, it depends on what you set the callback.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2007, 12:07 PM
#13
Thread Starter
Frenzied Member
Re: System Tray Menu
Callback?
Yeah i'm still a beginner at all this... Could you explain in more detail what i have to do please? This is the code that I am using:
Code:
Option Explicit
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long
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 Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_RBUTTONUP = &H205
Dim NID As NOTIFYICONDATA
Private Sub Form_Load()
Dim str As String
With NID
.cbSize = Len(NID)
.hIcon = Me.Icon
.hWnd = Me.hWnd
.szTip = "Hello" & vbNullChar
.ucallbackMessage = WM_LBUTTONDBLCLK
.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
.uId = 1&
End With
Shell_NotifyIcon NIM_ADD, NID
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Form1.PopupMenu menumain
End If
End Sub
Thanks in advance.
-
Nov 6th, 2007, 12:17 PM
#14
Re: System Tray Menu
Change the .ucallbackMessage from ".ucallbackMessage = WM_LBUTTONDBLCLK" to ".ucallbackMessage = WM_MOUSEMOVE".
Then use the code Joacim posted.
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 6th, 2007, 12:23 PM
#15
Thread Starter
Frenzied Member
Re: System Tray Menu
It works!!! Thanks so much to both of you!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|