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!

Howdy! I have developed an app w 1

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.

By the way, I am using VB 6, SP5 in Windows 2000, SP2


'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.uCallBackMessage = WM_RBUTTONUP
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

msg = X / Screen.TwipsPerPixelX

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
 
jbenson,

How about a 3 second timer then unload the form/menu?

WebbWill
 
Hi,

If you are displaying a popupmenu, it is being displayed in modal mode, meaning that NO other window receives messages anymore unless you create a windows hook. You seem to be waiting to receive the mouse messages when the popup is displayed, but it will never send those messages to the window, because it's modal. So either set up a windows hook or find another way around.

LuCkY
 
LuCkY,

Could you perhaps tell me, or point me to a source that will tell me, how to "set up a Windows hook"?
 
I'll try to write an example for you right now, just have some patience :)
 
Hmm, I took a look at it and I don't know exactly why it doesn't work the way you described above. According to MSDN it already sets up a windows hook if you specify the uCallbackMessage parameter. I also tried it with my own message and subclassing, but I got the same results as you.

The only other option (apart from finding some good example of the above) is setting a system wide hook. But that must be done in a lower language like C++. I will look for some examples on the internet for the above. There just has to be a way to get that code working ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top