Results 1 to 10 of 10

Thread: Handling Systray Icon Events

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    Handling Systray Icon Events

    I have a program that creates a systray icon using ShellNotifyIcon and assigns a message value to it that is supposed to be passed back to the owner window when activity takes place. How do I intercept this message in my program? Is there a site you can reccomend that would outline how to intercept a message in a vb program and create an event based on it?

    Thanks for any help.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    I know it involves Subclassing..

    but I cannot find any good code that demonstrates the process of subclassing. I did find one site that included an already compiled OCX file that would handle subclassing, but I want to understand what is going on behind the scenes there.

  3. #3
    So, was the test a success?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    Red face hmmm...

    Well, I'm glad this thread is at least good for something, even if it is just testing your ability to post.

  5. #5
    Try checking out http://www.mvps.org/vbnet or http://www.vbsquare.com/ for tutorials on subclassing.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    Wink

    looks like the info there will helpful.. thanks for the sites.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is a class that probably does what you want hopefully it helps. If not then don't mind me I am always pimping sample projects.

    It shows how to catch the rightclick and doubleclick and what not events on the tray icon.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30

    hey Edneeis....

    your example does work correctly, but i am confused about one part of the code. In the sub below, MSG is assigned a value of X / Screen.TwipsPerPixelX, which as i understand it should be the x coordinate in pixel notation of the mouse when moved over the form/icon. How does a case statment of the x pixel coordinate correctly interpret the messages? If any one knows what I'm missing, please fill me in. Thanks.

    Private Sub OwnerForm_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Static rec As Boolean, MSG As Long
    MSG = X / Screen.TwipsPerPixelX
    If rec = False Then
    rec = True
    Select Case MSG
    Case WM_LBUTTONDBLCLK:
    RaiseEvent DblClick
    Case WM_LBUTTONDOWN:
    RaiseEvent MouseDown(vbLeftButton)
    Case WM_LBUTTONUP:
    RaiseEvent MouseUp(vbLeftButton)
    Case WM_RBUTTONDBLCLK:
    RaiseEvent DblClick
    Case WM_RBUTTONDOWN:
    RaiseEvent MouseDown(vbRightButton)
    Case WM_RBUTTONUP:
    RaiseEvent MouseUp(vbRightButton)
    End Select
    rec = False
    End If
    End Sub

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I am not sure exactly why that works. It does seem weird. I just took bits and pieces of different examples and fixed it up into a class and went with it. I guess it has something to do with the X being the X from the MouseMove event????????????

    But hey if it works then its all good right.

    Although it is nice to understand whats happening.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    May 2001
    Posts
    30
    yeah, I even looked at the documentation for the mousemove event of a form thinking that maybe VB considers a mouse button press event to also be a mouse move event and then alters the values of X and Y accordingly So i put a statment in the routine, MSG2 = Y/ Screen.TwipsperpixelY to determine the value of Y, and it is always 0.

    So, I next added a MouseMove routine to the main form, which, when the program was in Icon form, returned the same values as the one from the object. But when in "Form mode", it returns values that make sense. Seems like there could be a problem if the form happened to be in a place where the mouse retuned the same value as the messages, which, granted, would require a screen size of 2308x1704, but could happen. Apparently the Systray must intercept the MouseOver/Button commands and then replace them with values relavent to the event. And the values it sends back don't change with the screen size, so there could be a problem under these conditions.

    Is there anyone who can verify that this is correct? Does anyone know for a fact that the systray modifys the X/Y values when the mouse is in its region? I'm just curious now ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width