[PATCH] user32: Create compatible caret bitmap in case of user bitmap too

Nikolay Sivov nsivov at codeweavers.com
Mon May 2 01:01:45 CDT 2016


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---

Fixes https://bugs.winehq.org/show_bug.cgi?id=40554

 dlls/user32/caret.c | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/dlls/user32/caret.c b/dlls/user32/caret.c
index 686dade..892dc20 100644
--- a/dlls/user32/caret.c
+++ b/dlls/user32/caret.c
@@ -114,10 +114,12 @@ BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap, INT width, INT height )
     int hidden = 0;
     HBITMAP hBmp = 0;
     HWND prev = 0;
+    HDC hdc;
 
-    TRACE("hwnd=%p\n", hwnd);
+    TRACE("hwnd=%p, bmp %p, width %d, height %d\n", hwnd, bitmap, width, height);
 
-    if (!hwnd) return FALSE;
+    if (!hwnd || !(hdc = GetDC(hwnd)))
+        return FALSE;
 
     if (bitmap && (bitmap != (HBITMAP)1))
     {
@@ -126,7 +128,7 @@ BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap, INT width, INT height )
         width = bmp.bmWidth;
         height = bmp.bmHeight;
 	bmp.bmBits = NULL;
-	hBmp = CreateBitmapIndirect(&bmp);
+        hBmp = CreateCompatibleBitmap(hdc, width, height);
 	if (hBmp)
 	{
 	    /* copy the bitmap */
@@ -138,30 +140,26 @@ BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap, INT width, INT height )
     }
     else
     {
-	HDC hdc;
+        HDC hMemDC;
 
         if (!width) width = GetSystemMetrics(SM_CXBORDER);
         if (!height) height = GetSystemMetrics(SM_CYBORDER);
 
 	/* create the uniform bitmap on the fly */
-	hdc = GetDC(hwnd);
-	if (hdc)
-	{
-	    HDC hMemDC = CreateCompatibleDC(hdc);
-	    if (hMemDC)
-	    {
-		if ((hBmp = CreateCompatibleBitmap(hMemDC, width, height )))
-		{
-		    HBITMAP hPrevBmp = SelectObject(hMemDC, hBmp);
-                    SetRect( &r, 0, 0, width, height );
-		    FillRect(hMemDC, &r, bitmap ? GetStockObject(GRAY_BRUSH) : GetStockObject(WHITE_BRUSH));
-		    SelectObject(hMemDC, hPrevBmp);
-		}
-		DeleteDC(hMemDC);
-	    }
-	    ReleaseDC(hwnd, hdc);
-	}
+        hMemDC = CreateCompatibleDC(hdc);
+        if (hMemDC)
+        {
+            if ((hBmp = CreateCompatibleBitmap(hMemDC, width, height )))
+            {
+                HBITMAP hPrevBmp = SelectObject(hMemDC, hBmp);
+                SetRect( &r, 0, 0, width, height );
+                FillRect(hMemDC, &r, bitmap ? GetStockObject(GRAY_BRUSH) : GetStockObject(WHITE_BRUSH));
+                SelectObject(hMemDC, hPrevBmp);
+            }
+            DeleteDC(hMemDC);
+        }
     }
+    ReleaseDC(hwnd, hdc);
     if (!hBmp) return FALSE;
 
     SERVER_START_REQ( set_caret_window )
-- 
2.8.1




More information about the wine-patches mailing list