Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Twapi 3.1 - SystemTray AddIcon

255 views
Skip to first unread message

Mark-in-TN

unread,
Oct 4, 2011, 8:58:07 AM10/4/11
to
I'm using twapi 3.1 on WIndows 7 to add an icon to the system tray
when a small wish 8.5 application is running. Here's an example:

proc TbarHandle { id event loc time } {
if {$event == "lbuttondown"} {
wm deiconify .
}
if {$event == "rbuttondown"} {
wm iconify .
}
}

set i [ twapi::load_icon_from_file c:/myicon.ico ]
set j [ twapi::systemtray addicon $i TbarHandle ]

I'd like to display a popup menu when the icon is right-clicked. Does
anyone have an example of how to do this?

Thanks.

Ashok Nadkarni

unread,
Oct 4, 2011, 11:36:12 AM10/4/11
to
For the popup menu itself, use the standard Tk 'menu' command.

Also, for correct keyboard based selection/navigation, match against
"contextmenu" as the event, not "rbuttondown". "contextmenu" will
include both right mouse as well keyboard based selection.

Something like the following (cut'n'pasted from working code but
modifications untested)

#
# Post the taskbar menu at the specified position
proc show_taskbar_menu {x y} {

# See http://support.microsoft.com/kb/q135788/
# Without this, clicking outside the menu does not cause menu to
disappear
# and cursor keys and ESC do not work.
set hwin [twapi::Twapi_GetNotificationWindow]
twapi::set_foreground_window $hwin

# Assumes you have created a menu previously and stored the command
# in
$::taskbar_menu post $x $y

twapi::PostMessage $hwin 0 0 0
}

Within your handler,
if {event eq "contextmenu"} {
# loc contains mouse location but for whatever reason
# not always accurate under load if user moves the mouse
# so get the location ourselves
lassign [twapi::get_mouse_location] x y
show_taskbar_menu $x $y
return
}
..other event handlers...

/Ashok

Mark-in-TN

unread,
Oct 5, 2011, 10:22:53 AM10/5/11
to
On Oct 4, 10:36 am, Ashok Nadkarni <palm...@yahoo.com> wrote:
> For the popup menu itself, use the standard Tk 'menu' command.
>
> Also, for correct keyboard based selection/navigation, match against
> "contextmenu" as the event, not "rbuttondown". "contextmenu" will
> include both right mouse as well keyboard based selection.
>
> Something like the following (cut'n'pasted from working code but
> modifications untested)
>
> #
> # Post the taskbar menu at the specified position
> proc show_taskbar_menu {x y} {
>
>      # Seehttp://support.microsoft.com/kb/q135788/
Thanks!
0 new messages