Skip to content

Commit d42bca6

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

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"
@@ -1069,6 +1070,7 @@ public class OS extends C {
10691070
public static final int PLANES = 0xe;
10701071
public static final int PM_NOREMOVE = 0x0;
10711072
public static final int PM_NOYIELD = 0x2;
1073+
public static final int PW_RENDERFULLCONTENT = 0x2; // undocumented ( >= Windows 8.1)
10721074
public static final int QS_HOTKEY = 0x0080;
10731075
public static final int QS_KEY = 0x0001;
10741076
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
@@ -2219,15 +2219,23 @@ public boolean print (GC gc) {
22192219
}
22202220
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22212221
OS.RedrawWindow (topHandle, null, 0, flags);
2222-
printWidget (topHandle, hdc, gc);
2222+
int printWindowFlags = 0;
2223+
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) {
2224+
/*
2225+
* Undocumented flag in windows, which also allows the capturing
2226+
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2227+
*/
2228+
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
2229+
}
2230+
printWidget (topHandle, hdc, gc, printWindowFlags);
22232231
if (gdipGraphics != 0) {
22242232
OS.RestoreDC(hdc, state);
22252233
Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
22262234
}
22272235
return true;
22282236
}
22292237

2230-
void printWidget (long hwnd, long hdc, GC gc) {
2238+
void printWidget (long hwnd, long hdc, GC gc, int printWindowFlags) {
22312239
/*
22322240
* Bug in Windows. For some reason, PrintWindow()
22332241
* returns success but does nothing when it is called
@@ -2311,7 +2319,7 @@ void printWidget (long hwnd, long hdc, GC gc) {
23112319
if ((bits1 & OS.WS_VISIBLE) == 0) {
23122320
OS.ShowWindow (hwnd, OS.SW_SHOW);
23132321
}
2314-
success = OS.PrintWindow (hwnd, hdc, 0);
2322+
success = OS.PrintWindow (hwnd, hdc, printWindowFlags);
23152323
if ((bits1 & OS.WS_VISIBLE) == 0) {
23162324
OS.ShowWindow (hwnd, OS.SW_HIDE);
23172325
}

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)