Skip to content

Commit d3772be

Browse files
committed
[Win32] Use PrintWindow() with PW_RENDERFULLCONTENT flag
Resolves #373.
1 parent d30571a commit d3772be

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class OS extends C {
3939
/**
4040
* Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
4141
*/
42+
public static final int WIN32_BUILD_WIN8_1 = 9600; // "Windows 8.1"
4243
public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update"
4344
public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update"
4445
public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update"
@@ -1067,6 +1068,7 @@ public class OS extends C {
10671068
public static final int PLANES = 0xe;
10681069
public static final int PM_NOREMOVE = 0x0;
10691070
public static final int PM_NOYIELD = 0x2;
1071+
public static final int PW_RENDERFULLCONTENT = 0x2; // undocumented ( >= Windows 8.1)
10701072
public static final int QS_HOTKEY = 0x0080;
10711073
public static final int QS_KEY = 0x0001;
10721074
public static final int QS_MOUSEMOVE = 0x0002;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,15 +2216,23 @@ public boolean print (GC gc) {
22162216
}
22172217
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22182218
OS.RedrawWindow (topHandle, null, 0, flags);
2219-
printWidget (topHandle, hdc, gc);
2219+
int printWindowFlags = 0;
2220+
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) {
2221+
/*
2222+
* Undocumented flag in windows, which also allows the capturing
2223+
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2224+
*/
2225+
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
2226+
}
2227+
printWidget (topHandle, hdc, gc, printWindowFlags);
22202228
if (gdipGraphics != 0) {
22212229
OS.RestoreDC(hdc, state);
22222230
Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
22232231
}
22242232
return true;
22252233
}
22262234

2227-
void printWidget (long hwnd, long hdc, GC gc) {
2235+
void printWidget (long hwnd, long hdc, GC gc, int printWindowFlags) {
22282236
/*
22292237
* Bug in Windows. For some reason, PrintWindow()
22302238
* returns success but does nothing when it is called
@@ -2308,7 +2316,7 @@ void printWidget (long hwnd, long hdc, GC gc) {
23082316
if ((bits1 & OS.WS_VISIBLE) == 0) {
23092317
OS.ShowWindow (hwnd, OS.SW_SHOW);
23102318
}
2311-
success = OS.PrintWindow (hwnd, hdc, 0);
2319+
success = OS.PrintWindow (hwnd, hdc, printWindowFlags);
23122320
if ((bits1 & OS.WS_VISIBLE) == 0) {
23132321
OS.ShowWindow (hwnd, OS.SW_HIDE);
23142322
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Group.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ boolean mnemonicMatch (char key) {
294294
}
295295

296296
@Override
297-
void printWidget (long hwnd, long hdc, GC gc) {
297+
void printWidget (long hwnd, long hdc, GC gc, int printWindowFlags) {
298298
/*
299299
* Bug in Windows. For some reason, PrintWindow()
300300
* returns success but does nothing when it is called
@@ -307,7 +307,7 @@ void printWidget (long hwnd, long hdc, GC gc) {
307307
if ((bits & OS.WS_VISIBLE) == 0) {
308308
OS.ShowWindow (hwnd, OS.SW_SHOW);
309309
}
310-
success = OS.PrintWindow (hwnd, hdc, 0);
310+
success = OS.PrintWindow (hwnd, hdc, printWindowFlags);
311311
if ((bits & OS.WS_VISIBLE) == 0) {
312312
OS.ShowWindow (hwnd, OS.SW_HIDE);
313313
}
@@ -334,6 +334,14 @@ void printWidget (long hwnd, long hdc, GC gc) {
334334
Control [] children = _getChildren ();
335335
Rectangle rect = getBoundsInPixels ();
336336
OS.IntersectClipRect (hdc, 0, 0, rect.width, rect.height);
337+
// When looping over child windows and printWindowFlags has
338+
// PW_RENDERFULLCONTENT set, then the printed content is always
339+
// rendered at the top-left of the passed hdc.
340+
// clear that flag
341+
// This should be not an issue, since with PW_RENDERFULLCONTENT set
342+
// the problem above (push button) does not appear to occurr.
343+
// To be on the safe side, clear the flag when dealing with children
344+
printWindowFlags &= ~OS.PW_RENDERFULLCONTENT;
337345
for (int i=children.length - 1; i>=0; --i) {
338346
Point location = children [i].getLocationInPixels ();
339347
int graphicsMode = OS.GetGraphicsMode(hdc);
@@ -346,7 +354,7 @@ void printWidget (long hwnd, long hdc, GC gc) {
346354
long topHandle = children [i].topHandle();
347355
int bits = OS.GetWindowLong (topHandle, OS.GWL_STYLE);
348356
if ((bits & OS.WS_VISIBLE) != 0) {
349-
children [i].printWidget (topHandle, hdc, gc);
357+
children [i].printWidget (topHandle, hdc, gc, printWindowFlags);
350358
}
351359
if (graphicsMode == OS.GM_ADVANCED) {
352360
float [] lpXform = {1, 0, 0, 1, -location.x, -location.y};

0 commit comments

Comments
 (0)