Add stubs for SetWindowDisplayAffinity and GetWindowDisplayAffinity in user32 Accepted

Revisions: 

Revision 1

user image Michael Müller Author
13 Aug. 17

In my tests on Windows 7 SetWindowDisplayAffinity always failed with ERROR_NOT_ENOUGH_MEMORY when dwm compositing is disabled and calling DwmEnableComposition didn't make a difference. The tests succeeded only when I manually enabled the Aero design. I therefore guess that applications should work fine with the stubs. They are also consistent with the remaining code, which pretends that compositing is disabled. Starting with Windows 8, compositing can no longer be disabled though.

Single files Merged diff Tar archive
You have unsaved changes. Press CTRL + ENTER in a text field to submit your comments.

0001-user32-Add-stubs-for-GetWindowDisplayAffinity-and-Se.patch

From 3722c04e281c11e479911b6054710aa3b54a75c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sun, 13 Aug 2017 02:09:51 +0200
Subject: user32: Add stubs for GetWindowDisplayAffinity and
SetWindowDisplayAffinity.
---
dlls/user32/tests/win.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
dlls/user32/user32.spec | 2 ++
dlls/user32/win.c | 34 ++++++++++++++++++++
include/winuser.h | 5 +++
4 files changed, 126 insertions(+)
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 0fc262986b..5bd43672aa 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -67,6 +67,8 @@ static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
static DWORD (WINAPI *pGetLayout)(HDC hdc);
static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
+static BOOL (WINAPI *pGetWindowDisplayAffinity)(HWND hwnd, DWORD *affinity);
+static BOOL (WINAPI *pSetWindowDisplayAffinity)(HWND hwnd, DWORD affinity);
static BOOL test_lbuttondown_flag;
static DWORD num_gettext_msgs;
@@ -9950,6 +9952,86 @@ static void test_desktop( void )
}
}
+static void test_display_affinity( HWND win )
+{
+ DWORD affinity;
+ BOOL ret, dwm;
+ LONG styleex;
+
+ if (!pGetWindowDisplayAffinity || !pSetWindowDisplayAffinity)
+ {
+ win_skip("GetWindowDisplayAffinity or SetWindowDisplayAffinity missing\n");
+ return;
+ }
+
+ ret = pGetWindowDisplayAffinity(NULL, NULL);
+ ok(!ret, "GetWindowDisplayAffinity succeed\n");
+ ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "Expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
+
+ ret = pGetWindowDisplayAffinity(NULL, &affinity);
+ ok(!ret, "GetWindowDisplayAffinity succeed\n");
+ ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "Expected ERROR_INVALID_WINDOW_HANDLE, got %d\n", GetLastError());
+
+ ret = pGetWindowDisplayAffinity(win, NULL);
+ ok(!ret, "GetWindowDisplayAffinity succeed\n");
+ ok(GetLastError() == ERROR_NOACCESS, "Expected ERROR_NOACCESS, got %d\n", GetLastError());
+
+ styleex = GetWindowLongW(win, GWL_EXSTYLE);
+ SetWindowLongW(win, GWL_EXSTYLE, styleex & (~WS_EX_LAYERED));
+
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ /* Windows 7 fails with ERROR_NOT_ENOUGH_MEMORY when dwm compositing is disabled */
+ ret = pSetWindowDisplayAffinity(win, WDA_MONITOR);
+ ok(ret || GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
+ "SetWindowDisplayAffinity failed with %d\n", GetLastError());
+ dwm = ret;
+
+ affinity = 0xfff;
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ if (dwm) ok(affinity == WDA_MONITOR, "Expected WDA_MONITOR, got 0x%x\n", affinity);
+ else ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ ret = pSetWindowDisplayAffinity(win, WDA_NONE);
+ ok(ret || GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
+ "SetWindowDisplayAffinity failed with %d\n", GetLastError());
+
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ SetWindowLongW(win, GWL_EXSTYLE, styleex | WS_EX_LAYERED);
+
+ affinity = 0xfff;
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ ret = pSetWindowDisplayAffinity(win, WDA_MONITOR);
+ ok(ret || GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
+ "SetWindowDisplayAffinity failed with %d\n", GetLastError());
+
+ affinity = 0xfff;
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ if (dwm) ok(affinity == WDA_MONITOR, "Expected WDA_MONITOR, got 0x%x\n", affinity);
+ else ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ ret = pSetWindowDisplayAffinity(win, WDA_NONE);
+ ok(ret || GetLastError() == ERROR_NOT_ENOUGH_MEMORY,
+ "SetWindowDisplayAffinity failed with %d\n", GetLastError());
+
+ affinity = 0xfff;
+ ret = pGetWindowDisplayAffinity(win, &affinity);
+ ok(ret, "GetWindowDisplayAffinity failed with %d\n", GetLastError());
+ ok(affinity == WDA_NONE, "Expected WDA_NONE, got 0x%x\n", affinity);
+
+ SetWindowLongW(win, GWL_EXSTYLE, styleex);
+}
+
START_TEST(win)
{
char **argv;
@@ -9974,6 +10056,8 @@ START_TEST(win)
pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
+ pGetWindowDisplayAffinity = (void *)GetProcAddress( user32, "GetWindowDisplayAffinity" );
+ pSetWindowDisplayAffinity = (void *)GetProcAddress( user32, "SetWindowDisplayAffinity" );
if (argc==4 && !strcmp(argv[2], "create_children"))
{
@@ -10099,6 +10183,7 @@ START_TEST(win)
test_deferwindowpos();
test_LockWindowUpdate(hwndMain);
test_desktop();
+ test_display_affinity(hwndMain);
/* add the tests above this line */
if (hhook) UnhookWindowsHookEx(hhook);
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index 4514877264..65e6296f1f 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -385,6 +385,7 @@
@ stdcall GetWindow(long long)
@ stdcall GetWindowContextHelpId(long)
@ stdcall GetWindowDC(long)
+@ stdcall GetWindowDisplayAffinity(long ptr)
@ stdcall GetWindowInfo(long ptr)
@ stdcall GetWindowLongA(long long)
@ stdcall -arch=win64 GetWindowLongPtrA(long long)
@@ -688,6 +689,7 @@
@ stdcall SetUserObjectSecurity(long ptr ptr)
@ stdcall SetWinEventHook(long long long ptr long long long)
@ stdcall SetWindowContextHelpId(long long)
+@ stdcall SetWindowDisplayAffinity(long long)
@ stub SetWindowFullScreenState
@ stdcall SetWindowLongA(long long long)
@ stdcall -arch=win64 SetWindowLongPtrA(long long long)
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index ea116b9d13..a46d9a6930 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -3994,3 +3994,37 @@ BOOL WINAPI RegisterTouchWindow(HWND hwnd, ULONG flags)
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
+
+/*****************************************************************************
+ * GetWindowDisplayAffinity (USER32.@)
+ */
+BOOL WINAPI GetWindowDisplayAffinity(HWND hwnd, DWORD *affinity)
+{
+ FIXME("(%p, %p): stub\n", hwnd, affinity);
+
+ if (!hwnd || !affinity)
+ {
+ SetLastError(hwnd ? ERROR_NOACCESS : ERROR_INVALID_WINDOW_HANDLE);
+ return FALSE;
+ }
+
+ *affinity = WDA_NONE;
+ return TRUE;
+}
+
+/*****************************************************************************
+ * SetWindowDisplayAffinity (USER32.@)
+ */
+BOOL WINAPI SetWindowDisplayAffinity(HWND hwnd, DWORD affinity)
+{
+ FIXME("(%p, %u): stub\n", hwnd, affinity);
+
+ if (!hwnd)
+ {
+ SetLastError(ERROR_INVALID_WINDOW_HANDLE);
+ return FALSE;
+ }
+
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+}
diff --git a/include/winuser.h b/include/winuser.h
index 4be4fc33f8..8ce2c5bea1 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -2535,6 +2535,9 @@ typedef struct tagMINIMIZEDMETRICS {
int iArrange;
} MINIMIZEDMETRICS, *PMINIMIZEDMETRICS, *LPMINIMIZEDMETRICS;
+/* Window affinity */
+#define WDA_NONE 0x0
+#define WDA_MONITOR 0x1
/* Window scrolling */
#define SW_SCROLLCHILDREN 0x0001
@@ -3736,6 +3739,7 @@ WINUSERAPI BOOL WINAPI GetUserObjectSecurity(HANDLE,PSECURITY_INFORMATION
WINUSERAPI HWND WINAPI GetWindow(HWND,UINT);
WINUSERAPI DWORD WINAPI GetWindowContextHelpId(HWND);
WINUSERAPI HDC WINAPI GetWindowDC(HWND);
+WINUSERAPI BOOL WINAPI GetWindowDisplayAffinity(HWND,DWORD*);
WINUSERAPI BOOL WINAPI GetWindowInfo(HWND, PWINDOWINFO);
WINUSERAPI LONG WINAPI GetWindowLongA(HWND,INT);
WINUSERAPI LONG WINAPI GetWindowLongW(HWND,INT);
@@ -4038,6 +4042,7 @@ WINUSERAPI BOOL WINAPI SetUserObjectInformationW(HANDLE,INT,LPVOID,DWORD)
#define SetUserObjectInformation WINELIB_NAME_AW(SetUserObjectInformation)
WINUSERAPI BOOL WINAPI SetUserObjectSecurity(HANDLE,PSECURITY_INFORMATION,PSECURITY_DESCRIPTOR);
WINUSERAPI BOOL WINAPI SetWindowContextHelpId(HWND,DWORD);
+WINUSERAPI BOOL WINAPI SetWindowDisplayAffinity(HWND,DWORD);
WINUSERAPI LONG WINAPI SetWindowLongA(HWND,INT,LONG);
WINUSERAPI LONG WINAPI SetWindowLongW(HWND,INT,LONG);
#define SetWindowLong WINELIB_NAME_AW(SetWindowLong)
--
2.13.2