System tray icon

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

System tray icon

Yar Hwee Boon
Hi all

Was wondering how I can show an icon in the systray and came across
this post http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=3fd5a808%40news.totallyobjects.com&rnum=2&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26q%3Dsystem%2Btray%26meta%3Dgroup%253Dcomp.lang.smalltalk.dolphin
in which Dmitry (Zamotkin) provided an example (perhaps using Blair's
TaskbarIcon package?). I tried to play around with the TaskbarIcon and
SwazooTaskbar classes and couldn't figure out exactly how to use them.
The following code is basically the only thing I managed to do.

workspace:

icon := TaskbarIcon icon: SwazooTaskbar icon.
icon show.


and I saw

TaskbarIcon class>>initialize
        "Snipped the other window messages besides WM_LBUTTONDOWN for
simplicity"
        TaskbarMessageMap:= LookupTable new.
        TaskbarMessageMap
                at: WM_LBUTTONDOWN put: #onLeftButtonPressed.

How/Where do I create the method #onLeftButtonPressed:? I added it to
TaskbarIcon and it seems to work, but it doesn't seem the right place.
Can anyone help to explain or give some hints? Thanks.

Hwee Boon


Reply | Threaded
Open this post in threaded view
|

Re: System tray icon

Don Rylander-3
Udo Schneider had a package called NotifyShell which should do what you
want.  I don't know whether he's got the newer version anywhere, but at the
end of this post is the latest version I have.

You may also want to put icons into your application, see:
http://www.object-arts.co.uk/wiki/html/Dolphin/IconsToGo.htm

HTH,

Don

=== Paste everything below this line into a file named "US NotifyShell.pac"
===
| package |
package := Package name: 'US NotifyShell'.
package paxVersion: 0;
 basicComment: 'US NotifyShell
Udo Schneider <[hidden email]> 2002

This package contains additions to the standard Dolphin Smalltalk Shell
class which allows you to use the traybar.

Execute the following code to see an example implementation of the
NotifyShell which responds to various events.

 NotifyShellExample show'.

package basicPackageVersion: '0.005'.

"Add the package scripts"

"Add the class names, loose method names, global names, resource names"
package classNames
 add: #NotifyShell;
 add: #NotifyShellExample;
 add: #ShellNotifyView;
 yourself.

package methodNames
 yourself.

package globalNames
 yourself.

package resourceNames
 yourself.

"Binary Global Names"
package binaryGlobalNames: (Set new
 yourself).
"Resource Names"
package allResourceNames: (Set new
 add: #NotifyShell -> 'Default view';
 yourself).

"Add the prerequisite names"
package setPrerequisites: (IdentitySet new
 add: 'Development System';
 add: 'Dolphin';
 yourself).

package!

"Class Definitions"!

Shell subclass: #NotifyShell
 instanceVariableNames: ''
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
NotifyShell subclass: #NotifyShellExample
 instanceVariableNames: ''
 classVariableNames: ''
 poolDictionaries: ''
 classInstanceVariableNames: ''!
ShellView subclass: #ShellNotifyView
 instanceVariableNames: 'notifyStruct notifyMessage notifyIcon
notifyTipMessage'
 classVariableNames: 'NotifyMessageMap'
 poolDictionaries: ''
 classInstanceVariableNames: ''!
"Loose Methods"!

"End of package definition"!



NotifyShell comment: ''!

NotifyShell guid: (GUID fromString:
'{76A412BA-947A-40AA-83BA-9BD384979C29}')!

!NotifyShell categoriesForClass!Unclassified! !


NotifyShellExample comment: ''!

NotifyShellExample guid: (GUID fromString:
'{8E0528A6-54F0-4368-8D83-83CC78AF605D}')!

!NotifyShellExample categoriesForClass!Unclassified! !
!NotifyShellExample methodsFor!

createSchematicWiring
 "Create the trigger wiring for the receiver"

 super createSchematicWiring.
 self when: #onTraybarLeftButtonPressed send: #traybarEvent: to: self with:
'Left Button Pressed'.
 self when: #onTraybarRightButtonPressed send: #traybarEvent: to: self with:
'Right Button Pressed'.
 self when: #onTraybarLeftButtonDoubleClicked send: #traybarEvent: to: self
with: 'Left Button Double Clicked'.
 self when: #onTraybarRightButtonDoucleClicked send: #traybarEvent: to: self
with: 'Right Button Double Clicked'.!

traybarEvent: aString
 MessageBox notify: aString! !
!NotifyShellExample categoriesFor:
#createSchematicWiring!*-unclassified!public! !
!NotifyShellExample categoriesFor: #traybarEvent:!*-unclassified!public! !



ShellNotifyView comment: ''!

ShellNotifyView guid: (GUID fromString:
'{6C3394D3-CC74-471F-86D8-6F5A7D25E621}')!

!ShellNotifyView categoriesForClass!Unclassified! !
!ShellNotifyView methodsFor!

