|
-
March 29th, 2001, 10:21 AM
#1
System tray menu
I've created a test application that sits in the system tray, when the icon in the tray is right-clicked a menu will pop up.
But the problem is .. the menu responds to mouse events but not keypress ... like 'Esc'.
Btw, the main form(menu owner is set to invisible)
The code portion is as below :
private Sub Form_Load()
With nid
.cbSize = len(nid)
.hwnd = frmMain.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.szTip = "Right click to display menu" & vbNullChar
.hIcon = frmMain.Icon
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub
private Sub Form_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
Dim Result as Long
Dim msg as Long
If me.ScaleMode = vbPixels then
msg = X
else
msg = X / Screen.TwipsPerPixelX
End If
Select Case msg
Case 517 'display menu
SetForegroundWindow (me.hwnd)'set window as top, still cant respond to key
me.PopupMenu menuMyMenu
Case 514
'Some code
End Select
End Sub
Pls help. Thank you.
Vincent
-
March 29th, 2001, 11:24 AM
#2
Re: System tray menu
i don't think it is possible to trap key press when you app is sitting on the systray without any of it's form visible.
The only way that I can think of is to HOOK to WM_ messages especially the keyboard state. I've seen a lot of codes regarding the HOOK in this forum. You should be able to search for it.
Just an idea-
Cool Bizs
Good Luck,
-Cool Bizs
-
March 29th, 2001, 11:39 AM
#3
Re: System tray menu
I have written a DLL that implements low level hooks (like keyboard, mouse etc.) in a safe and easy to use wrapper.
Drop me a "private message" with your email and I'll send it to you.
There is also a little "fudge" which is to have a form in your app which is one pixel big and set that to be the foreground window before showng the menu...it will then get keyboard events if you have its "KeyPreview" set to True.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
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
|