-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtitlebar.py
62 lines (53 loc) · 1.87 KB
/
titlebar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import win32con
from ctypes import *
import sys
# Structure passed to CreateSolidBrush function
# Represents RGB
class COLORREF(Structure):
_fields_ = [
("byRed", c_byte),
("byGreen", c_byte),
("byBlue", c_byte)
]
# Menu structure used in calls to SetMenuInfo
class MENUINFO(Structure):
_fields_ = [
("cbSize", c_long),
("fMask", c_long),
("dwStyle", c_long),
('cyMax', c_long),
("hbrBack", c_long),
("dwContextHelpID", c_long),
("dwMenuData", c_long)
]
def ChangeMenuBarColor(hwnd):
"""
Changes the background color of the menubar and optionally gives
different colors to menu items
"""
user32 = windll.user32
DrawMenuBar = user32.DrawMenuBar
GetMenu = user32.GetMenu
GetSubMenu = user32.GetSubMenu
GetSystemMenu = user32.GetSystemMenu
SetMenuInfo = user32.SetMenuInfo
GetMenuInfo = user32.GetMenuInfo
gdi32 = windll.gdi32
CreateSolidBrush = gdi32.CreateSolidBrush
# Instantiate MENUINFO
menuinfo = MENUINFO()
# Important to set the size
menuinfo.cbSize = sizeof(MENUINFO)
menuinfo.fMask = win32con.MIM_BACKGROUND
#if not self.bShadeSubMenus:
#menuinfo.fMask |= win32con.MIM_APPLYTOSUBMENUS
menuinfo.hbrBack = CreateSolidBrush(COLORREF(255, 0, 0))
# Important! Pass *pointer* of the menuinfo instance to the win32 call
SetMenuInfo(GetMenu(hwnd), pointer(menuinfo))
menuinfo.fMask = win32con.MIM_BACKGROUND | win32con.MIM_APPLYTOSUBMENUS
menuinfo.hbrBack = CreateSolidBrush(COLORREF(255, 255, 0))
SetMenuInfo(GetSubMenu(GetMenu(hwnd), 0), pointer(menuinfo))
menuinfo.fMask = win32con.MIM_BACKGROUND | win32con.MIM_APPLYTOSUBMENUS
menuinfo.hbrBack = CreateSolidBrush(COLORREF(128, 255, 128))
SetMenuInfo(GetSubMenu(GetMenu(hwnd), 1), pointer(menuinfo))
DrawMenuBar(hwnd)