addNotifyIcon
 self initializeNotifyStruct.
 notifyStruct hWnd: self asParameter.
 ^ShellLibrary default shell_NotifyIcon: NIM_ADD pnid: notifyStruct

!

basicInitializeNotifyStruct

 notifyStruct
  uID: 1;
  icon: notifyIcon;
  message: notifyMessage;
  tipText: notifyTipMessage displayString.
!

deleteNotifyIcon
 ^ShellLibrary default shell_NotifyIcon: NIM_DELETE pnid: notifyStruct.!

dispatchRegistered: registeredId wParam: wParam lParam: lParam
 ^registeredId = notifyMessage
  ifTrue: [
   (NotifyMessageMap includesKey: lParam) ifTrue: [
    self perform: (NotifyMessageMap at: lParam)
   ]
 ]!

initializeNotifyStruct
 notifyStruct := NOTIFYICONDATA new.
 notifyMessage := self class registerMessage: 'Dolphin Shell Notification'.
 self basicInitializeNotifyStruct.!

modifyNotifyIcon

 self basicInitializeNotifyStruct.
 ^ShellLibrary default shell_NotifyIcon: NIM_MODIFY pnid: notifyStruct.!

notifyIcon
 "Private - Answer the value of the receiver's ''notifyIcon'' instance
variable."
 notifyIcon isNil ifTrue: [notifyIcon := self  icon].
 ^notifyIcon!

notifyIcon: anObject
 "Private - Set the value of the receiver's ''notifyIcon'' instance variable
to the argument, anObject."

 notifyIcon := anObject!

notifyMessage
 "Private - Answer the value of the receiver's ''notifyMessage'' instance
variable."

 ^notifyMessage!

notifyMessage: anObject
 "Private - Set the value of the receiver's ''notifyMessage'' instance
variable to the argument, anObject."

 notifyMessage := anObject!

notifyStruct
 "Private - Answer the value of the receiver's ''notifyStruct'' instance
variable."

 ^notifyStruct!

notifyStruct: anObject
 "Private - Set the value of the receiver's ''notifyStruct'' instance
variable to the argument, anObject."

 notifyStruct := anObject!

notifyTipMessage
 "Private - Answer the value of the receiver's ''notifyTipMessage'' instance
variable."
 notifyTipMessage isNil ifTrue: [notifyTipMessage := 'Notify Message'].
 ^notifyTipMessage!

notifyTipMessage: anObject
 "Private - Set the value of the receiver's ''notifyTipMessage'' instance
variable to the argument, anObject."

 notifyTipMessage := anObject!

onCreated: anEvent
 self addNotifyIcon.
 ^super onCreated: anEvent
!

onDestroyed
 self deleteNotifyIcon.
 ^super onDestroyed
!

onTraybarLeftButtonDoubleClicked
 self presenter trigger: #onTraybarLeftButtonDoubleClicked!

onTraybarLeftButtonPressed
 self presenter trigger: #onTraybarLeftButtonPressed!

onTraybarRightButtonDoubleClicked
 self presenter trigger: #onTraybarRightButtonDoubleClicked!

onTraybarRightButtonPressed
 self presenter trigger: #onTraybarRightButtonPressed!

onViewMinimized: aSizeEvent
 "Private - ShellNotifyView handler for window minimize.  Hide the window,
then
 hand off to super."

 self hide.
 ^super onViewMinimized: aSizeEvent! !
!ShellNotifyView categoriesFor: #addNotifyIcon!*-unclassified!private! !
!ShellNotifyView categoriesFor:
#basicInitializeNotifyStruct!initializing!private! !
!ShellNotifyView categoriesFor: #deleteNotifyIcon!*-unclassified!private! !
!ShellNotifyView categoriesFor:
#dispatchRegistered:wParam:lParam:!*-unclassified!private! !
!ShellNotifyView categoriesFor:
#initializeNotifyStruct!initializing!private! !
!ShellNotifyView categoriesFor: #modifyNotifyIcon!*-unclassified!private! !
!ShellNotifyView categoriesFor: #notifyIcon!accessing!private! !
!ShellNotifyView categoriesFor: #notifyIcon:!accessing!private! !
!ShellNotifyView categoriesFor: #notifyMessage!accessing!private! !
!ShellNotifyView categoriesFor: #notifyMessage:!accessing!private! !
!ShellNotifyView categoriesFor: #notifyStruct!accessing!private! !
!ShellNotifyView categoriesFor: #notifyStruct:!accessing!private! !
!ShellNotifyView categoriesFor: #notifyTipMessage!accessing!private! !
!ShellNotifyView categoriesFor: #notifyTipMessage:!accessing!private! !
!ShellNotifyView categoriesFor: #onCreated:!event handling!private! !
!ShellNotifyView categoriesFor: #onDestroyed!event handling!private! !
!ShellNotifyView categoriesFor: #onTraybarLeftButtonDoubleClicked!event
handling!private! !
!ShellNotifyView categoriesFor: #onTraybarLeftButtonPressed!event
handling!private! !
!ShellNotifyView categoriesFor: #onTraybarRightButtonDoubleClicked!event
handling!private! !
!ShellNotifyView categoriesFor: #onTraybarRightButtonPressed!event
handling!private! !
!ShellNotifyView categoriesFor: #onViewMinimized:!event handling!private! !

