Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System Tray Popup Menu problem

Status
Not open for further replies.

jebenson

Technical User
Feb 4, 2002
2,956
0
0
US
Howdy!

I have developed an app which I want to run hidden, with an icon in the system tray on the taskbar. I also have the app provide a popup menu when the user right-clicks on the icon in the system tray. This all works fine. The problem is that once the popup menu is showing, it will not disappear. That is, the user r-clicks on the icon, the popup menu appears, then the user clicks somewhere else (e.g., desktop, somewhere else on taskbar, another application, etc.) and the popup menu stays visible. The ONLY way to make the popup menu disappear is to actually select an item from the menu. And here's the best part - the app makes all other system tray popup menus behave in the same manner. If any other popup menu for any other application is brought up from the system tray, it also will not disappear until an item is selected from its menu. One other piece of interesting information - the behavior of other menus not disappearing does not occur until the popup menu from my app has been displayed. That is, you can sit there an call up popup menus from the system tray all day long, and there is no problem. But after the first time the popup menu is called from my app, the other popup menus will then persist on the screen until selected.

I have checked the Microsoft website - no luck (all I found was basically the code below). Any ideas?

The relevant code is listed below. The contents of the menu should be irrelevant (shouldn't they?), but all the menu named "mnuPopup" contains is "Exit", with an End command. Note that in the Form_MouseMove sub I tried using mnuPopup.Visible=False, to no effect.

'Declare a user-defined variable to pass to the Shell_NotifyIcon
'function.
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

'Declare the constants for the API function. These constants can be
'found in the header file Shellapi.h.

'The following constants are the messages sent to the
'Shell_NotifyIcon function to add, modify, or delete an icon from the
'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2

'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200

'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.

'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up

'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up

'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA

'**********************************************************
'**********************************************************
Private Sub Form_Load()
'Set the individual values of the NOTIFYICONDATA data type.
nid.cbSize = Len(nid)
nid.hWnd = frmServer.hWnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = frmServer.Icon
nid.szTip = "CJPC Database Copy Server" & vbNullChar

'Call the Shell_NotifyIcon function to add the icon to the taskbar
'status area.
Shell_NotifyIcon NIM_ADD, nid
End Sub

'**********************************************************
'**********************************************************
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

DoEvents

Dim msg As Long

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

Select Case msg
Case WM_LBUTTONDOWN
mnuPopup.Visible = False
Case WM_LBUTTONUP
mnuPopup.Visible = False
Case WM_LBUTTONDBLCLK
mnuPopup.Visible = False
Case WM_RBUTTONDOWN
mnuPopup.Visible = False
Case WM_RBUTTONUP
PopupMenu mnuPopup
Case WM_RBUTTONDBLCLK
mnuPopup.Visible = False
End Select
End Sub
 
By the way - I am using VB 6, SP 5 in Windows 2000 SP 2.
 
jbenson,

Have you tried using a timer to close the form?


webbwill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top