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

View File

@ -375,6 +375,8 @@ def gdi_screenshot(x1, y1, x2, y2, hwnd=None):
rect.right = x2
rect.bottom = y2
bf = _gdi_screenshot(hwnd, rect, pointer(sz))
if not (sz.value and bf):
return None
data = cast(bf, POINTER(c_char))[: sz.value]
c_free(bf)
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)
{
*size = 0;
if (rect.bottom == rect.top || rect.left == rect.right)
return nullptr;
if (!hwnd)
hwnd = GetDesktopWindow();
auto hdc = GetDC(hwnd);