![]() which tells SetMenuInfo to alter the info for the submenus as well. Another interesting flag is the MIM_APPLYTOSUBMENUS. To change the background, use the flag MIM_BACKGROUND. The fMask struct member is important in telling SetMenuInfo what to do to the Menu whose handle is passed. SetMenuInfo takes a pointer to a MENUINFO structure, which can be created using the ctypes.pointer() function. To pass a structure to a Win23 call, use ctypes module and subclass ctypes.Structure. DrawMenuBar - Refreshes the menu bar, after setting the menu's information structure. SetMenuInfo - Sets the menu characteristics based on a filled-in MENUINFO structure.ĥ. CreateSolidBrush - Create a COLORREF (RGB) based brush.Ĥ. In the example above, 0 = File Menu, 1 = Help Menu.ģ. GetSubMenu - gets submenu handle, given the menu handle and the 0-based index of the the submenu. GetMenu - gets menu handle for the given window handle.Ģ. The calls operate on the Windows handle and the handle of the wxPython frame is got using GetHandle().ġ. The solution I came up with to set the background color is by using Win32 API calls. The background of the menubar can not be set using SetBackgroundColour() in wxPython (or at least did not work for me!). The motivation for this came about from a question posted on the wxpython-users mailing list where someone wanted to create a themed window in WinXP but was unable to change the background color of the menubar. ![]() PySimpleApp () f = TestFrame ( None, shadesubmenus = bShadeSubMenus ) app. argv except : bShadeSubMenus = False app = wx. hwnd ) if _name_ = '_main_' : try : bShadeSubMenus = sys. hwnd ), 1 ), pointer ( menuinfo )) DrawMenuBar ( self. ![]() hbrBack = CreateSolidBrush ( COLORREF ( 128, 255, 128 )) SetMenuInfo ( GetSubMenu ( GetMenu ( self. hwnd ), 0 ), pointer ( menuinfo )) menuinfo. hbrBack = CreateSolidBrush ( COLORREF ( 255, 255, 0 )) SetMenuInfo ( GetSubMenu ( GetMenu ( self. hbrBack = CreateSolidBrush ( COLORREF ( 255, 0, 0 )) # Important! Pass *pointer* of the menuinfo instance to the win32 call SetMenuInfo ( GetMenu ( self. CreateSolidBrush # Instantiate MENUINFO menuinfo = MENUINFO () # Important to set the size menuinfo. ChangeMenuBarColor () def ChangeMenuBarColor ( self ): """ Changes the background color of the menubar and optionally gives different colors to menu items """ user32 = windll. GetSize () # Get my windows handle - hwnd self. ![]() Append ( - 1, 'About', 'About' ) menubar. Append ( - 1, 'Exit', 'Quit application' ) menubar. Append ( - 1, 'Open', 'Open new file' ) menu1. bShadeSubMenus = shadesubmenus menubar = wx. _init_ ( self, parent, id, title, pos, size, style, name ) self. NO_FULL_REPAINT_ON_RESIZE, name = 'TestFrame', shadesubmenus = False ): wx. Frame ): """ Subclass of wx.Frame that presents the app's main window """ def _init_ ( self, parent, id =- 1, title = 'Test Menu', pos = wx. import wx import win32con from ctypes import * import sys # Structure passed to CreateSolidBrush function # Represents RGB class COLORREF ( Structure ): _fields_ = # Menu structure used in calls to SetMenuInfo class MENUINFO ( Structure ): _fields_ = class TestFrame ( wx. Alternative is to get the values of the constants # from MSDN. # This script demonstrates changing the color of the menu bar/individual # menus in a wxPython UI for the Win32 platform # Requires # - ctypes to access the user32 and gdi32 modules, to set up structures # and other win32 oriented helper functions # - pywin32 module, to use win32con and access constants (this is optional # but really handy).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |