This commit is contained in:
恍兮惚兮 2024-05-28 13:52:32 +08:00
parent 4c6866c9ad
commit f7a05e5680
3 changed files with 9 additions and 2 deletions

View File

@ -51,6 +51,8 @@ def grabwindow(app, callback=None):
_() _()
try: try:
hwnd = gobject.baseobject.textsource.hwnd hwnd = gobject.baseobject.textsource.hwnd
if not hwnd:
raise
except: except:
hwnd = windows.GetForegroundWindow() hwnd = windows.GetForegroundWindow()
@ -77,7 +79,6 @@ def grabwindow(app, callback=None):
_() _()
def getprocesslist(): def getprocesslist():
pids = windows.EnumProcesses() pids = windows.EnumProcesses()
@ -233,5 +234,6 @@ def mouseselectwindow(callback):
def screenshot(x1, y1, x2, y2, hwnd=None): def screenshot(x1, y1, x2, y2, hwnd=None):
bs = winsharedutils.gdi_screenshot(x1, y1, x2, y2, hwnd) bs = winsharedutils.gdi_screenshot(x1, y1, x2, y2, hwnd)
pixmap = QPixmap() pixmap = QPixmap()
pixmap.loadFromData(bs) if bs:
pixmap.loadFromData(bs)
return pixmap return pixmap

View File

@ -375,6 +375,8 @@ def gdi_screenshot(x1, y1, x2, y2, hwnd=None):
rect.right = x2 rect.right = x2
rect.bottom = y2 rect.bottom = y2
bf = _gdi_screenshot(hwnd, rect, pointer(sz)) bf = _gdi_screenshot(hwnd, rect, pointer(sz))
if not (sz.value and bf):
return None
data = cast(bf, POINTER(c_char))[: sz.value] data = cast(bf, POINTER(c_char))[: sz.value]
c_free(bf) c_free(bf)
return data return data

View File

@ -158,6 +158,9 @@ BYTE *SaveBitmapToBuffer(HBITMAP hBitmap, size_t *size)
} }
DECLARE BYTE *gdi_screenshot(HWND hwnd, RECT rect, size_t *size) DECLARE BYTE *gdi_screenshot(HWND hwnd, RECT rect, size_t *size)
{ {
*size = 0;
if (rect.bottom == rect.top || rect.left == rect.right)
return nullptr;
if (!hwnd) if (!hwnd)
hwnd = GetDesktopWindow(); hwnd = GetDesktopWindow();
auto hdc = GetDC(hwnd); auto hdc = GetDC(hwnd);