Problem with System Tray shortcuts 
Author Message
 Problem with System Tray shortcuts

Hi,

I'm using the following statement to put an icon in the system tray and
return the mousemove event to a picturebox control :

Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias
"Shell_NotifyIconA"  (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As
Long

It works fine on my computer (Win2000), but on two of the machines in the
office (both running Win98) it does not receive the mouse click, only the
mousemove event itself.  Therefore I can get it to do things when I move the
mouse over the icon, but not when I click on it.  Does any one have an
explanation or a solution?  Should I use the API to try to pickup on the
mouseclick event when in the mousemove sub?

Thanks very much,

Jamie Brown
InfoComp Ltd.



Mon, 09 Aug 2004 00:56:16 GMT  
 Problem with System Tray shortcuts


Quote:
> Hi,

> I'm using the following statement to put an icon in the system
tray and
> return the mousemove event to a picturebox control :

> Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias
> "Shell_NotifyIconA"  (ByVal dwMessage As Long, lpData As
NOTIFYICONDATA) As
> Long

> It works fine on my computer (Win2000), but on two of the
machines in the
> office (both running Win98) it does not receive the mouse
click, only the
> mousemove event itself.  Therefore I can get it to do things
when I move the
> mouse over the icon, but not when I click on it.  Does any one
have an
> explanation or a solution?  Should I use the API to try to
pickup on the
> mouseclick event when in the mousemove sub?

I've seen this work on Win98.  Can you post the code where
you're adding the icon, as well as the subclassing code that
you're using to catch the notifications?


Mon, 09 Aug 2004 00:59:25 GMT  
 Problem with System Tray shortcuts
Hi,

I made a little module that was meant to do it all for me...  It is below in
its full state.  As for the event handling, I just had this sort of thing:
(I just made this bit in Outlook Express, so don't analyse it too closely!)

Private Sub picThisBox_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
    if button=vbleftbutton then
        msgbox "Its the left button!"
    end if
End Sub

Here's the module code, from VisualBasic, that works on Win2000 but not on
Win98:

############## CODE BEGINS HERE #####################

Option Explicit

Public Const NIM_ADD As Long = &H0
Public Const NIM_MODIFY As Long = &H1
Public Const NIM_DELETE As Long = &H2

Public Const NIF_ICON As Long = &H2     'adding an ICON
Public Const NIF_TIP As Long = &H4      'adding a TIP
Public Const NIF_MESSAGE As Long = &H1  'want return messages

'rodent constant we'll need for the callback
Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONUP As Long = &H202
Public Const WM_LBUTTONDBLCLK As Long = &H203

Public Const WM_MBUTTONDOWN As Long = &H207
Public Const WM_MBUTTONUP As Long = &H208
Public Const WM_MBUTTONDBLCLK As Long = &H209

Public Const WM_RBUTTONDOWN As Long = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public Const WM_RBUTTONDBLCLK As Long = &H206

'the actual workhorse
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 NID As NOTIFYICONDATA

'Get/SetWindowLong messages
Public Const GWL_WNDPROC As Long = (-4)
Public Const GWL_HWNDPARENT As Long = (-8)
Public Const GWL_ID As Long = (-12)
Public Const GWL_STYLE As Long = (-16)
Public Const GWL_EXSTYLE As Long = (-20)
Public Const GWL_USERDATA As Long = (-21)

'general windows messages
Public Const WM_USER As Long = &H400
Public Const WM_MYHOOK As Long = WM_USER + 1
Public Const WM_NOTIFY As Long = &H4E
Public Const WM_COMMAND As Long = &H111
Public Const WM_CLOSE As Long = &H10
Public Const WM_MOUSEMOVE = &H200

Declare Function Shell_NotifyIcon Lib "shell32.dll" _
   Alias "Shell_NotifyIconA" _
   (ByVal dwMessage As Long, _
   lpData As NOTIFYICONDATA) As Long

Public Sub iconAdd(objForm As Form, objPictureBox As PictureBox, strTip As
String)

    With NID
      .cbSize = LenB(NID)
      .hwnd = objPictureBox.hwnd
      .uID = 125&
      .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
      .uCallbackMessage = WM_MOUSEMOVE
      .hIcon = objPictureBox.Picture
      .szTip = strTip & Chr$(0)
    End With

    Shell_NotifyIcon NIM_ADD, NID

End Sub

Public Sub iconDelete()

    Shell_NotifyIcon NIM_DELETE, NID

End Sub

################ CODE ENDS HERE ###################

Regards,

Jamie


Quote:



> > Hi,

> > I'm using the following statement to put an icon in the system
> tray and
> > return the mousemove event to a picturebox control :

> > Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias
> > "Shell_NotifyIconA"  (ByVal dwMessage As Long, lpData As
> NOTIFYICONDATA) As
> > Long

> > It works fine on my computer (Win2000), but on two of the
> machines in the
> > office (both running Win98) it does not receive the mouse
> click, only the
> > mousemove event itself.  Therefore I can get it to do things
> when I move the
> > mouse over the icon, but not when I click on it.  Does any one
> have an
> > explanation or a solution?  Should I use the API to try to
> pickup on the
> > mouseclick event when in the mousemove sub?

> I've seen this work on Win98.  Can you post the code where
> you're adding the icon, as well as the subclassing code that
> you're using to catch the notifications?



Mon, 09 Aug 2004 01:15:25 GMT  
 Problem with System Tray shortcuts
I've not used this approach to making a systray icon, though
I've heard it disparaged in these groups before.  Apparently the
reliability of a non-subclassed approach is not good.  Here's a
"kosher" example:

http://www.mvps.org/vbnet/code/subclass/shellnotifybasic.htm



Mon, 09 Aug 2004 01:21:03 GMT  
 Problem with System Tray shortcuts
Quote:
> Public Sub iconAdd(objForm As Form, objPictureBox As

PictureBox, strTip As

Quote:
> String)

>     With NID
>       .cbSize = LenB(NID)
>       .hwnd = objPictureBox.hwnd
>       .uID = 125&
>       .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
>       .uCallbackMessage = WM_MOUSEMOVE
>       .hIcon = objPictureBox.Picture
>       .szTip = strTip & Chr$(0)
>     End With

>     Shell_NotifyIcon NIM_ADD, NID

> End Sub

Just an additional though if you're dedicated to this
approach -- it seems fairly clear from this code, that you
should only expect mouse movements (and not clicks) from the
uCallbackMessage line.


Mon, 09 Aug 2004 01:23:54 GMT  
 Problem with System Tray shortcuts
Hi,

Thank you - I'm certainly not dedicated to the method I was using.  I'm only
dedicated to methods that work!  :-)  I'll investigate that one...

Cheers,

Jamie


Quote:
> I've not used this approach to making a systray icon, though
> I've heard it disparaged in these groups before.  Apparently the
> reliability of a non-subclassed approach is not good.  Here's a
> "kosher" example:

> http://www.mvps.org/vbnet/code/subclass/shellnotifybasic.htm



Mon, 09 Aug 2004 18:32:03 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem with System Tray shortcuts

2. Q: Problems with System Tray functionality in VB5 and question about TaskBar/System Tray

3. Removing System Tray shortcuts

4. Removing System Tray shortcuts

5. CoolHide - Help you hide/minimize window to Tray and hide icons from the system tray

6. CoolHide - Help you hide/minimize window to Tray and hide icons from the system tray

7. System Tray Problem

8. System Tray Icon problems

9. Minimize to system tray problem

10. System Tray problem

11. System Tray Problem with VB

12. System Tray Icon Problem.

 

 
Powered by phpBB® Forum Software