PDA

Click to See Complete Forum and Search --> : Undecided system tray


bertie9
Nov 13th, 1999, 08:55 AM
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

Aaron Young
Nov 14th, 1999, 08:56 AM
It would be more helpful to know what code you used to put the Icon in the Tray.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

bertie9
Nov 15th, 1999, 01:32 AM
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

Aaron Young
Nov 15th, 1999, 02:26 AM
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..

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

Try This..

msg = ScaleX(X, ScaleMode, vbPixels)



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

bertie9
Nov 16th, 1999, 06:57 AM
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

Aaron Young
Nov 16th, 1999, 08:19 AM
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
aarony@redwingsoftware.com
adyoung@win.bright.net

bertie9
Nov 17th, 1999, 01:17 AM
Aaron,
Thanks very much for taking the time to help.
I'll give the picture box method a go.

Best Regards
Matt