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