Results 1 to 7 of 7

Thread: Undecided system tray

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    10

    Post

    I have a program that I have put in the system tray using Shell_NotifyIcon. The program includes a toolbar and a treeview. When the both the treeview and the toolbar are visible the system tray icon will not respond to any events. However, if either the treeview or toolbar (or both) are not visible then the system tray icon works fine and will display the required menu.
    I was wondering, do the on_buttonclick and nodeclick events steal the messages?
    Does anyone know of a way around this?

    Pleae help it's driving me nuts.

    Regards
    Matt

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    It would be more helpful to know what code you used to put the Icon in the Tray.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    10

    Post

    HI
    This is the code for putting the icon in the system tray.

    In a module:

    'user defined type required by Shell_NotifyIcon API call
    Public 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


    'constants required by Shell_NotifyIcon API call:
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_LBUTTONDOWN = &H201 'Button down
    Public Const WM_LBUTTONUP = &H202 'Button up
    Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
    Public Const WM_RBUTTONDOWN = &H204 'Button down
    Public Const WM_RBUTTONUP = &H205 'Button up
    Public Const WM_RBUTTONDBLCLK = &H206 'Double-click

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

    Public nid As NOTIFYICONDATA


    In form load:

    With nid
    .cbSize = Len(nid)
    .hwnd = frmAddressBook.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = &H200
    .hIcon = Me.Icon
    .szTip = "Your ToolTip" & vbNullChar
    End With

    Shell_NotifyIcon NIM_ADD, nid


    In Form_mouseMove:

    'this procedure receives the callbacks from the System Tray icon.
    Dim result As Long
    Dim msg As Long
    'the value of X will vary depending upon the scalemode setting
    If Me.ScaleMode = vbPixels Then
    msg = X
    Else
    msg = X / Screen.TwipsPerPixelX
    End If
    Select Case msg
    Case WM_LBUTTONUP '514 restore form window
    Me.WindowState = vbNormal
    result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_LBUTTONDBLCLK '515 restore form window
    Me.WindowState = vbNormal
    result = SetForegroundWindow(Me.hwnd)
    Me.Show
    Case WM_RBUTTONUP '517 display popup menu
    result = SetForegroundWindow(Me.hwnd)
    Me.PopupMenu Me.mPopupSys
    End Select


    Thanks in advance for any help.
    Matt

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Do you by any chance have your Forms ScaleMode set to something other than Pixels or Twips?.. If so, you calculation to get the Message will fail using the Division by TwipsPerPixel, instead of this..
    Code:
    If Me.ScaleMode = vbPixels Then
        msg = X
    Else
        msg = X / Screen.TwipsPerPixelX
    End If
    Try This..
    Code:
        msg = ScaleX(X, ScaleMode, vbPixels)

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    10

    Post

    Thanks Aaron,
    The form scalemode was set to twips. That bit of code didn't help but thanks anyway. I guess I'll figure it out eventually or just give up on it.

    Regards
    Matt

  6. #6
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    I didn't get any problems with the setup you described, perhaps you could try adding an Invisible Picturebox and use that for your Icon MouseMove Event, (Set the Hwnd of the TrayIcon Structure to Picture1.hwnd), that's the way I normally do it, instead of using the Form to recieve the messages.


    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    10

    Post

    Aaron,
    Thanks very much for taking the time to help.
    I'll give the picture box method a go.

    Best Regards
    Matt

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