!ShellNotifyView class methodsFor!

initialize
 NotifyMessageMap := Dictionary new.
 NotifyMessageMap at: WM_LBUTTONDOWN put: #onTraybarLeftButtonPressed;
   at: WM_RBUTTONDOWN put: #onTraybarRightButtonPressed;
  at: WM_LBUTTONDBLCLK put: #onTraybarLeftButtonDoubleClicked;
  at: WM_RBUTTONDBLCLK put: #onTraybarRightButtonDoubleClicked.!

publishedAspectsOfInstances
 ^super publishedAspectsOfInstances
  add: (Aspect icon: #notifyIcon);
  add: (Aspect string: #notifyTipMessage);
  yourself
!

publishedEventsOfInstances
 "Answer a Set of Symbols that describe the published events triggered
 by instances of the receiver."

 ^super publishedEventsOfInstances
  add: #onTraybarLeftButtonPressed;
  add: #onTraybarRightButtonPressed;
  add: #onTraybarLeftButtonDoubleClicked;
  add: #onTraybarRightButtonDoubleClicked;
  yourself.! !
!ShellNotifyView class categoriesFor: #initialize!*-unclassified!public! !
!ShellNotifyView class categoriesFor:
#publishedAspectsOfInstances!*-unclassified!public! !
!ShellNotifyView class categoriesFor:
#publishedEventsOfInstances!*-unclassified!public! !


"Binary Globals"!

"Resources"!

(ResourceIdentifier class: NotifyShell name: 'Default view') assign: (Object
fromBinaryStoreBytes:
(ByteArray fromHexString:
'2153544220302046020C0001000000566965775265736F75726365000000000E01240053544
25265736F757263655354424279746541727261794163636573736F7250726F7879000000003
600090042797465417272617923040000215354422030204E080C000A0000005354425669657
750726F7879000000004E020D0001000000535442436C61737350726F7879000000003600060
0537472696E67120000005553205368656C6C4E6F7469667956696577920000000F000000536
8656C6C4E6F74696679566965772600050041727261791F0000000000000000000000C200000
00200000001009E0101000200600000000000000000000000000000000500000000000000000
000000000000000000000000000000E021A005354424964656E7469747944696374696F6E617
27950726F7879000000007A000000000000009200000007000000446F6C7068696E920000001
20000004964656E7469747944696374696F6E617279C20000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000100000000000
0000000000006010E004E4F5449465949434F4E4441544100000000360009004279746541727
261795800000058000000C4041300010000000700000079C10000CD0315004E6F74696679204
D657373616765000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000F3820100460504000300000049636F6E0000000
000000000100000000E02110053544253696E676C65746F6E50726F7879000000007A0000000
0000000200100009200000018000000496D61676552656C617469766546696C654C6F6361746
F720E010E0053544253796D626F6C50726F787900000000920000000700000063757272656E7
4920000000D0000005368656C6C566965772E69636F0E021F0053544245787465726E616C526
5736F757263654C69627261727950726F7879000000009200000010000000646F6C7068696E6
4723030342E646C6C00000000920000000E0000004E6F74696679204D65737361676506010F0
04D65737361676553657175656E6365000000000E021200535442436F6C6C656374696F6E507
26F7879000000007A000000000000002001000092000000110000004F726465726564436F6C6
C656374696F6EC20000000200000006030B004D65737361676553656E6400000000FA0100000
0000000920000001000000063726561746541743A657874656E743AC20000000200000006020
500506F696E74000000000100000001000000320300000000000055050000010400006000000
0E202000000000000FA0100000000000092000000080000006D656E754261723AC2000000010
00000000000006000000006010F0057494E444F57504C4143454D454E5400000000720100002
C0000002C0000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0000000000000
000AA020000000200009A02000000000000B0020000400100003203000000000000C1000000C
10000000000000015000000460504000300000049636F6E0000000000000000100000000E021
10053544253696E676C65746F6E50726F7879000000004E020D0001000000535442436C61737
350726F78790000000036000600537472696E6707000000446F6C7068696E120100001800000
0496D61676552656C617469766546696C654C6F6361746F720E010E0053544253796D626F6C5
0726F787900000000120100000700000063757272656E7412010000090000005368656C6C2E6
9636F0E021F0053544245787465726E616C5265736F757263654C69627261727950726F78790
00000001201000010000000646F6C7068696E64723030342E646C6C00000000'))!