def get_icon_from_window(hwnd): """Create an icon file in the temp directory for the window handle and return its path. Actually, it is not unclear how the Windows API works to retrieve the icon info and save it as icon... """ hicon = win32api.SendMessage(hwnd, win32con.WM_GETICON, win32con.ICON_BIG) if hicon == 0: hicon = win32api.SendMessage(hwnd, win32con.WM_GETICON, win32con.ICON_SMALL) if hicon == 0: hicon = win32gui.GetClassLong(hwnd, win32con.GCL_HICON) if hicon == 0: hicon = win32gui.GetClassLong(hwnd, win32con.GCL_HICONSM) if hicon == 0: hicon = get_hicon_from_exe(hwnd) if hicon == 0: return None ico_x = win32api.GetSystemMetrics(win32con.SM_CXICON) # creating a destination memory DC hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0)) hbmp = win32ui.CreateBitmap() hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_x) hdc = hdc.CreateCompatibleDC() hdc.SelectObject(hbmp) hdc.DrawIcon((0, 0), hicon) # file_path = TEMP_DIR + "\Icontemp" + str(hwnd) + ".bmp" file_path = ICONFILE_TEMP_STR.format(str(hwnd)) hbmp.SaveBitmapFile(hdc, file_path) return file_path
def get_hicon(hWin): hIcon = win32api.SendMessage(hWin, win32con.WM_GETICON, win32con.FALSE, 0) if hIcon == win32con.NULL: hIcon = win32api.SendMessage(hWin, win32con.WM_GETICON, win32con.TRUE, 0) if hIcon == win32con.NULL: hIcon = win32gui.GetClassLong(hWin, win32con.GCL_HICONSM) if hIcon == win32con.NULL: hIcon = win32gui.GetClassLong(hWin, win32con.GCL_HICON) if hIcon == win32con.NULL: hIcon = win32gui.LoadIcon(win32con.NULL, MAKEINTRESOURCE(win32con.IDI_APPLICATION)) return hIcon
def DropShadow(self, drop=True): """ Adds a shadow under the window. :param `drop`: whether to drop a shadow or not. :note: This method is available only on Windows and requires Mark Hammond's pywin32 package. """ if not _libimported: # No Mark Hammond's win32all extension return if wx.Platform != "__WXMSW__": # This works only on Windows XP return hwnd = self.GetHandle() # Create a rounded rectangle region size = self.GetSize() if drop: if hasattr(win32gui, "CreateRoundRectRgn"): rgn = win32gui.CreateRoundRectRgn(0, 0, size.x, size.y, 9, 9) win32gui.SetWindowRgn(hwnd, rgn, True) CS_DROPSHADOW = 0x00020000 # Load the user32 library if not hasattr(self, "_winlib"): self._winlib = win32api.LoadLibrary("user32") csstyle = win32api.GetWindowLong(hwnd, win32con.GCL_STYLE) if drop: if csstyle & CS_DROPSHADOW: return else: csstyle |= CS_DROPSHADOW #Nothing to be done else: csstyle &= ~CS_DROPSHADOW # Drop the shadow underneath the window GCL_STYLE = -26 cstyle = win32gui.GetClassLong(hwnd, GCL_STYLE) if drop: if cstyle & CS_DROPSHADOW == 0: win32api.SetClassLong(hwnd, GCL_STYLE, cstyle | CS_DROPSHADOW) else: win32api.SetClassLong(hwnd, GCL_STYLE, cstyle & ~CS_DROPSHADOW)
def DropShadow(w, drop=True): if wx.Platform != "__WXMSW__" or _importFail: return hwnd = w.GetHandle() size = w.GetSize() rgn = win32gui.CreateRoundRectRgn(0, 0, size.x + 1, size.y + 1, _rounded, _rounded) win32gui.SetWindowRgn(hwnd, rgn, True) CS_DROPSHADOW = 0x00020000 GCL_STYLE = -26 cstyle = win32gui.GetClassLong(hwnd, GCL_STYLE) if drop: if cstyle & CS_DROPSHADOW == 0: win32api.SetClassLong(hwnd, GCL_STYLE, cstyle | CS_DROPSHADOW) else: win32api.SetClassLong(hwnd, GCL_STYLE, cstyle & ~ CS_DROPSHADOW)