Solved

Task Bar Icons

Posted on 2001-08-14
8
195 Views
Last Modified: 2010-05-02
So I've successfully added an icon to the system tray for my app and defined the mouse clicks and such, only they don't work.  When I try to get the values for them, they are constant 34's and a right-button doubleclick is 35.  Outside of that, it doesn't work.  Here's my code...


Private 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

'Declare the constants for the API function. These constants can be
'found in the header file Shellapi.h.

'The following constants are the messages sent to the
'Shell_NotifyIcon function to add, modify, or delete an icon from the
'taskbar status area.
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2

'The following constant is the message sent when a mouse event occurs
'within the rectangular boundaries of the icon in the taskbar status
'area.
Private Const WM_MOUSEMOVE = &H200

'The following constants are the flags that indicate the valid
'members of the NOTIFYICONDATA data type.
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4

'The following constants are used to determine the mouse input on the
'the icon in the taskbar status area.

'Left-click constants.
Private Const WM_LBUTTONDBLCLK = &H203   'Double-click
Private Const WM_LBUTTONDOWN = &H201     'Button down
Private Const WM_LBUTTONUP = &H202       'Button up

'Right-click constants.
Private Const WM_RBUTTONDBLCLK = &H206   'Double-click
Private Const WM_RBUTTONDOWN = &H204     'Button down
Private Const WM_RBUTTONUP = &H205       'Button up

'Declare the API function call.
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

'Dimension a variable as the user-defined data type.
Dim nid As NOTIFYICONDATA

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim msg As Long
   
    If Moving Then
        Me.Left = Me.Left + X - mX
        Me.Top = Me.Top + Y - mY
    Else
        'Event occurs when the mouse pointer is within the rectangular
        'boundaries of the icon in the taskbar status area.
   
        msg = X / Screen.TwipsPerPixelX

        'when not commented out, the following line tells me the value of msg.  because 34
        'happens whenever the mouse is over it and even if it's not moving, I sometimes add
        'If msg <> 34 Then
        'MsgBox "msg=" & msg & vbCrLf & "x=" & X & vbCrLf & "y=" & Y & vbCrLf & "TwipsX=" & Screen.TwipsPerPixelX & vbCrLf & "TwipsY=" & Screen.TwipsPerPixelY
        Select Case msg
            Case WM_LBUTTONDOWN
                MsgBox "lbd"
            Case WM_LBUTTONUP
                MsgBox "ldu"
            Case WM_LBUTTONDBLCLK
                MsgBox "lbdc"
            Case WM_RBUTTONDOWN
                MsgBox "rbd"
            Case WM_RBUTTONUP
                MsgBox "rbu"
            Case WM_RBUTTONDBLCLK
                MsgBox "rbdc"
        End Select
 
    End If
End Sub

Private Sub Form_Load()
       nid.cbSize = Len(nid)
       nid.hWnd = MainForm.hWnd
       nid.uId = vbNull
       nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       nid.uCallBackMessage = WM_MOUSEMOVE
       nid.hIcon = MainForm.Icon
       nid.szTip = "Taskbar Status Area Sample Program" & vbNullChar
   
       'Call the Shell_NotifyIcon function to add the icon to the taskbar
       'status area.
       Shell_NotifyIcon NIM_ADD, nid
End Sub



So what do I have to do to make the buttons work?
0
Comment
Question by:Lee W, MVP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 20

Expert Comment

by:hes
ID: 6385059
Take a look at ths example

http://www.allapi.net/api/api333.php
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 6385099
I'll look it over in greater detail shortly, however, can you see anything wrong with my code?
0
 
LVL 2

Expert Comment

by:JanusFury
ID: 6385125
Um, I don't think you're supposed to get the Message number from the X location, just a guess... I haven't worked with the system tray directly from a form.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:hes
ID: 6385235
I think you have to get the x in the mousedown event not the mousemove
0
 
LVL 12

Accepted Solution

by:
jgv earned 150 total points
ID: 6385869
Try this:

If Me.ScaleMode = vbPixels Then
    msg = X
Else
    msg = X / Screen.TwipsPerPixelX
End If
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 6385892
jgv - perfect - you're a god, thank you.  (well... maybe a demi-god)
0
 
LVL 2

Expert Comment

by:JanusFury
ID: 6386273
??? what was msg for anyway? I'm a bit confused as to how it has to do with X and Pixels O_o
0
 
LVL 96

Author Comment

by:Lee W, MVP
ID: 6386680
Anyone?  I just cut and paste from a sample on www.vbcode.com, making a couple of minor changes.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question