hsyong
March 29th, 2001, 09:21 AM
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
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