本文整理汇总了Python中win32gui.CreatePopupMenu方法的典型用法代码示例。如果您正苦于以下问题:Python win32gui.CreatePopupMenu方法的具体用法?Python win32gui.CreatePopupMenu怎么用?Python win32gui.CreatePopupMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32gui
的用法示例。
在下文中一共展示了win32gui.CreatePopupMenu方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OnTaskbarNotify
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
if lparam==win32con.WM_LBUTTONUP:
print "You clicked me."
elif lparam==win32con.WM_LBUTTONDBLCLK:
print "You double-clicked me - goodbye"
win32gui.DestroyWindow(self.hwnd)
elif lparam==win32con.WM_RBUTTONUP:
print "You right clicked me."
menu = win32gui.CreatePopupMenu()
win32gui.AppendMenu( menu, win32con.MF_STRING, 1023, "Display Dialog")
win32gui.AppendMenu( menu, win32con.MF_STRING, 1024, "Say Hello")
win32gui.AppendMenu( menu, win32con.MF_STRING, 1025, "Exit program" )
pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
win32gui.SetForegroundWindow(self.hwnd)
win32gui.TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
return 1
示例2: show_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def show_menu(self):
menu = win32gui.CreatePopupMenu()
self.create_menu(menu, self.menu_options)
# win32gui.SetMenuDefaultItem(menu, 1000, 0)
pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
win32gui.SetForegroundWindow(self.hwnd)
win32gui.TrackPopupMenu(menu,
win32con.TPM_LEFTALIGN,
pos[0],
pos[1],
0,
self.hwnd,
None)
win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
示例3: create_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def create_menu(self, menu, menu_options):
for option_text, option_icon, option_action, option_id in menu_options[::-1]:
if option_icon:
option_icon = self.prep_menu_icon(option_icon)
if option_id in self.menu_actions_by_id:
item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
wID=option_id)
win32gui.InsertMenuItem(menu, 0, 1, item)
else:
submenu = win32gui.CreatePopupMenu()
self.create_menu(submenu, option_action)
item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
hSubMenu=submenu)
win32gui.InsertMenuItem(menu, 0, 1, item)
示例4: show_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def show_menu(self):
"""Draw the popup menu."""
menu = win32gui.CreatePopupMenu()
self._create_menu(menu, self.menu_options)
pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
win32gui.SetForegroundWindow(self.hwnd)
win32gui.TrackPopupMenu(menu,
win32con.TPM_LEFTALIGN,
pos[0],
pos[1],
0,
self.hwnd,
None)
win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
self.logger.debug('Menu displayed.')
示例5: show_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def show_menu(self):
menu = win32gui.CreatePopupMenu()
self.create_menu(menu, self.menu_options)
#win32gui.SetMenuDefaultItem(menu, 1000, 0)
pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
win32gui.SetForegroundWindow(self.hwnd)
win32gui.TrackPopupMenu(menu,
win32con.TPM_LEFTALIGN,
pos[0],
pos[1],
0,
self.hwnd,
None)
win32gui.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
示例6: create_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def create_menu(self, menu, menu_options):
for option_text, option_icon, option_action, option_id in menu_options[::-1]:
if option_icon:
option_icon = self.prep_menu_icon(option_icon)
if option_id in self.menu_actions_by_id:
item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
wID=option_id)
win32gui.InsertMenuItem(menu, 0, 1, item)
else:
submenu = win32gui.CreatePopupMenu()
self.create_menu(submenu, option_action)
item, extras = win32gui_struct.PackMENUITEMINFO(text=option_text,
hbmpItem=option_icon,
hSubMenu=submenu)
win32gui.InsertMenuItem(menu, 0, 1, item)
示例7: _show_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def _show_menu( self ):
menu = win32gui.CreatePopupMenu()
for action in self.menu_actions:
if action:
flags = win32con.MF_STRING
if not action.sensitive:
flags |= win32con.MF_GRAYED
win32gui.AppendMenu( menu, flags, action.get_id(), action.label )
else:
win32gui.AppendMenu( menu, win32con.MF_SEPARATOR, 0, '' )
pos = win32gui.GetCursorPos()
win32gui.SetForegroundWindow( self.window_handle )
win32gui.TrackPopupMenu( menu,
win32con.TPM_LEFTALIGN | win32con.TPM_BOTTOMALIGN,
pos[ 0 ],
pos[ 1 ],
0,
self.window_handle,
None )
win32gui.PostMessage( self.window_handle, win32con.WM_NULL, 0, 0 )
示例8: _create_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def _create_menu(self, menu, menu_options):
"""Generate the popup menu just before drawing.
This is needed as it recursively runs on submenus.
"""
for menu_option in menu_options[::-1]:
if menu_option.get('hidden', False):
continue
text = menu_option.get('name', 'Option')
icon = menu_option.get('icon', None)
action = menu_option.get('action', None)
id = menu_option.get('_id')
#Set icon
if icon:
try:
icon = self._set_icon_menu(icon)
except pywintypes.error:
icon = None
#Add menu item
if id in self.menu_actions_by_id or action is None:
item, extras = win32gui_struct.PackMENUITEMINFO(text=text,
hbmpItem=icon,
wID=id)
win32gui.InsertMenuItem(menu, 0, 1, item)
#Add submenu
else:
submenu = win32gui.CreatePopupMenu()
self._create_menu(submenu, action)
item, extras = win32gui_struct.PackMENUITEMINFO(text=text,
hbmpItem=icon,
hSubMenu=submenu)
win32gui.InsertMenuItem(menu, 0, 1, item)
示例9: get_popup
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def get_popup(self):
menu = win32gui.CreatePopupMenu()
(item, _) = win32gui_struct.PackMENUITEMINFO(text='Quit', wID=self.IDI_QUIT)
win32gui.InsertMenuItem(menu, 0, 1, item)
win32gui.SetMenuDefaultItem(menu, 0, self.IDI_QUIT)
(item, _) = win32gui_struct.PackMENUITEMINFO(text='Test', wID=123)
win32gui.InsertMenuItem(menu, 0, 1, item)
return menu
示例10: show_menu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def show_menu(self):
menu = win32gui.CreatePopupMenu()
self.create_menu(menu)
pos = win32gui.GetCursorPos()
win32gui.SetForegroundWindow(self.shell.main_frame.hwnd)
win32gui.TrackPopupMenu(menu,
win32con.TPM_LEFTALIGN,
pos[0],
pos[1],
0,
self.shell.main_frame.hwnd,
None)
示例11: OnContextMenu
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def OnContextMenu(self, hwnd, msg, wparam, lparam):
# Get the selected items.
pidls = []
n = -1
while 1:
n = win32gui.SendMessage(self.hwnd_child,
commctrl.LVM_GETNEXTITEM,
n,
commctrl.LVNI_SELECTED)
if n==-1:
break
pidls.append(self.children[n][-1:])
spt = win32api.GetCursorPos()
if not pidls:
print "Ignoring background click"
return
# Get the IContextMenu for the items.
inout, cm = self.folder.GetUIObjectOf(self.hwnd_parent, pidls, shell.IID_IContextMenu, 0)
hmenu = win32gui.CreatePopupMenu()
sel = None
# As per 'Q179911', we need to determine if the default operation
# should be 'open' or 'explore'
try:
flags = 0
try:
self.browser.GetControlWindow(shellcon.FCW_TREE)
flags |= shellcon.CMF_EXPLORE
except pythoncom.com_error:
pass
id_cmd_first = 1 # TrackPopupMenu makes it hard to use 0
cm.QueryContextMenu(hmenu, 0, id_cmd_first, -1, flags)
tpm_flags = win32con.TPM_LEFTALIGN | win32con.TPM_RETURNCMD | \
win32con.TPM_RIGHTBUTTON
sel = win32gui.TrackPopupMenu(hmenu,
tpm_flags,
spt[0], spt[1],
0, self.hwnd, None)
print "TrackPopupMenu returned", sel
finally:
win32gui.DestroyMenu(hmenu)
if sel:
ci = 0, self.hwnd_parent, sel-id_cmd_first, None, None, 0, 0, 0
cm.InvokeCommand(ci)
示例12: icon_wndproc
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def icon_wndproc(hwnd, msg, wp, lp):
""" Window proc for the tray icons """
if lp==win32con.WM_LBUTTONDOWN:
## popup menu won't disappear if you don't do this
win32gui.SetForegroundWindow(hwnd)
curr_desktop=win32service.OpenInputDesktop(0,True,win32con.MAXIMUM_ALLOWED)
curr_desktop_name=win32service.GetUserObjectInformation(curr_desktop,win32con.UOI_NAME)
winsta=win32service.GetProcessWindowStation()
desktops=winsta.EnumDesktops()
m=win32gui.CreatePopupMenu()
desktop_cnt=len(desktops)
## *don't* create an item 0
for d in range(1, desktop_cnt+1):
mf_flags=win32con.MF_STRING
## if you switch to winlogon yourself, there's nothing there and you're stuck
if desktops[d-1].lower() in ('winlogon','disconnect'):
mf_flags=mf_flags|win32con.MF_GRAYED|win32con.MF_DISABLED
if desktops[d-1]==curr_desktop_name:
mf_flags=mf_flags|win32con.MF_CHECKED
win32gui.AppendMenu(m, mf_flags, d, desktops[d-1])
win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt+1, 'Create new ...')
win32gui.AppendMenu(m, win32con.MF_STRING, desktop_cnt+2, 'Exit')
x,y=win32gui.GetCursorPos()
d=win32gui.TrackPopupMenu(m,win32con.TPM_LEFTBUTTON|win32con.TPM_RETURNCMD|win32con.TPM_NONOTIFY,
x,y, 0, hwnd, None)
win32gui.PumpWaitingMessages()
win32gui.DestroyMenu(m)
if d==desktop_cnt+1: ## Create new
get_new_desktop_name(hwnd)
elif d==desktop_cnt+2: ## Exit
win32gui.PostQuitMessage(0)
win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, window_info[hwnd])
del window_info[hwnd]
origin_desktop.SwitchDesktop()
elif d>0:
hdesk=win32service.OpenDesktop(desktops[d-1],0,0,win32con.MAXIMUM_ALLOWED)
hdesk.SwitchDesktop()
return 0
else:
return win32gui.DefWindowProc(hwnd, msg, wp, lp)
示例13: OnTaskbarNotify
# 需要导入模块: import win32gui [as 别名]
# 或者: from win32gui import CreatePopupMenu [as 别名]
def OnTaskbarNotify(
self,
hwnd,
msg,
wparam,
lparam,
):
if lparam == win32con.WM_LBUTTONUP:
pass
elif lparam == win32con.WM_LBUTTONDBLCLK:
pass
elif lparam == win32con.WM_RBUTTONUP:
menu = win32gui.CreatePopupMenu()
win32gui.AppendMenu(menu, win32con.MF_STRING, 1023,
'Toggle Display')
win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '')
if self.serverState == self.EnumServerState.STOPPED:
win32gui.AppendMenu(menu, win32con.MF_STRING, 1024,
'Start Server')
win32gui.AppendMenu(menu, win32con.MF_STRING
| win32con.MF_GRAYED, 1025,
'Restart Server')
win32gui.AppendMenu(menu, win32con.MF_STRING
| win32con.MF_GRAYED, 1026,
'Stop Server')
else:
win32gui.AppendMenu(menu, win32con.MF_STRING
| win32con.MF_GRAYED, 1024,
'Start Server')
win32gui.AppendMenu(menu, win32con.MF_STRING, 1025,
'Restart Server')
win32gui.AppendMenu(menu, win32con.MF_STRING, 1026,
'Stop Server')
win32gui.AppendMenu(menu, win32con.MF_SEPARATOR, 0, '')
win32gui.AppendMenu(menu, win32con.MF_STRING, 1027,
'Quit (pid:%i)' % os.getpid())
pos = win32gui.GetCursorPos()
# See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp
win32gui.SetForegroundWindow(self.hwnd)
win32gui.TrackPopupMenu(
menu,
win32con.TPM_LEFTALIGN,
pos[0],
pos[1],
0,
self.hwnd,
None,
)
win32api.PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
return 1