Dmitry Timoshkov : user32: UpdateLayeredWindow() should fail on non-layered or already initialized window.

Alexandre Julliard julliard at winehq.org
Tue Sep 21 13:59:31 CDT 2010


Module: wine
Branch: master
Commit: a7188842afe7cb35b15980a3ffd1c8fa5aa23391
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a7188842afe7cb35b15980a3ffd1c8fa5aa23391

Author: Dmitry Timoshkov <dmitry at codeweavers.com>
Date:   Tue Sep 21 16:35:30 2010 +0900

user32: UpdateLayeredWindow() should fail on non-layered or already initialized window.

---

 dlls/user32/tests/win.c |   36 +++++++++++++++++++++++++++++++++++-
 dlls/user32/win.c       |    7 +++++++
 2 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 190ca79..1434bc8 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -49,6 +49,7 @@ static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
 static UINT (WINAPI *pGetWindowModuleFileNameA)(HWND,LPSTR,UINT);
 static BOOL (WINAPI *pGetLayeredWindowAttributes)(HWND,COLORREF*,BYTE*,DWORD*);
 static BOOL (WINAPI *pSetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD);
+static BOOL (WINAPI *pUpdateLayeredWindow)(HWND,HDC,POINT*,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
 static BOOL (WINAPI *pGetMonitorInfoA)(HMONITOR,LPMONITORINFO);
 static HMONITOR (WINAPI *pMonitorFromPoint)(POINT,DWORD);
 static int  (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
@@ -5568,16 +5569,29 @@ static void test_layered_window(void)
     COLORREF key = 0;
     BYTE alpha = 0;
     DWORD flags = 0;
+    POINT pt = { 0, 0 };
+    SIZE sz = { 200, 200 };
+    HDC hdc;
+    HBITMAP hbm;
     BOOL ret;
 
-    if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes)
+    if (!pGetLayeredWindowAttributes || !pSetLayeredWindowAttributes || !pUpdateLayeredWindow)
     {
         win_skip( "layered windows not supported\n" );
         return;
     }
+
+    hdc = CreateCompatibleDC( 0 );
+    hbm = CreateCompatibleBitmap( hdc, 200, 200 );
+    SelectObject( hdc, hbm );
+
     hwnd = CreateWindowExA(0, "MainWindowClass", "message window", WS_CAPTION,
                            100, 100, 200, 200, 0, 0, 0, NULL);
     assert( hwnd );
+    SetLastError( 0xdeadbeef );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
     ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
@@ -5585,6 +5599,10 @@ static void test_layered_window(void)
     SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
+    ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
+    ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
     ret = pSetLayeredWindowAttributes( hwnd, 0x123456, 44, LWA_ALPHA );
     ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
@@ -5592,14 +5610,23 @@ static void test_layered_window(void)
     ok( key == 0x123456 || key == 0, "wrong color key %x\n", key );
     ok( alpha == 44, "wrong alpha %u\n", alpha );
     ok( flags == LWA_ALPHA, "wrong flags %x\n", flags );
+    SetLastError( 0xdeadbeef );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
 
     /* clearing WS_EX_LAYERED resets attributes */
     SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
+    SetLastError( 0xdeadbeef );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
     SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( ret, "UpdateLayeredWindow should succeed on layered window\n" );
     ret = pSetLayeredWindowAttributes( hwnd, 0x654321, 22, LWA_COLORKEY | LWA_ALPHA );
     ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
@@ -5607,6 +5634,10 @@ static void test_layered_window(void)
     ok( key == 0x654321, "wrong color key %x\n", key );
     ok( alpha == 22, "wrong alpha %u\n", alpha );
     ok( flags == (LWA_COLORKEY | LWA_ALPHA), "wrong flags %x\n", flags );
+    SetLastError( 0xdeadbeef );
+    ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
+    ok( !ret, "UpdateLayeredWindow should fail on layered but initialized window\n" );
+    ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
 
     ret = pSetLayeredWindowAttributes( hwnd, 0x888888, 33, LWA_COLORKEY );
     ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
@@ -5640,6 +5671,8 @@ static void test_layered_window(void)
     ok( flags == 0, "wrong flags %x\n", flags );
 
     DestroyWindow( hwnd );
+    DeleteDC( hdc );
+    DeleteObject( hbm );
 }
 
 static MONITORINFO mi;
@@ -6140,6 +6173,7 @@ START_TEST(win)
     pGetWindowModuleFileNameA = (void *)GetProcAddress( user32, "GetWindowModuleFileNameA" );
     pGetLayeredWindowAttributes = (void *)GetProcAddress( user32, "GetLayeredWindowAttributes" );
     pSetLayeredWindowAttributes = (void *)GetProcAddress( user32, "SetLayeredWindowAttributes" );
+    pUpdateLayeredWindow = (void *)GetProcAddress( user32, "UpdateLayeredWindow" );
     pGetMonitorInfoA = (void *)GetProcAddress( user32,  "GetMonitorInfoA" );
     pMonitorFromPoint = (void *)GetProcAddress( user32,  "MonitorFromPoint" );
     pGetWindowRgnBox = (void *)GetProcAddress( user32, "GetWindowRgnBox" );
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 63f6689..d691676 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -3434,6 +3434,13 @@ BOOL WINAPI UpdateLayeredWindowIndirect( HWND hwnd, const UPDATELAYEREDWINDOWINF
 {
     BYTE alpha = 0xff;
 
+    if (!(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_LAYERED) ||
+        GetLayeredWindowAttributes( hwnd, NULL, NULL, NULL ))
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return FALSE;
+    }
+
     if (!(info->dwFlags & ULW_EX_NORESIZE) && (info->pptDst || info->psize))
     {
         int x = 0, y = 0, cx = 0, cy = 0;




More information about the wine-cvs mailing list