From 0cf7978c58a301ac461d83776e7e235cbcbfd90c Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Thu, 15 Jan 2004 22:33:30 +0000 Subject: [PATCH] Draw window icons into the title bar. However SendMessageTimeout() needs to be implemented to get it working properly (and also DrawIconEx() has to be extended to use StretchBlt() in order to get drawing big icons poperly. svn path=/trunk/; revision=7668 --- reactos/include/defines.h | 5 ++ reactos/lib/user32/windows/nonclient.c | 67 +++++++++++++------------- 2 files changed, 39 insertions(+), 33 deletions(-) diff --git a/reactos/include/defines.h b/reactos/include/defines.h index 9f91a9f960a..d5e4347245a 100644 --- a/reactos/include/defines.h +++ b/reactos/include/defines.h @@ -973,6 +973,11 @@ extern "C" { #define DFCS_MONO (32768) #define DFCS_PUSHED (512) +/* DrawIcon */ +#define ICON_SMALL (0) +#define ICON_BIG (1) +#define ICON_SMALL2 (2) + /* DrawIconEx */ #define DI_COMPAT (4) #define DI_DEFAULTSIZE (8) diff --git a/reactos/lib/user32/windows/nonclient.c b/reactos/lib/user32/windows/nonclient.c index 57f6ecc8284..4cdea6d515a 100644 --- a/reactos/lib/user32/windows/nonclient.c +++ b/reactos/lib/user32/windows/nonclient.c @@ -119,39 +119,40 @@ UserHasMenu(HWND hWnd, ULONG Style) return (!(Style & WS_CHILD) && GetMenu(hWnd) != 0); } -BOOL -UserDrawSysMenuButton(HWND hWnd, HDC hDC, LPRECT Rect, BOOL down) +HICON +UserGetWindowIcon(HWND hwnd) { - HDC hDcMem; - HBITMAP hSavedBitmap; - static HBITMAP hbSysMenu = NULL; + HICON Ret = 0; + + SendMessageTimeoutW(hwnd, WM_GETICON, ICON_SMALL2, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&Ret); + if (!Ret) + SendMessageTimeoutW(hwnd, WM_GETICON, ICON_SMALL, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&Ret); + if (!Ret) + SendMessageTimeoutW(hwnd, WM_GETICON, ICON_BIG, 0, SMTO_ABORTIFHUNG, 1000, (LPDWORD)&Ret); + if (!Ret) + Ret = (HICON)GetClassLongW(hwnd, GCL_HICONSM); + if (!Ret) + Ret = (HICON)GetClassLongW(hwnd, GCL_HICON); + if (!Ret) + SendMessageTimeoutW(hwnd, WM_QUERYDRAGICON, 0, 0, 0, 1000, (LPDWORD)&Ret); + if (!Ret) + Ret = LoadIconW(0, IDI_APPLICATION); + + return Ret; +} - if (hbSysMenu == NULL) - { - hbSysMenu = (HBITMAP)LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE)); - } - - hDcMem = CreateCompatibleDC(hDC); - if (!hDcMem) - { - return FALSE; - } - - hSavedBitmap = SelectObject(hDcMem, hbSysMenu); - if (!hSavedBitmap) - { - DeleteDC(hDcMem); - return FALSE; - } - - BitBlt(hDC, Rect->left + 2, Rect->top + 3, 16, 14, hDcMem, - (GetWindowLongW(hWnd, GWL_STYLE) & WS_CHILD) ? - GetSystemMetrics(SM_CXSIZE): 0, 0, SRCCOPY); - - SelectObject(hDcMem, hSavedBitmap); - DeleteDC(hDcMem); - - return TRUE; +BOOL +UserDrawSysMenuButton(HWND hWnd, HDC hDC, LPRECT Rect) +{ + HICON WindowIcon; + + if((WindowIcon = UserGetWindowIcon(hWnd))) + { + return DrawIconEx(hDC, Rect->left + 2, Rect->top + 2, WindowIcon, + GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), + 0, NULL, DI_NORMAL); + } + return FALSE; } /* @@ -1100,7 +1101,7 @@ DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags) PatBlt(MemDC, 0, 0, xx, lprc->bottom - lprc->top, PATCOPY); // For some reason the icon isn't centered correctly... r.top --; - UserDrawSysMenuButton(hWnd, MemDC, &r, FALSE); + UserDrawSysMenuButton(hWnd, MemDC, &r); r.top ++; r.left += xx; } @@ -1164,7 +1165,7 @@ DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags) { // For some reason the icon isn't centered correctly... r.top --; - UserDrawSysMenuButton(hWnd, MemDC, &r, FALSE); + UserDrawSysMenuButton(hWnd, MemDC, &r); r.top ++; } r.top ++;