我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用win32con.MF_GRAYED。
def SetHelpMenuOtherHelp(mainMenu): """Modifies the main Help Menu to handle all registered help files. mainMenu -- The main menu to modify - usually from docTemplate.GetSharedMenu() """ # Load all help files from the registry. global helpIDMap if helpIDMap is None: helpIDMap = {} cmdID = win32ui.ID_HELP_OTHER excludeList = ['Main Python Documentation', 'Pythonwin Reference'] firstList = ListAllHelpFiles() # We actually want to not only exclude these entries, but # their help file names (as many entries may share the same name) excludeFnames = [] for desc, fname in firstList: if desc in excludeList: excludeFnames.append(fname) helpDescs = [] for desc, fname in firstList: if fname not in excludeFnames: helpIDMap[cmdID] = (desc, fname) win32ui.GetMainFrame().HookCommand(HandleHelpOtherCommand, cmdID) cmdID = cmdID + 1 helpMenu = mainMenu.GetSubMenu(mainMenu.GetMenuItemCount()-1) # Help menu always last. otherHelpMenuPos = 2 # cant search for ID, as sub-menu has no ID. otherMenu = helpMenu.GetSubMenu(otherHelpMenuPos) while otherMenu.GetMenuItemCount(): otherMenu.DeleteMenu(0, win32con.MF_BYPOSITION) if helpIDMap: for id, (desc, fname) in helpIDMap.iteritems(): otherMenu.AppendMenu(win32con.MF_ENABLED|win32con.MF_STRING,id, desc) else: helpMenu.EnableMenuItem(otherHelpMenuPos, win32con.MF_BYPOSITION | win32con.MF_GRAYED)
def SetHelpMenuOtherHelp(mainMenu): """Modifies the main Help Menu to handle all registered help files. mainMenu -- The main menu to modify - usually from docTemplate.GetSharedMenu() """ # Load all help files from the registry. global helpIDMap if helpIDMap is None: helpIDMap = {} cmdID = win32ui.ID_HELP_OTHER excludeList = ['Main Python Documentation', 'Pythonwin Reference'] firstList = ListAllHelpFiles() # We actually want to not only exclude these entries, but # their help file names (as many entries may share the same name) excludeFnames = [] for desc, fname in firstList: if desc in excludeList: excludeFnames.append(fname) helpDescs = [] for desc, fname in firstList: if fname not in excludeFnames: helpIDMap[cmdID] = (desc, fname) win32ui.GetMainFrame().HookCommand(HandleHelpOtherCommand, cmdID) cmdID = cmdID + 1 helpMenu = mainMenu.GetSubMenu(mainMenu.GetMenuItemCount()-1) # Help menu always last. otherHelpMenuPos = 2 # cant search for ID, as sub-menu has no ID. otherMenu = helpMenu.GetSubMenu(otherHelpMenuPos) while otherMenu.GetMenuItemCount(): otherMenu.DeleteMenu(0, win32con.MF_BYPOSITION) if helpIDMap: for id, (desc, fname) in helpIDMap.items(): otherMenu.AppendMenu(win32con.MF_ENABLED|win32con.MF_STRING,id, desc) else: helpMenu.EnableMenuItem(otherHelpMenuPos, win32con.MF_BYPOSITION | win32con.MF_GRAYED)
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
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)
def getMenuInfo(hMenu, uIDItem): '''Get various info about a menu item. Arguments: hMenu The menu in which the item is to be found. uIDItem The item's index Returns: Menu item information object. This object is basically a 'bunch' (see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308). It will have useful attributes: name, itemCount, submenu, isChecked, isDisabled, isGreyed, and isSeperator Raises: WinGuiAutoError When the requested menu option isn't found. Usage example: submenuInfo = getMenuInfo(hMenu, submenu) hMenu, hMenuItemCount = submenuInfo.submenu, submenuInfo.itemCount''' # An object to hold the menu info class MenuInfo(Bunch): pass menuInfo = MenuInfo() # Menu state menuState = ctypes.windll.user32.GetMenuState(hMenu, uIDItem, win32con.MF_BYPOSITION) if menuState == -1: raise WinGuiAutoError("No such menu item, hMenu=" + str(hMenu) + " uIDItem=" + str(uIDItem)) menuInfo.isChecked = bool(menuState & win32con.MF_CHECKED) menuInfo.isDisabled = bool(menuState & win32con.MF_DISABLED) menuInfo.isGreyed = bool(menuState & win32con.MF_GRAYED) menuInfo.isSeperator = bool(menuState & win32con.MF_SEPARATOR) # ... there are more, but these are the ones I'm interested in # Menu name menuName = ctypes.c_buffer("\000" * 32) ctypes.windll.user32.GetMenuStringA(ctypes.c_int(hMenu), ctypes.c_int(uIDItem), menuName, ctypes.c_int(len(menuName)), win32con.MF_BYPOSITION) menuInfo.name = menuName.value # Sub menu info menuInfo.itemCount = menuState >> 8 if bool(menuState & win32con.MF_POPUP): menuInfo.submenu = ctypes.windll.user32.GetSubMenu(hMenu, uIDItem) else: menuInfo.submenu = None return menuInfo
def getMenuInfo(hMenu, uIDItem): #print "getMenuInfo fuction,hMenu,uIDItem",hMenu,uIDItem '''Get various info about a menu item. Arguments: hMenu The menu in which the item is to be found. uIDItem The item's index Returns: Menu item information object. This object is basically a 'bunch' (see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308). It will have useful attributes: name, itemCount, submenu, isChecked, isDisabled, isGreyed, and isSeperator Raises: WinGuiAutoError When the requested menu option isn't found. Usage example: submenuInfo = getMenuInfo(hMenu, submenu) hMenu, hMenuItemCount = submenuInfo.submenu, submenuInfo.itemCount''' # An object to hold the menu info class MenuInfo(Bunch): pass menuInfo = MenuInfo() # Menu state menuState = ctypes.windll.user32.GetMenuState(hMenu, uIDItem, win32con.MF_BYPOSITION) #print "menuState_MF_BYPOSITION:",ctypes.windll.user32.GetMenuState(hMenu,uIDItem,win32con.MF_BYPOSITION) #print "menuState_MF_BYCOMMAND:",ctypes.windll.user32.GetMenuState(hMenu,uIDItem,win32con.MF_BYCOMMAND) if menuState == -1: raise WinGuiAutoError("No such menu item, hMenu=" + str(hMenu) + " uIDItem=" + str(uIDItem)) menuInfo.isChecked = bool(menuState & win32con.MF_CHECKED) menuInfo.isDisabled = bool(menuState & win32con.MF_DISABLED) menuInfo.isGreyed = bool(menuState & win32con.MF_GRAYED) menuInfo.isSeperator = bool(menuState & win32con.MF_SEPARATOR) # ... there are more, but these are the ones I'm interested in # Menu name menuName = ctypes.c_buffer("\000" * 32) ctypes.windll.user32.GetMenuStringA(ctypes.c_int(hMenu), ctypes.c_int(uIDItem), menuName, ctypes.c_int(len(menuName)), win32con.MF_BYPOSITION) menuInfo.name = menuName.value # Sub menu info menuInfo.itemCount = menuState >> 8 if bool(menuState & win32con.MF_POPUP): menuInfo.submenu = ctypes.windll.user32.GetSubMenu(hMenu, uIDItem) else: menuInfo.submenu = None #print "menuInfo",menuInfo return menuInfo