Python win32con.DI_NORMAL Examples
The following are 6
code examples of win32con.DI_NORMAL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32con
, or try the search function
.
Example #1
Source File: gui_win.py From ComicStreamer with Apache License 2.0 | 7 votes |
def prep_menu_icon(self, icon): # First load the icon. ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(0) hdcScreen = win32gui.GetDC(0) hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y) hbmOld = win32gui.SelectObject(hdcBitmap, hbm) # Fill the background. brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush) # unclear if brush needs to be feed. Best clue I can find is: # "GetSysColorBrush returns a cached brush instead of allocating a new # one." - implies no DeleteObject # draw the icon win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) win32gui.SelectObject(hdcBitmap, hbmOld) win32gui.DeleteDC(hdcBitmap) return hbm
Example #2
Source File: SysTrayIcon.py From LIFX-Control-Panel with MIT License | 6 votes |
def prep_menu_icon(self, icon): # First load the icon. ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(0) hdcScreen = win32gui.GetDC(0) hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y) hbmOld = win32gui.SelectObject(hdcBitmap, hbm) # Fill the background. brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush) # unclear if brush needs to be feed. Best clue I can find is: # "GetSysColorBrush returns a cached brush instead of allocating a new # one." - implies no DeleteObject # draw the icon win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) win32gui.SelectObject(hdcBitmap, hbmOld) win32gui.DeleteDC(hdcBitmap) return hbm
Example #3
Source File: systray.py From OpenBazaar-Installer with MIT License | 6 votes |
def prep_menu_icon(self, icon): # First load the icon. ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(0) hdcScreen = win32gui.GetDC(0) hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y) hbmOld = win32gui.SelectObject(hdcBitmap, hbm) # Fill the background. brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush) # unclear if brush needs to be feed. Best clue I can find is: # "GetSysColorBrush returns a cached brush instead of allocating a new # one." - implies no DeleteObject # draw the icon win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) win32gui.SelectObject(hdcBitmap, hbmOld) win32gui.DeleteDC(hdcBitmap) return hbm
Example #4
Source File: shell.py From eavatar-me with Apache License 2.0 | 6 votes |
def prep_menu_icon(self, icon): # First load the icon. ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hicon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hdcBitmap = win32gui.CreateCompatibleDC(0) hdcScreen = win32gui.GetDC(0) hbm = win32gui.CreateCompatibleBitmap(hdcScreen, ico_x, ico_y) hbmOld = win32gui.SelectObject(hdcBitmap, hbm) # Fill the background. brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush) # unclear if brush needs to be feed. Best clue I can find is: # "GetSysColorBrush returns a cached brush instead of allocating a new # one." - implies no DeleteObject # draw the icon win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) win32gui.SelectObject(hdcBitmap, hbmOld) win32gui.DeleteDC(hdcBitmap) return hbm
Example #5
Source File: tray.py From MouseTracks with GNU General Public License v3.0 | 5 votes |
def _set_icon_menu(self, icon): """Load icons into the tray items. Got from https://stackoverflow.com/a/45890829. """ ico_x = win32api.GetSystemMetrics(win32con.SM_CXSMICON) ico_y = win32api.GetSystemMetrics(win32con.SM_CYSMICON) hIcon = win32gui.LoadImage(0, icon, win32con.IMAGE_ICON, ico_x, ico_y, win32con.LR_LOADFROMFILE) hwndDC = win32gui.GetWindowDC(self.hwnd) dc = win32ui.CreateDCFromHandle(hwndDC) memDC = dc.CreateCompatibleDC() iconBitmap = win32ui.CreateBitmap() iconBitmap.CreateCompatibleBitmap(dc, ico_x, ico_y) oldBmp = memDC.SelectObject(iconBitmap) brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU) win32gui.FillRect(memDC.GetSafeHdc(), (0, 0, ico_x, ico_y), brush) win32gui.DrawIconEx(memDC.GetSafeHdc(), 0, 0, hIcon, ico_x, ico_y, 0, 0, win32con.DI_NORMAL) memDC.SelectObject(oldBmp) memDC.DeleteDC() win32gui.ReleaseDC(self.hwnd, hwndDC) self.logger.debug('Set menu icon.') return iconBitmap.GetHandle()
Example #6
Source File: win32gui_menu.py From ironpython2 with Apache License 2.0 | 4 votes |
def OnDrawItem(self, hwnd, msg, wparam, lparam): ## lparam is a DRAWITEMSTRUCT fmt = "5i2P4iP" data = struct.unpack(fmt, PyGetMemory(lparam, struct.calcsize(fmt))) ctlType, ctlID, itemID, itemAction, itemState, hwndItem, \ hDC, left, top, right, bot, itemData = data rect = left, top, right, bot hicon, text = self.menu_item_map[itemData] if text is None: # This means the menu-item had HBMMENU_CALLBACK - so all we # draw is the icon. rect is the entire area we should use. DrawIconEx(hDC, left, top, hicon, right-left, bot-top, 0, 0, win32con.DI_NORMAL) else: # If the user has selected the item, use the selected # text and background colors to display the item. selected = itemState & win32con.ODS_SELECTED if selected: crText = SetTextColor(hDC, GetSysColor(win32con.COLOR_HIGHLIGHTTEXT)) crBkgnd = SetBkColor(hDC, GetSysColor(win32con.COLOR_HIGHLIGHT)) each_pad = self.icon_x_pad // 2 x_icon = left + GetSystemMetrics(win32con.SM_CXMENUCHECK) + each_pad x_text = x_icon + self.menu_icon_width + each_pad # Draw text first, specifying a complete rect to fill - this sets # up the background (but overwrites anything else already there!) # Select the font, draw it, and restore the previous font. hfontOld = SelectObject(hDC, self.font_menu) ExtTextOut(hDC, x_text, top+2, win32con.ETO_OPAQUE, rect, text) SelectObject(hDC, hfontOld) # Icon image next. Icons are transparent - no need to handle # selection specially. DrawIconEx(hDC, x_icon, top+2, hicon, self.menu_icon_width, self.menu_icon_height, 0, 0, win32con.DI_NORMAL) # Return the text and background colors to their # normal state (not selected). if selected: SetTextColor(hDC, crText) SetBkColor(hDC, crBkgnd)