toff_in_sydney
asked on
VB and the Taskbar/System Tray
I've got an app that's trying to minimize itself to the taskbar/system tray (whatever you want to call it), but the callbacks on WM_MOUSEMOVE aren't working. Here's the code I use in the Form_Load:
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
If (False = Shell_NotifyIcon(NIM_ADD, nid)) Then
MsgBox "Oops!"
End If
If (gs.p.fMinimiseOnStartup) Then
frmMain.WindowState = vbMinimized
frmMain.Hide
End If
And here's the procedure that SHOULD be getting the callbacks:
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 frmMain.ScaleMode = vbPixels Then
msg = X
Else
msg = X / Screen.TwipsPerPixelX
End If
Select Case msg
Case WM_LBUTTONUP
frmMain.WindowState = vbNormal
SetForegroundWindow (frmMain.hwnd)
frmMain.Show
Case WM_LBUTTONDBLCLK
frmMain.WindowState = vbNormal
SetForegroundWindow frmMain.hwnd
frmMain.Show
Case WM_RBUTTONUP
SetForegroundWindow frmMain.hwnd
frmMain.PopupMenu frmMain.mPopupSys
End Select
End Sub
But it's not getting any MOUSEMOVE messages from the icon. The icon appears in the system tray just fine, and if I leave the form up, the MOUSEMOVE messages are invoking the procedure above...but any mouse movement over the icon in the system tray doesn't. What am I doing wrong?
nid.cbSize = Len(nid)
nid.hwnd = Me.hwnd
nid.uId = vbNull
nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
nid.uCallBackMessage = WM_MOUSEMOVE
nid.hIcon = Me.Icon
If (False = Shell_NotifyIcon(NIM_ADD, nid)) Then
MsgBox "Oops!"
End If
If (gs.p.fMinimiseOnStartup) Then
frmMain.WindowState = vbMinimized
frmMain.Hide
End If
And here's the procedure that SHOULD be getting the callbacks:
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 frmMain.ScaleMode = vbPixels Then
msg = X
Else
msg = X / Screen.TwipsPerPixelX
End If
Select Case msg
Case WM_LBUTTONUP
frmMain.WindowState = vbNormal
SetForegroundWindow (frmMain.hwnd)
frmMain.Show
Case WM_LBUTTONDBLCLK
frmMain.WindowState = vbNormal
SetForegroundWindow frmMain.hwnd
frmMain.Show
Case WM_RBUTTONUP
SetForegroundWindow frmMain.hwnd
frmMain.PopupMenu frmMain.mPopupSys
End Select
End Sub
But it's not getting any MOUSEMOVE messages from the icon. The icon appears in the system tray just fine, and if I leave the form up, the MOUSEMOVE messages are invoking the procedure above...but any mouse movement over the icon in the system tray doesn't. What am I doing wrong?
AFAIK, only clicking a mouse button over the trayed icon will activate the callback routine, just moving your mouse over it doesn't do it.
It's working for me...
It's working for me...
ASKER
Yes, moving the mouse over it does activate the callback routine...tried and tested with small apps that just contain that. In any case, clicking doesn't activate it, either.
Since it is working for me and not for you, lets focus on what could be different. These are the declarations I used to test:
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
Public Const NIM_ADD = 0
Public Const NIM_MODIFY = 1
Public Const NIM_DELETE = 2
Public Const NIF_MESSAGE = 1
Public Const NIF_ICON = 2
Public Const NIF_TIP = 4
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const WM_NULL = &H0
Declare Function Shell_NotifyIconA Lib "shell32" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
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
Public Const NIM_ADD = 0
Public Const NIM_MODIFY = 1
Public Const NIM_DELETE = 2
Public Const NIF_MESSAGE = 1
Public Const NIF_ICON = 2
Public Const NIF_TIP = 4
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public Const WM_NULL = &H0
Declare Function Shell_NotifyIconA Lib "shell32" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks priya...I don't know what I was doing wrong, but i used your code instead and it works perfectly.
you are welcome!
-priya
-priya
Have you tried clicking on the icon?