Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 def prep_menu_icon(self, 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)
     brush = win32gui.GetSysColorBrush(win32con.COLOR_MENU)
     win32gui.FillRect(hdcBitmap, (0, 0, 16, 16), brush)
     win32gui.DrawIconEx(hdcBitmap, 0, 0, hicon, ico_x, ico_y, 0, 0,
                         win32con.DI_NORMAL)
     win32gui.SelectObject(hdcBitmap, hbmOld)
     win32gui.DeleteDC(hdcBitmap)
     return hbm