2 * Common controls functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1998,2000 Eric Kohl
6 * Copyright 2014-2015 Michael Müller
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * This code was audited for completeness against the documented features
25 * of Comctl32.dll version 6.0 on Oct. 21, 2002, by Christian Neumair.
27 * Unless otherwise noted, we believe this code to be complete, as per
28 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
32 * -- implement GetMUILanguage + InitMUILanguage
33 * -- finish NOTES for MenuHelp, GetEffectiveClientRect and GetStatusTextW
34 * -- FIXMEs + BUGS (search for them)
37 * -- ICC_ANIMATE_CLASS
42 * -- ICC_INTERNET_CLASSES
44 * -- ICC_LISTVIEW_CLASSES
45 * -- ICC_NATIVEFNTCTL_CLASS
46 * -- ICC_PAGESCROLLER_CLASS
47 * -- ICC_PROGRESS_CLASS
48 * -- ICC_STANDARD_CLASSES (not yet implemented)
50 * -- ICC_TREEVIEW_CLASSES
52 * -- ICC_USEREX_CLASSES
53 * -- ICC_WIN95_CLASSES
68 #define NO_SHLWAPI_STREAM
71 #include "wine/debug.h"
73 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
76 static LRESULT WINAPI
COMCTL32_SubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
78 static LPWSTR COMCTL32_wSubclass
= NULL
;
79 HMODULE COMCTL32_hModule
= 0;
80 static LANGID COMCTL32_uiLang
= MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
81 HBRUSH COMCTL32_hPattern55AABrush
= NULL
;
82 COMCTL32_SysColor comctl32_color
;
84 static HBITMAP COMCTL32_hPattern55AABitmap
= NULL
;
86 static const WORD wPattern55AA
[] =
88 0x5555, 0xaaaa, 0x5555, 0xaaaa,
89 0x5555, 0xaaaa, 0x5555, 0xaaaa
92 static const WCHAR strCC32SubclassInfo
[] = {
93 'C','C','3','2','S','u','b','c','l','a','s','s','I','n','f','o',0
100 #define NAME L"microsoft.windows.common-controls"
101 #define VERSION_V5 L"5.82.2600.2982"
102 #define VERSION L"6.0.2600.2982"
103 #define PUBLIC_KEY L"6595b64144ccf1df"
107 #elif defined __x86_64__
108 #define ARCH L"amd64"
113 static const WCHAR manifest_filename
[] = ARCH L
"_" NAME L
"_" PUBLIC_KEY L
"_" VERSION L
"_none_deadbeef.manifest";
114 static const WCHAR manifest_filename_v5
[] = ARCH L
"_" NAME L
"_" PUBLIC_KEY L
"_" VERSION_V5 L
"_none_deadbeef.manifest";
116 static WCHAR
* GetManifestPath(BOOL create
, BOOL bV6
)
121 pwszBuf
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
125 GetWindowsDirectoryW(pwszBuf
, MAX_PATH
);
126 hres
= StringCchCatW(pwszBuf
, MAX_PATH
, L
"\\winsxs");
130 CreateDirectoryW(pwszBuf
, NULL
);
131 hres
= StringCchCatW(pwszBuf
, MAX_PATH
, L
"\\manifests\\");
135 CreateDirectoryW(pwszBuf
, NULL
);
137 hres
= StringCchCatW(pwszBuf
, MAX_PATH
, bV6
? manifest_filename
: manifest_filename_v5
);
144 static HANDLE
CreateComctl32ActCtx(BOOL bV6
)
148 ACTCTXW ActCtx
= {sizeof(ACTCTX
)};
150 pwstrSource
= GetManifestPath(FALSE
, bV6
);
153 ERR("GetManifestPath failed! bV6=%d\n", bV6
);
154 return INVALID_HANDLE_VALUE
;
156 ActCtx
.lpSource
= pwstrSource
;
157 ret
= CreateActCtxW(&ActCtx
);
158 HeapFree(GetProcessHeap(), 0, pwstrSource
);
159 if (ret
== INVALID_HANDLE_VALUE
)
160 ERR("CreateActCtxW failed! bV6=%d\n", bV6
);
164 static void RegisterControls(BOOL bV6
)
168 DATETIME_Register ();
172 IPADDRESS_Register ();
173 LISTVIEW_Register ();
174 MONTHCAL_Register ();
175 NATIVEFONT_Register ();
177 PROGRESS_Register ();
182 TOOLTIPS_Register ();
183 TRACKBAR_Register ();
184 TREEVIEW_Register ();
195 COMBOLBOX_Register ();
200 TOOLBARv6_Register();
204 static void UnregisterControls(BOOL bV6
)
206 ANIMATE_Unregister ();
207 COMBOEX_Unregister ();
208 DATETIME_Unregister ();
209 FLATSB_Unregister ();
210 HEADER_Unregister ();
211 HOTKEY_Unregister ();
212 IPADDRESS_Unregister ();
213 LISTVIEW_Unregister ();
214 MONTHCAL_Unregister ();
215 NATIVEFONT_Unregister ();
217 PROGRESS_Unregister ();
219 STATUS_Unregister ();
220 SYSLINK_Unregister ();
222 TOOLTIPS_Unregister ();
223 TRACKBAR_Unregister ();
224 TREEVIEW_Unregister ();
225 UPDOWN_Unregister ();
229 TOOLBAR_Unregister ();
235 COMBOLBOX_Unregister ();
237 LISTBOX_Unregister ();
238 STATIC_Unregister ();
240 TOOLBARv6_Unregister ();
245 static void InitializeClasses()
247 HANDLE hActCtx5
, hActCtx6
;
251 /* like comctl32 5.82+ register all the common control classes */
252 /* Register the classes once no matter what */
253 hActCtx5
= CreateComctl32ActCtx(FALSE
);
254 activated
= (hActCtx5
!= INVALID_HANDLE_VALUE
? ActivateActCtx(hActCtx5
, &ulCookie
) : FALSE
);
255 RegisterControls(FALSE
); /* Register the classes pretending to be v5 */
256 if (activated
) DeactivateActCtx(0, ulCookie
);
258 hActCtx6
= CreateComctl32ActCtx(TRUE
);
259 if (hActCtx6
!= INVALID_HANDLE_VALUE
)
261 activated
= ActivateActCtx(hActCtx6
, &ulCookie
);
262 RegisterControls(TRUE
); /* Register the classes pretending to be v6 */
263 if (activated
) DeactivateActCtx(0, ulCookie
);
265 /* Initialize the themed controls only when the v6 manifest is present */
266 THEMING_Initialize (hActCtx5
, hActCtx6
);
270 static void UninitializeClasses()
272 HANDLE hActCtx5
, hActCtx6
;
276 hActCtx5
= CreateComctl32ActCtx(FALSE
);
277 activated
= (hActCtx5
!= INVALID_HANDLE_VALUE
? ActivateActCtx(hActCtx5
, &ulCookie
) : FALSE
);
278 UnregisterControls(FALSE
);
279 if (activated
) DeactivateActCtx(0, ulCookie
);
281 hActCtx6
= CreateComctl32ActCtx(TRUE
);
282 if (hActCtx6
!= INVALID_HANDLE_VALUE
)
284 activated
= ActivateActCtx(hActCtx6
, &ulCookie
);
285 THEMING_Uninitialize();
286 UnregisterControls(TRUE
);
287 if (activated
) DeactivateActCtx(0, ulCookie
);
291 /***********************************************************************
292 * RegisterClassNameW [COMCTL32.@]
294 * Register window class again while using as SxS module.
296 BOOLEAN WINAPI
RegisterClassNameW(LPCWSTR className
)
302 #endif /* __REACTOS__ */
305 static void unregister_versioned_classes(void)
307 #define VERSION "6.0.2600.2982!"
308 static const char *classes
[] =
311 VERSION WC_COMBOBOXA
,
319 for (i
= 0; i
< ARRAY_SIZE(classes
); i
++)
320 UnregisterClassA(classes
[i
], NULL
);
326 /***********************************************************************
329 * Initializes the internal 'COMCTL32.DLL'.
332 * hinstDLL [I] handle to the 'dlls' instance
334 * lpvReserved [I] reserved, must be NULL
341 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
343 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
346 case DLL_PROCESS_ATTACH
:
347 DisableThreadLibraryCalls(hinstDLL
);
349 COMCTL32_hModule
= hinstDLL
;
351 /* add global subclassing atom (used by 'tooltip' and 'updown') */
352 COMCTL32_wSubclass
= (LPWSTR
)(DWORD_PTR
)GlobalAddAtomW (strCC32SubclassInfo
);
353 TRACE("Subclassing atom added: %p\n", COMCTL32_wSubclass
);
355 /* create local pattern brush */
356 COMCTL32_hPattern55AABitmap
= CreateBitmap (8, 8, 1, 1, wPattern55AA
);
357 COMCTL32_hPattern55AABrush
= CreatePatternBrush (COMCTL32_hPattern55AABitmap
);
359 /* Get all the colors at DLL load */
360 COMCTL32_RefreshSysColors();
363 /* like comctl32 5.82+ register all the common control classes */
366 DATETIME_Register ();
370 IPADDRESS_Register ();
371 LISTVIEW_Register ();
372 MONTHCAL_Register ();
373 NATIVEFONT_Register ();
375 PROGRESS_Register ();
381 TOOLTIPS_Register ();
382 TRACKBAR_Register ();
383 TREEVIEW_Register ();
388 COMBOLBOX_Register ();
393 /* subclass user32 controls */
394 THEMING_Initialize ();
401 case DLL_PROCESS_DETACH
:
402 if (lpvReserved
) break;
404 /* clean up subclassing */
405 THEMING_Uninitialize();
407 /* unregister all common control classes */
408 ANIMATE_Unregister ();
409 COMBOEX_Unregister ();
410 DATETIME_Unregister ();
411 FLATSB_Unregister ();
412 HEADER_Unregister ();
413 HOTKEY_Unregister ();
414 IPADDRESS_Unregister ();
415 LISTVIEW_Unregister ();
416 MONTHCAL_Unregister ();
417 NATIVEFONT_Unregister ();
419 PROGRESS_Unregister ();
421 STATUS_Unregister ();
422 SYSLINK_Unregister ();
424 TOOLBAR_Unregister ();
425 TOOLTIPS_Unregister ();
426 TRACKBAR_Unregister ();
427 TREEVIEW_Unregister ();
428 UPDOWN_Unregister ();
430 unregister_versioned_classes ();
433 UninitializeClasses();
435 /* delete local pattern brush */
436 DeleteObject (COMCTL32_hPattern55AABrush
);
437 DeleteObject (COMCTL32_hPattern55AABitmap
);
439 /* delete global subclassing atom */
440 GlobalDeleteAtom (LOWORD(COMCTL32_wSubclass
));
441 TRACE("Subclassing atom deleted: %p\n", COMCTL32_wSubclass
);
449 /***********************************************************************
450 * MenuHelp [COMCTL32.2]
452 * Handles the setting of status bar help messages when the user
453 * selects menu items.
456 * uMsg [I] message (WM_MENUSELECT) (see NOTES)
457 * wParam [I] wParam of the message uMsg
458 * lParam [I] lParam of the message uMsg
459 * hMainMenu [I] handle to the application's main menu
460 * hInst [I] handle to the module that contains string resources
461 * hwndStatus [I] handle to the status bar window
462 * lpwIDs [I] pointer to an array of integers (see NOTES)
468 * The official documentation is incomplete!
469 * This is the correct documentation:
472 * MenuHelp() does NOT handle WM_COMMAND messages! It only handles
473 * WM_MENUSELECT messages.
476 * (will be written ...)
480 MenuHelp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, HMENU hMainMenu
,
481 HINSTANCE hInst
, HWND hwndStatus
, UINT
* lpwIDs
)
485 if (!IsWindow (hwndStatus
))
490 TRACE("WM_MENUSELECT wParam=0x%lX lParam=0x%lX\n",
493 if ((HIWORD(wParam
) == 0xFFFF) && (lParam
== 0)) {
494 /* menu was closed */
495 TRACE("menu was closed!\n");
496 SendMessageW (hwndStatus
, SB_SIMPLE
, FALSE
, 0);
499 /* menu item was selected */
500 if (HIWORD(wParam
) & MF_POPUP
)
501 uMenuID
= *(lpwIDs
+1);
503 uMenuID
= (UINT
)LOWORD(wParam
);
504 TRACE("uMenuID = %u\n", uMenuID
);
509 if (!LoadStringW (hInst
, uMenuID
, szText
, ARRAY_SIZE(szText
)))
512 SendMessageW (hwndStatus
, SB_SETTEXTW
,
513 255 | SBT_NOBORDERS
, (LPARAM
)szText
);
514 SendMessageW (hwndStatus
, SB_SIMPLE
, TRUE
, 0);
520 TRACE("WM_COMMAND wParam=0x%lX lParam=0x%lX\n",
522 /* WM_COMMAND is not invalid since it is documented
523 * in the windows api reference. So don't output
524 * any FIXME for WM_COMMAND
526 WARN("We don't care about the WM_COMMAND\n");
530 FIXME("Invalid Message 0x%x!\n", uMsg
);
536 /***********************************************************************
537 * ShowHideMenuCtl [COMCTL32.3]
539 * Shows or hides controls and updates the corresponding menu item.
542 * hwnd [I] handle to the client window.
543 * uFlags [I] menu command id.
544 * lpInfo [I] pointer to an array of integers. (See NOTES.)
551 * The official documentation is incomplete!
552 * This is the correct documentation:
555 * Handle to the window that contains the menu and controls.
558 * Identifier of the menu item to receive or lose a check mark.
561 * The array of integers contains pairs of values. BOTH values of
562 * the first pair must be the handles to the application's main menu.
563 * Each subsequent pair consists of a menu id and control id.
567 ShowHideMenuCtl (HWND hwnd
, UINT_PTR uFlags
, LPINT lpInfo
)
571 TRACE("%p, %lx, %p\n", hwnd
, uFlags
, lpInfo
);
576 if (!(lpInfo
[0]) || !(lpInfo
[1]))
579 /* search for control */
580 lpMenuId
= &lpInfo
[2];
581 while (*lpMenuId
!= uFlags
)
584 if (GetMenuState ((HMENU
)(DWORD_PTR
)lpInfo
[1], uFlags
, MF_BYCOMMAND
) & MFS_CHECKED
) {
585 /* uncheck menu item */
586 CheckMenuItem ((HMENU
)(DWORD_PTR
)lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_UNCHECKED
);
590 SetWindowPos (GetDlgItem (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
594 /* check menu item */
595 CheckMenuItem ((HMENU
)(DWORD_PTR
)lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_CHECKED
);
599 SetWindowPos (GetDlgItem (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
607 /***********************************************************************
608 * GetEffectiveClientRect [COMCTL32.4]
610 * Calculates the coordinates of a rectangle in the client area.
613 * hwnd [I] handle to the client window.
614 * lpRect [O] pointer to the rectangle of the client window
615 * lpInfo [I] pointer to an array of integers (see NOTES)
621 * The official documentation is incomplete!
622 * This is the correct documentation:
625 * (will be written ...)
629 GetEffectiveClientRect (HWND hwnd
, LPRECT lpRect
, const INT
*lpInfo
)
635 TRACE("(%p %p %p)\n",
636 hwnd
, lpRect
, lpInfo
);
638 GetClientRect (hwnd
, lpRect
);
646 hwndCtrl
= GetDlgItem (hwnd
, *lpRun
);
647 if (GetWindowLongW (hwndCtrl
, GWL_STYLE
) & WS_VISIBLE
) {
648 TRACE("control id 0x%x\n", *lpRun
);
649 GetWindowRect (hwndCtrl
, &rcCtrl
);
650 MapWindowPoints (NULL
, hwnd
, (LPPOINT
)&rcCtrl
, 2);
651 SubtractRect (lpRect
, lpRect
, &rcCtrl
);
658 /***********************************************************************
659 * DrawStatusTextW [COMCTL32.@]
661 * Draws text with borders, like in a status bar.
664 * hdc [I] handle to the window's display context
665 * lprc [I] pointer to a rectangle
666 * text [I] pointer to the text
667 * style [I] drawing style
673 * The style variable can have one of the following values:
674 * (will be written ...)
677 void WINAPI
DrawStatusTextW (HDC hdc
, LPCRECT lprc
, LPCWSTR text
, UINT style
)
680 UINT border
= BDR_SUNKENOUTER
;
682 if (style
& SBT_POPOUT
)
683 border
= BDR_RAISEDOUTER
;
684 else if (style
& SBT_NOBORDERS
)
687 DrawEdge (hdc
, &r
, border
, BF_RECT
|BF_ADJUST
);
691 int oldbkmode
= SetBkMode (hdc
, TRANSPARENT
);
692 UINT align
= DT_LEFT
;
695 if (style
& SBT_RTLREADING
)
696 FIXME("Unsupported RTL style!\n");
701 DrawTextW (hdc
, text
- strCnt
, strCnt
, &r
, align
|DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
);
704 if (align
==DT_RIGHT
) {
707 align
= (align
==DT_LEFT
? DT_CENTER
: DT_RIGHT
);
713 if (strCnt
) DrawTextW (hdc
, text
- strCnt
, -1, &r
, align
|DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
);
714 SetBkMode(hdc
, oldbkmode
);
719 /***********************************************************************
720 * DrawStatusText [COMCTL32.@]
721 * DrawStatusTextA [COMCTL32.5]
723 * Draws text with borders, like in a status bar.
726 * hdc [I] handle to the window's display context
727 * lprc [I] pointer to a rectangle
728 * text [I] pointer to the text
729 * style [I] drawing style
735 void WINAPI
DrawStatusTextA (HDC hdc
, LPCRECT lprc
, LPCSTR text
, UINT style
)
741 if ( (len
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 )) ) {
742 if ( (textW
= Alloc( len
* sizeof(WCHAR
) )) )
743 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, len
);
746 DrawStatusTextW( hdc
, lprc
, textW
, style
);
751 /***********************************************************************
752 * CreateStatusWindow [COMCTL32.@]
753 * CreateStatusWindowA [COMCTL32.6]
755 * Creates a status bar
758 * style [I] window style
759 * text [I] pointer to the window text
760 * parent [I] handle to the parent window
761 * wid [I] control id of the status bar
764 * Success: handle to the status window
769 CreateStatusWindowA (LONG style
, LPCSTR text
, HWND parent
, UINT wid
)
771 return CreateWindowA(STATUSCLASSNAMEA
, text
, style
,
772 CW_USEDEFAULT
, CW_USEDEFAULT
,
773 CW_USEDEFAULT
, CW_USEDEFAULT
,
774 parent
, (HMENU
)(DWORD_PTR
)wid
, 0, 0);
778 /***********************************************************************
779 * CreateStatusWindowW [COMCTL32.@]
781 * Creates a status bar control
784 * style [I] window style
785 * text [I] pointer to the window text
786 * parent [I] handle to the parent window
787 * wid [I] control id of the status bar
790 * Success: handle to the status window
795 CreateStatusWindowW (LONG style
, LPCWSTR text
, HWND parent
, UINT wid
)
797 return CreateWindowW(STATUSCLASSNAMEW
, text
, style
,
798 CW_USEDEFAULT
, CW_USEDEFAULT
,
799 CW_USEDEFAULT
, CW_USEDEFAULT
,
800 parent
, (HMENU
)(DWORD_PTR
)wid
, 0, 0);
804 /***********************************************************************
805 * CreateUpDownControl [COMCTL32.16]
807 * Creates an up-down control
810 * style [I] window styles
811 * x [I] horizontal position of the control
812 * y [I] vertical position of the control
813 * cx [I] with of the control
814 * cy [I] height of the control
815 * parent [I] handle to the parent window
816 * id [I] the control's identifier
817 * inst [I] handle to the application's module instance
818 * buddy [I] handle to the buddy window, can be NULL
819 * maxVal [I] upper limit of the control
820 * minVal [I] lower limit of the control
821 * curVal [I] current value of the control
824 * Success: handle to the updown control
829 CreateUpDownControl (DWORD style
, INT x
, INT y
, INT cx
, INT cy
,
830 HWND parent
, INT id
, HINSTANCE inst
,
831 HWND buddy
, INT maxVal
, INT minVal
, INT curVal
)
834 CreateWindowW (UPDOWN_CLASSW
, 0, style
, x
, y
, cx
, cy
,
835 parent
, (HMENU
)(DWORD_PTR
)id
, inst
, 0);
837 SendMessageW (hUD
, UDM_SETBUDDY
, (WPARAM
)buddy
, 0);
838 SendMessageW (hUD
, UDM_SETRANGE
, 0, MAKELONG(maxVal
, minVal
));
839 SendMessageW (hUD
, UDM_SETPOS
, 0, MAKELONG(curVal
, 0));
846 /***********************************************************************
847 * InitCommonControls [COMCTL32.17]
849 * Registers the common controls.
858 * This function is just a dummy - all the controls are registered at
859 * the DLL initialization time. See InitCommonContolsEx for details.
863 InitCommonControls (void)
868 /***********************************************************************
869 * InitCommonControlsEx [COMCTL32.@]
871 * Registers the common controls.
874 * lpInitCtrls [I] pointer to an INITCOMMONCONTROLS structure.
881 * Probably all versions of comctl32 initializes the Win95 controls in DllMain
882 * during DLL initialization. Starting from comctl32 v5.82 all the controls
883 * are initialized there. We follow this behaviour and this function is just
886 * Note: when writing programs under Windows, if you don't call any function
887 * from comctl32 the linker may not link this DLL. If InitCommonControlsEx
888 * was the only comctl32 function you were calling and you remove it you may
889 * have a false impression that InitCommonControlsEx actually did something.
893 InitCommonControlsEx (const INITCOMMONCONTROLSEX
*lpInitCtrls
)
895 if (!lpInitCtrls
|| lpInitCtrls
->dwSize
!= sizeof(INITCOMMONCONTROLSEX
))
898 TRACE("(0x%08x)\n", lpInitCtrls
->dwICC
);
903 /***********************************************************************
904 * CreateToolbarEx [COMCTL32.@]
906 * Creates a toolbar window.
924 * Success: handle to the tool bar control
929 CreateToolbarEx (HWND hwnd
, DWORD style
, UINT wID
, INT nBitmaps
,
930 HINSTANCE hBMInst
, UINT_PTR wBMID
, LPCTBBUTTON lpButtons
,
931 INT iNumButtons
, INT dxButton
, INT dyButton
,
932 INT dxBitmap
, INT dyBitmap
, UINT uStructSize
)
937 CreateWindowExW(0, TOOLBARCLASSNAMEW
, NULL
, style
|WS_CHILD
, 0,0,100,30,
938 hwnd
, (HMENU
)(DWORD_PTR
)wID
, COMCTL32_hModule
, NULL
);
942 SendMessageW (hwndTB
, TB_BUTTONSTRUCTSIZE
, uStructSize
, 0);
944 /* set bitmap and button size */
945 /*If CreateToolbarEx receives 0, windows sets default values*/
950 if (dxBitmap
== 0 || dyBitmap
== 0)
951 dxBitmap
= dyBitmap
= 16;
952 SendMessageW(hwndTB
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(dxBitmap
, dyBitmap
));
958 /* TB_SETBUTTONSIZE -> TB_SETBITMAPSIZE bug introduced for Windows compatibility */
959 if (dxButton
!= 0 && dyButton
!= 0)
960 SendMessageW(hwndTB
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(dxButton
, dyButton
));
964 if (nBitmaps
> 0 || hBMInst
== HINST_COMMCTRL
)
966 tbab
.hInst
= hBMInst
;
969 SendMessageW (hwndTB
, TB_ADDBITMAP
, nBitmaps
, (LPARAM
)&tbab
);
973 SendMessageW (hwndTB
, TB_ADDBUTTONSW
, iNumButtons
, (LPARAM
)lpButtons
);
980 /***********************************************************************
981 * CreateMappedBitmap [COMCTL32.8]
983 * Loads a bitmap resource using a colour map.
986 * hInstance [I] Handle to the module containing the bitmap.
987 * idBitmap [I] The bitmap resource ID.
988 * wFlags [I] CMB_MASKED for using bitmap as a mask or 0 for normal.
989 * lpColorMap [I] Colour information needed for the bitmap or NULL (uses system colours).
990 * iNumMaps [I] Number of COLORMAP's pointed to by lpColorMap.
993 * Success: handle to the new bitmap
998 CreateMappedBitmap (HINSTANCE hInstance
, INT_PTR idBitmap
, UINT wFlags
,
999 LPCOLORMAP lpColorMap
, INT iNumMaps
)
1003 const BITMAPINFOHEADER
*lpBitmap
;
1004 LPBITMAPINFOHEADER lpBitmapInfo
;
1005 UINT nSize
, nColorTableSize
, iColor
;
1006 RGBQUAD
*pColorTable
;
1007 INT i
, iMaps
, nWidth
, nHeight
;
1010 LPCOLORMAP sysColorMap
;
1012 COLORMAP internalColorMap
[4] =
1013 {{0x000000, 0}, {0x808080, 0}, {0xC0C0C0, 0}, {0xFFFFFF, 0}};
1015 /* initialize pointer to colortable and default color table */
1018 sysColorMap
= lpColorMap
;
1021 internalColorMap
[0].to
= GetSysColor (COLOR_BTNTEXT
);
1022 internalColorMap
[1].to
= GetSysColor (COLOR_BTNSHADOW
);
1023 internalColorMap
[2].to
= GetSysColor (COLOR_BTNFACE
);
1024 internalColorMap
[3].to
= GetSysColor (COLOR_BTNHIGHLIGHT
);
1026 sysColorMap
= internalColorMap
;
1029 hRsrc
= FindResourceW (hInstance
, (LPWSTR
)idBitmap
, (LPWSTR
)RT_BITMAP
);
1032 hglb
= LoadResource (hInstance
, hRsrc
);
1035 lpBitmap
= LockResource (hglb
);
1036 if (lpBitmap
== NULL
)
1039 if (lpBitmap
->biSize
>= sizeof(BITMAPINFOHEADER
) && lpBitmap
->biClrUsed
)
1040 nColorTableSize
= lpBitmap
->biClrUsed
;
1041 else if (lpBitmap
->biBitCount
<= 8)
1042 nColorTableSize
= (1 << lpBitmap
->biBitCount
);
1044 nColorTableSize
= 0;
1045 nSize
= lpBitmap
->biSize
;
1046 if (nSize
== sizeof(BITMAPINFOHEADER
) && lpBitmap
->biCompression
== BI_BITFIELDS
)
1047 nSize
+= 3 * sizeof(DWORD
);
1048 nSize
+= nColorTableSize
* sizeof(RGBQUAD
);
1049 lpBitmapInfo
= GlobalAlloc (GMEM_FIXED
, nSize
);
1050 if (lpBitmapInfo
== NULL
)
1052 RtlMoveMemory (lpBitmapInfo
, lpBitmap
, nSize
);
1054 pColorTable
= (RGBQUAD
*)(((LPBYTE
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
1056 for (iColor
= 0; iColor
< nColorTableSize
; iColor
++) {
1057 for (i
= 0; i
< iMaps
; i
++) {
1058 cRef
= RGB(pColorTable
[iColor
].rgbRed
,
1059 pColorTable
[iColor
].rgbGreen
,
1060 pColorTable
[iColor
].rgbBlue
);
1061 if ( cRef
== sysColorMap
[i
].from
) {
1063 if (wFlags
& CBS_MASKED
) {
1064 if (sysColorMap
[i
].to
!= COLOR_BTNTEXT
)
1065 pColorTable
[iColor
] = RGB(255, 255, 255);
1069 pColorTable
[iColor
].rgbBlue
= GetBValue(sysColorMap
[i
].to
);
1070 pColorTable
[iColor
].rgbGreen
= GetGValue(sysColorMap
[i
].to
);
1071 pColorTable
[iColor
].rgbRed
= GetRValue(sysColorMap
[i
].to
);
1076 nWidth
= lpBitmapInfo
->biWidth
;
1077 nHeight
= lpBitmapInfo
->biHeight
;
1078 hdcScreen
= GetDC (NULL
);
1079 hbm
= CreateCompatibleBitmap (hdcScreen
, nWidth
, nHeight
);
1081 HDC hdcDst
= CreateCompatibleDC (hdcScreen
);
1082 HBITMAP hbmOld
= SelectObject (hdcDst
, hbm
);
1083 const BYTE
*lpBits
= (const BYTE
*)lpBitmap
+ nSize
;
1084 StretchDIBits (hdcDst
, 0, 0, nWidth
, nHeight
, 0, 0, nWidth
, nHeight
,
1085 lpBits
, (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
,
1087 SelectObject (hdcDst
, hbmOld
);
1090 ReleaseDC (NULL
, hdcScreen
);
1091 GlobalFree (lpBitmapInfo
);
1092 FreeResource (hglb
);
1098 /***********************************************************************
1099 * CreateToolbar [COMCTL32.7]
1101 * Creates a toolbar control.
1114 * Success: handle to the tool bar control
1118 * Do not use this function anymore. Use CreateToolbarEx instead.
1122 CreateToolbar (HWND hwnd
, DWORD style
, UINT wID
, INT nBitmaps
,
1123 HINSTANCE hBMInst
, UINT wBMID
,
1124 LPCTBBUTTON lpButtons
,INT iNumButtons
)
1126 return CreateToolbarEx (hwnd
, style
| CCS_NODIVIDER
, wID
, nBitmaps
,
1127 hBMInst
, wBMID
, lpButtons
,
1128 iNumButtons
, 0, 0, 0, 0, CCSIZEOF_STRUCT(TBBUTTON
, dwData
));
1132 /***********************************************************************
1133 * DllGetVersion [COMCTL32.@]
1135 * Retrieves version information of the 'COMCTL32.DLL'
1138 * pdvi [O] pointer to version information structure.
1142 * Failure: E_INVALIDARG
1145 * Returns version of a comctl32.dll from IE4.01 SP1.
1148 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
1150 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) {
1151 WARN("wrong DLLVERSIONINFO size from app\n");
1152 return E_INVALIDARG
;
1155 pdvi
->dwMajorVersion
= COMCTL32_VERSION
;
1156 pdvi
->dwMinorVersion
= COMCTL32_VERSION_MINOR
;
1157 pdvi
->dwBuildNumber
= 2919;
1158 pdvi
->dwPlatformID
= 6304;
1160 TRACE("%u.%u.%u.%u\n",
1161 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
1162 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
1167 /***********************************************************************
1168 * DllInstall (COMCTL32.@)
1170 * Installs the ComCtl32 DLL.
1174 * Failure: A HRESULT error
1176 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
1178 TRACE("(%u, %s): stub\n", bInstall
, debugstr_w(cmdline
));
1182 /***********************************************************************
1183 * _TrackMouseEvent [COMCTL32.@]
1185 * Requests notification of mouse events
1187 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1188 * to the hwnd specified in the ptme structure. After the event message
1189 * is posted to the hwnd, the entry in the queue is removed.
1191 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1192 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1193 * immediately and the TME_LEAVE flag being ignored.
1196 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1202 * IMPLEMENTATION moved to USER32.TrackMouseEvent
1207 _TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1209 return TrackMouseEvent (ptme
);
1212 /*************************************************************************
1213 * GetMUILanguage [COMCTL32.@]
1215 * Returns the user interface language in use by the current process.
1218 * Language ID in use by the current process.
1220 LANGID WINAPI
GetMUILanguage (VOID
)
1222 return COMCTL32_uiLang
;
1226 /*************************************************************************
1227 * InitMUILanguage [COMCTL32.@]
1229 * Sets the user interface language to be used by the current process.
1234 VOID WINAPI
InitMUILanguage (LANGID uiLang
)
1236 COMCTL32_uiLang
= uiLang
;
1240 /***********************************************************************
1241 * SetWindowSubclass [COMCTL32.410]
1243 * Starts a window subclass
1246 * hWnd [in] handle to window subclass.
1247 * pfnSubclass [in] Pointer to new window procedure.
1248 * uIDSubclass [in] Unique identifier of subclass together with pfnSubclass.
1249 * dwRef [in] Reference data to pass to window procedure.
1256 * If an application manually subclasses a window after subclassing it with
1257 * this API and then with this API again, then none of the previous
1258 * subclasses get called or the original window procedure.
1261 BOOL WINAPI
SetWindowSubclass (HWND hWnd
, SUBCLASSPROC pfnSubclass
,
1262 UINT_PTR uIDSubclass
, DWORD_PTR dwRef
)
1264 LPSUBCLASS_INFO stack
;
1265 LPSUBCLASSPROCS proc
;
1267 TRACE ("(%p, %p, %lx, %lx)\n", hWnd
, pfnSubclass
, uIDSubclass
, dwRef
);
1269 if (!hWnd
|| !pfnSubclass
)
1272 /* Since the window procedure that we set here has two additional arguments,
1273 * we can't simply set it as the new window procedure of the window. So we
1274 * set our own window procedure and then calculate the other two arguments
1277 /* See if we have been called for this window */
1278 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1280 /* allocate stack */
1281 stack
= Alloc (sizeof(SUBCLASS_INFO
));
1283 ERR ("Failed to allocate our Subclassing stack\n");
1286 SetPropW (hWnd
, COMCTL32_wSubclass
, stack
);
1288 /* set window procedure to our own and save the current one */
1289 if (IsWindowUnicode (hWnd
))
1290 stack
->origproc
= (WNDPROC
)SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
,
1291 (DWORD_PTR
)COMCTL32_SubclassProc
);
1293 stack
->origproc
= (WNDPROC
)SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
,
1294 (DWORD_PTR
)COMCTL32_SubclassProc
);
1297 /* Check to see if we have called this function with the same uIDSubClass
1298 * and pfnSubclass */
1299 proc
= stack
->SubclassProcs
;
1301 if ((proc
->id
== uIDSubclass
) &&
1302 (proc
->subproc
== pfnSubclass
)) {
1310 proc
= Alloc(sizeof(SUBCLASSPROCS
));
1312 ERR ("Failed to allocate subclass entry in stack\n");
1313 if (IsWindowUnicode (hWnd
))
1314 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1316 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1318 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1322 proc
->subproc
= pfnSubclass
;
1324 proc
->id
= uIDSubclass
;
1325 proc
->next
= stack
->SubclassProcs
;
1326 stack
->SubclassProcs
= proc
;
1332 /***********************************************************************
1333 * GetWindowSubclass [COMCTL32.411]
1335 * Gets the Reference data from a subclass.
1338 * hWnd [in] Handle to the window which we are subclassing
1339 * pfnSubclass [in] Pointer to the subclass procedure
1340 * uID [in] Unique identifier of the subclassing procedure
1341 * pdwRef [out] Pointer to the reference data
1348 BOOL WINAPI
GetWindowSubclass (HWND hWnd
, SUBCLASSPROC pfnSubclass
,
1349 UINT_PTR uID
, DWORD_PTR
*pdwRef
)
1351 const SUBCLASS_INFO
*stack
;
1352 const SUBCLASSPROCS
*proc
;
1354 TRACE ("(%p, %p, %lx, %p)\n", hWnd
, pfnSubclass
, uID
, pdwRef
);
1356 /* See if we have been called for this window */
1357 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1361 proc
= stack
->SubclassProcs
;
1363 if ((proc
->id
== uID
) &&
1364 (proc
->subproc
== pfnSubclass
)) {
1365 *pdwRef
= proc
->ref
;
1375 /***********************************************************************
1376 * RemoveWindowSubclass [COMCTL32.412]
1378 * Removes a window subclass.
1381 * hWnd [in] Handle to the window which we are subclassing
1382 * pfnSubclass [in] Pointer to the subclass procedure
1383 * uID [in] Unique identifier of this subclass
1390 BOOL WINAPI
RemoveWindowSubclass(HWND hWnd
, SUBCLASSPROC pfnSubclass
, UINT_PTR uID
)
1392 LPSUBCLASS_INFO stack
;
1393 LPSUBCLASSPROCS prevproc
= NULL
;
1394 LPSUBCLASSPROCS proc
;
1397 TRACE ("(%p, %p, %lx)\n", hWnd
, pfnSubclass
, uID
);
1399 /* Find the Subclass to remove */
1400 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1404 proc
= stack
->SubclassProcs
;
1406 if ((proc
->id
== uID
) &&
1407 (proc
->subproc
== pfnSubclass
)) {
1410 stack
->SubclassProcs
= proc
->next
;
1412 prevproc
->next
= proc
->next
;
1414 if (stack
->stackpos
== proc
)
1415 stack
->stackpos
= stack
->stackpos
->next
;
1425 if (!stack
->SubclassProcs
&& !stack
->running
) {
1426 TRACE("Last Subclass removed, cleaning up\n");
1427 /* clean up our heap and reset the original window procedure */
1428 if (IsWindowUnicode (hWnd
))
1429 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1431 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1433 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1439 /***********************************************************************
1440 * COMCTL32_SubclassProc (internal)
1442 * Window procedure for all subclassed windows.
1443 * Saves the current subclassing stack position to support nested messages
1445 static LRESULT WINAPI
COMCTL32_SubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1447 LPSUBCLASS_INFO stack
;
1448 LPSUBCLASSPROCS proc
;
1451 TRACE ("(%p, 0x%08x, 0x%08lx, 0x%08lx)\n", hWnd
, uMsg
, wParam
, lParam
);
1453 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1455 ERR ("Our sub classing stack got erased for %p!! Nothing we can do\n", hWnd
);
1459 /* Save our old stackpos to properly handle nested messages */
1460 proc
= stack
->stackpos
;
1461 stack
->stackpos
= stack
->SubclassProcs
;
1463 ret
= DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
1465 stack
->stackpos
= proc
;
1467 if (!stack
->SubclassProcs
&& !stack
->running
) {
1468 TRACE("Last Subclass removed, cleaning up\n");
1469 /* clean up our heap and reset the original window procedure */
1470 if (IsWindowUnicode (hWnd
))
1471 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1473 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1475 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1480 /***********************************************************************
1481 * DefSubclassProc [COMCTL32.413]
1483 * Calls the next window procedure (i.e. the one before this subclass)
1486 * hWnd [in] The window that we're subclassing
1488 * wParam [in] WPARAM
1489 * lParam [in] LPARAM
1496 LRESULT WINAPI
DefSubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1498 LPSUBCLASS_INFO stack
;
1501 TRACE ("(%p, 0x%08x, 0x%08lx, 0x%08lx)\n", hWnd
, uMsg
, wParam
, lParam
);
1503 /* retrieve our little stack from the Properties */
1504 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1506 ERR ("Our sub classing stack got erased for %p!! Nothing we can do\n", hWnd
);
1510 /* If we are at the end of stack then we have to call the original
1511 * window procedure */
1512 if (!stack
->stackpos
) {
1513 if (IsWindowUnicode (hWnd
))
1514 ret
= CallWindowProcW (stack
->origproc
, hWnd
, uMsg
, wParam
, lParam
);
1516 ret
= CallWindowProcA (stack
->origproc
, hWnd
, uMsg
, wParam
, lParam
);
1518 const SUBCLASSPROCS
*proc
= stack
->stackpos
;
1519 stack
->stackpos
= stack
->stackpos
->next
;
1520 /* call the Subclass procedure from the stack */
1521 ret
= proc
->subproc (hWnd
, uMsg
, wParam
, lParam
,
1522 proc
->id
, proc
->ref
);
1529 /***********************************************************************
1530 * COMCTL32_CreateToolTip [NOT AN API]
1532 * Creates a tooltip for the control specified in hwnd and does all
1533 * necessary setup and notifications.
1536 * hwndOwner [I] Handle to the window that will own the tool tip.
1539 * Success: Handle of tool tip window.
1544 COMCTL32_CreateToolTip(HWND hwndOwner
)
1548 hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1549 CW_USEDEFAULT
, CW_USEDEFAULT
,
1550 CW_USEDEFAULT
, CW_USEDEFAULT
, hwndOwner
,
1553 /* Send NM_TOOLTIPSCREATED notification */
1556 NMTOOLTIPSCREATED nmttc
;
1557 /* true owner can be different if hwndOwner is a child window */
1558 HWND hwndTrueOwner
= GetWindow(hwndToolTip
, GW_OWNER
);
1559 nmttc
.hdr
.hwndFrom
= hwndTrueOwner
;
1560 nmttc
.hdr
.idFrom
= GetWindowLongPtrW(hwndTrueOwner
, GWLP_ID
);
1561 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
1562 nmttc
.hwndToolTips
= hwndToolTip
;
1564 SendMessageW(GetParent(hwndTrueOwner
), WM_NOTIFY
,
1565 GetWindowLongPtrW(hwndTrueOwner
, GWLP_ID
), (LPARAM
)&nmttc
);
1572 /***********************************************************************
1573 * COMCTL32_RefreshSysColors [NOT AN API]
1575 * Invoked on any control recognizing a WM_SYSCOLORCHANGE message to
1576 * refresh the color values in the color structure
1586 COMCTL32_RefreshSysColors(void)
1588 comctl32_color
.clrBtnHighlight
= GetSysColor (COLOR_BTNHIGHLIGHT
);
1589 comctl32_color
.clrBtnShadow
= GetSysColor (COLOR_BTNSHADOW
);
1590 comctl32_color
.clrBtnText
= GetSysColor (COLOR_BTNTEXT
);
1591 comctl32_color
.clrBtnFace
= GetSysColor (COLOR_BTNFACE
);
1592 comctl32_color
.clrHighlight
= GetSysColor (COLOR_HIGHLIGHT
);
1593 comctl32_color
.clrHighlightText
= GetSysColor (COLOR_HIGHLIGHTTEXT
);
1594 comctl32_color
.clrHotTrackingColor
= GetSysColor (COLOR_HOTLIGHT
);
1595 comctl32_color
.clr3dHilight
= GetSysColor (COLOR_3DHILIGHT
);
1596 comctl32_color
.clr3dShadow
= GetSysColor (COLOR_3DSHADOW
);
1597 comctl32_color
.clr3dDkShadow
= GetSysColor (COLOR_3DDKSHADOW
);
1598 comctl32_color
.clr3dFace
= GetSysColor (COLOR_3DFACE
);
1599 comctl32_color
.clrWindow
= GetSysColor (COLOR_WINDOW
);
1600 comctl32_color
.clrWindowText
= GetSysColor (COLOR_WINDOWTEXT
);
1601 comctl32_color
.clrGrayText
= GetSysColor (COLOR_GRAYTEXT
);
1602 comctl32_color
.clrActiveCaption
= GetSysColor (COLOR_ACTIVECAPTION
);
1603 comctl32_color
.clrInfoBk
= GetSysColor (COLOR_INFOBK
);
1604 comctl32_color
.clrInfoText
= GetSysColor (COLOR_INFOTEXT
);
1607 /***********************************************************************
1608 * COMCTL32_DrawInsertMark [NOT AN API]
1610 * Draws an insertion mark (which looks similar to an 'I').
1613 * hDC [I] Device context to draw onto.
1614 * lpRect [I] Co-ordinates of insertion mark.
1615 * clrInsertMark [I] Colour of the insertion mark.
1616 * bHorizontal [I] True if insert mark should be drawn horizontally,
1617 * vertical otherwise.
1623 * Draws up to but not including the bottom co-ordinate when drawing
1624 * vertically or the right co-ordinate when horizontal.
1626 void COMCTL32_DrawInsertMark(HDC hDC
, const RECT
*lpRect
, COLORREF clrInsertMark
, BOOL bHorizontal
)
1628 HPEN hPen
= CreatePen(PS_SOLID
, 1, clrInsertMark
);
1630 static const DWORD adwPolyPoints
[] = {4,4,4};
1631 LONG lCentre
= (bHorizontal
?
1632 lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
)/2 :
1633 lpRect
->left
+ (lpRect
->right
- lpRect
->left
)/2);
1634 LONG l1
= (bHorizontal
? lpRect
->left
: lpRect
->top
);
1635 LONG l2
= (bHorizontal
? lpRect
->right
: lpRect
->bottom
);
1636 const POINT aptInsertMark
[] =
1638 /* top (V) or left (H) arrow */
1642 {lCentre
+ 1, l1
+ 2},
1646 {lCentre
+ 1, l1
- 1},
1647 {lCentre
+ 1, l2
- 2},
1648 /* bottom (V) or right (H) arrow */
1650 {lCentre
- 2, l2
- 1},
1651 {lCentre
+ 3, l2
- 1},
1652 {lCentre
+ 1, l2
- 3},
1654 hOldPen
= SelectObject(hDC
, hPen
);
1655 PolyPolyline(hDC
, aptInsertMark
, adwPolyPoints
, ARRAY_SIZE(adwPolyPoints
));
1656 SelectObject(hDC
, hOldPen
);
1660 /***********************************************************************
1661 * COMCTL32_EnsureBitmapSize [internal]
1663 * If needed, enlarge the bitmap so that the width is at least cxMinWidth and
1664 * the height is at least cyMinHeight. If the bitmap already has these
1665 * dimensions nothing changes.
1668 * hBitmap [I/O] Bitmap to modify. The handle may change
1669 * cxMinWidth [I] If the width of the bitmap is smaller, then it will
1670 * be enlarged to this value
1671 * cyMinHeight [I] If the height of the bitmap is smaller, then it will
1672 * be enlarged to this value
1673 * cyBackground [I] The color with which the new area will be filled
1678 void COMCTL32_EnsureBitmapSize(HBITMAP
*pBitmap
, int cxMinWidth
, int cyMinHeight
, COLORREF crBackground
)
1683 HBITMAP hNewDCBitmap
, hOldDCBitmap
;
1687 if (!GetObjectW(*pBitmap
, sizeof(BITMAP
), &bmp
))
1689 cxNew
= (cxMinWidth
> bmp
.bmWidth
? cxMinWidth
: bmp
.bmWidth
);
1690 cyNew
= (cyMinHeight
> bmp
.bmHeight
? cyMinHeight
: bmp
.bmHeight
);
1691 if (cxNew
== bmp
.bmWidth
&& cyNew
== bmp
.bmHeight
)
1694 hdcNew
= CreateCompatibleDC(NULL
);
1695 hNewBitmap
= CreateBitmap(cxNew
, cyNew
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
1696 hNewDCBitmap
= SelectObject(hdcNew
, hNewBitmap
);
1697 hNewDCBrush
= SelectObject(hdcNew
, CreateSolidBrush(crBackground
));
1699 hdcOld
= CreateCompatibleDC(NULL
);
1700 hOldDCBitmap
= SelectObject(hdcOld
, *pBitmap
);
1702 BitBlt(hdcNew
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcOld
, 0, 0, SRCCOPY
);
1703 if (bmp
.bmWidth
< cxMinWidth
)
1704 PatBlt(hdcNew
, bmp
.bmWidth
, 0, cxNew
, bmp
.bmHeight
, PATCOPY
);
1705 if (bmp
.bmHeight
< cyMinHeight
)
1706 PatBlt(hdcNew
, 0, bmp
.bmHeight
, bmp
.bmWidth
, cyNew
, PATCOPY
);
1707 if (bmp
.bmWidth
< cxMinWidth
&& bmp
.bmHeight
< cyMinHeight
)
1708 PatBlt(hdcNew
, bmp
.bmWidth
, bmp
.bmHeight
, cxNew
, cyNew
, PATCOPY
);
1710 SelectObject(hdcNew
, hNewDCBitmap
);
1711 DeleteObject(SelectObject(hdcNew
, hNewDCBrush
));
1713 SelectObject(hdcOld
, hOldDCBitmap
);
1716 DeleteObject(*pBitmap
);
1717 *pBitmap
= hNewBitmap
;
1721 void COMCTL32_GetFontMetrics(HFONT hFont
, TEXTMETRICW
*ptm
)
1723 HDC hdc
= GetDC(NULL
);
1726 hOldFont
= SelectObject(hdc
, hFont
);
1727 GetTextMetricsW(hdc
, ptm
);
1728 SelectObject(hdc
, hOldFont
);
1729 ReleaseDC(NULL
, hdc
);
1732 #ifndef OCM__BASE /* avoid including olectl.h */
1733 #define OCM__BASE (WM_USER+0x1c00)
1736 /***********************************************************************
1737 * COMCTL32_IsReflectedMessage [internal]
1739 * Some parents reflect notify messages - for some messages sent by the child,
1740 * they send it back with the message code increased by OCM__BASE (0x2000).
1741 * This allows better subclassing of controls. We don't need to handle such
1742 * messages but we don't want to print ERRs for them, so this helper function
1745 * Some of the codes are in the CCM_FIRST..CCM_LAST range, but there is no
1746 * collision with defined CCM_ codes.
1748 BOOL
COMCTL32_IsReflectedMessage(UINT uMsg
)
1752 case OCM__BASE
+ WM_COMMAND
:
1753 case OCM__BASE
+ WM_CTLCOLORBTN
:
1754 case OCM__BASE
+ WM_CTLCOLOREDIT
:
1755 case OCM__BASE
+ WM_CTLCOLORDLG
:
1756 case OCM__BASE
+ WM_CTLCOLORLISTBOX
:
1757 case OCM__BASE
+ WM_CTLCOLORMSGBOX
:
1758 case OCM__BASE
+ WM_CTLCOLORSCROLLBAR
:
1759 case OCM__BASE
+ WM_CTLCOLORSTATIC
:
1760 case OCM__BASE
+ WM_DRAWITEM
:
1761 case OCM__BASE
+ WM_MEASUREITEM
:
1762 case OCM__BASE
+ WM_DELETEITEM
:
1763 case OCM__BASE
+ WM_VKEYTOITEM
:
1764 case OCM__BASE
+ WM_CHARTOITEM
:
1765 case OCM__BASE
+ WM_COMPAREITEM
:
1766 case OCM__BASE
+ WM_HSCROLL
:
1767 case OCM__BASE
+ WM_VSCROLL
:
1768 case OCM__BASE
+ WM_PARENTNOTIFY
:
1769 case OCM__BASE
+ WM_NOTIFY
:
1776 /***********************************************************************
1777 * MirrorIcon [COMCTL32.414]
1779 * Mirrors an icon so that it will appear correctly on a mirrored DC.
1782 * phicon1 [I/O] Icon.
1783 * phicon2 [I/O] Icon.
1789 BOOL WINAPI
MirrorIcon(HICON
*phicon1
, HICON
*phicon2
)
1791 FIXME("(%p, %p): stub\n", phicon1
, phicon2
);
1795 static inline BOOL
IsDelimiter(WCHAR c
)
1808 static int CALLBACK
PathWordBreakProc(LPCWSTR lpch
, int ichCurrent
, int cch
, int code
)
1810 if (code
== WB_ISDELIMITER
)
1811 return IsDelimiter(lpch
[ichCurrent
]);
1814 int dir
= (code
== WB_LEFT
) ? -1 : 1;
1815 for(; 0 <= ichCurrent
&& ichCurrent
< cch
; ichCurrent
+= dir
)
1816 if (IsDelimiter(lpch
[ichCurrent
])) return ichCurrent
;
1821 /***********************************************************************
1822 * SetPathWordBreakProc [COMCTL32.384]
1824 * Sets the word break procedure for an edit control to one that understands
1825 * paths so that the user can jump over directories.
1828 * hwnd [I] Handle to edit control.
1829 * bSet [I] If this is TRUE then the word break proc is set, otherwise it is removed.
1832 * Result from EM_SETWORDBREAKPROC message.
1834 LRESULT WINAPI
SetPathWordBreakProc(HWND hwnd
, BOOL bSet
)
1836 return SendMessageW(hwnd
, EM_SETWORDBREAKPROC
, 0,
1837 (LPARAM
)(bSet
? PathWordBreakProc
: NULL
));
1840 /***********************************************************************
1841 * DrawShadowText [COMCTL32.@]
1843 * Draw text with shadow.
1845 int WINAPI
DrawShadowText(HDC hdc
, LPCWSTR pszText
, UINT cch
, RECT
*prc
, DWORD dwFlags
,
1846 COLORREF crText
, COLORREF crShadow
, int ixOffset
, int iyOffset
)
1850 INT iRet
, x
, y
, x2
, y2
;
1852 HBITMAP hbm
, hbmOld
;
1858 /* Create 32 bit DIB section for the shadow */
1859 ZeroMemory(&bi
, sizeof(bi
));
1860 bi
.bmiHeader
.biSize
= sizeof(bi
.bmiHeader
);
1861 bi
.bmiHeader
.biWidth
= prc
->right
- prc
->left
+ 4;
1862 bi
.bmiHeader
.biHeight
= prc
->bottom
- prc
->top
+ 5; // bottom-up DIB
1863 bi
.bmiHeader
.biPlanes
= 1;
1864 bi
.bmiHeader
.biBitCount
= 32;
1865 bi
.bmiHeader
.biCompression
= BI_RGB
;
1866 hbm
= CreateDIBSection(hdc
, &bi
, DIB_RGB_COLORS
, (PVOID
*)&pBits
, NULL
, 0);
1869 ERR("CreateDIBSection failed\n");
1873 /* Create memory device context for new DIB section and select it */
1874 hdcMem
= CreateCompatibleDC(hdc
);
1877 ERR("CreateCompatibleDC failed\n");
1882 hbmOld
= (HBITMAP
)SelectObject(hdcMem
, hbm
);
1884 /* Draw text on our helper bitmap */
1885 hOldFont
= (HFONT
)SelectObject(hdcMem
, GetCurrentObject(hdc
, OBJ_FONT
));
1886 SetTextColor(hdcMem
, RGB(16, 16, 16));
1887 SetBkColor(hdcMem
, RGB(0, 0, 0));
1888 SetBkMode(hdcMem
, TRANSPARENT
);
1889 SetRect(&rcText
, 0, 0, prc
->right
- prc
->left
, prc
->bottom
- prc
->top
);
1890 DrawTextW(hdcMem
, pszText
, cch
, &rcText
, dwFlags
);
1891 SelectObject(hdcMem
, hOldFont
);
1893 /* Flush GDI so data pointed by pBits is valid */
1896 /* Set alpha of pixels (forget about colors for now. They will be changed in next loop).
1897 We copy text image 4*5 times and each time alpha is added */
1898 for (x
= 0; x
< bi
.bmiHeader
.biWidth
; ++x
)
1899 for (y
= 0; y
< bi
.bmiHeader
.biHeight
; ++y
)
1901 BYTE
*pDest
= &pBits
[(y
* bi
.bmiHeader
.biWidth
+ x
) * 4];
1904 for (x2
= x
- 4 + 1; x2
<= x
; ++x2
)
1905 for (y2
= y
; y2
< y
+ 5; ++y2
)
1907 if (x2
>= 0 && x2
< bi
.bmiHeader
.biWidth
&& y2
>= 0 && y2
< bi
.bmiHeader
.biHeight
)
1909 BYTE
*pSrc
= &pBits
[(y2
* bi
.bmiHeader
.biWidth
+ x2
) * 4];
1919 /* Now set the color of each pixel to shadow color * alpha (see GdiAlphaBlend) */
1920 for (x
= 0; x
< bi
.bmiHeader
.biWidth
; ++x
)
1921 for (y
= 0; y
< bi
.bmiHeader
.biHeight
; ++y
)
1923 BYTE
*pDest
= &pBits
[(y
* bi
.bmiHeader
.biWidth
+ x
) * 4];
1924 pDest
[0] = GetBValue(crShadow
) * pDest
[3] / 255;
1925 pDest
[1] = GetGValue(crShadow
) * pDest
[3] / 255;
1926 pDest
[2] = GetRValue(crShadow
) * pDest
[3] / 255;
1929 /* Fix ixOffset of the shadow (tested on Win) */
1933 /* Alpha blend helper image to destination DC */
1934 bf
.BlendOp
= AC_SRC_OVER
;
1936 bf
.SourceConstantAlpha
= 255;
1937 bf
.AlphaFormat
= AC_SRC_ALPHA
;
1938 GdiAlphaBlend(hdc
, prc
->left
+ ixOffset
, prc
->top
+ iyOffset
, bi
.bmiHeader
.biWidth
, bi
.bmiHeader
.biHeight
, hdcMem
, 0, 0, bi
.bmiHeader
.biWidth
, bi
.bmiHeader
.biHeight
, bf
);
1940 /* Delete the helper bitmap */
1941 SelectObject(hdcMem
, hbmOld
);
1945 /* Finally draw the text over shadow */
1946 crOldText
= SetTextColor(hdc
, crText
);
1947 SetBkMode(hdc
, TRANSPARENT
);
1948 iRet
= DrawTextW(hdc
, pszText
, cch
, prc
, dwFlags
);
1949 SetTextColor(hdc
, crOldText
);
1954 /***********************************************************************
1955 * LoadIconWithScaleDown [COMCTL32.@]
1957 HRESULT WINAPI
LoadIconWithScaleDown(HINSTANCE hinst
, const WCHAR
*name
, int cx
, int cy
, HICON
*icon
)
1959 TRACE("(%p, %s, %d, %d, %p)\n", hinst
, debugstr_w(name
), cx
, cy
, icon
);
1964 return E_INVALIDARG
;
1966 *icon
= LoadImageW(hinst
, name
, IMAGE_ICON
, cx
, cy
,
1967 (hinst
|| IS_INTRESOURCE(name
)) ? 0 : LR_LOADFROMFILE
);
1969 return HRESULT_FROM_WIN32(GetLastError());
1974 /***********************************************************************
1975 * LoadIconMetric [COMCTL32.@]
1977 HRESULT WINAPI
LoadIconMetric(HINSTANCE hinst
, const WCHAR
*name
, int size
, HICON
*icon
)
1981 TRACE("(%p, %s, %d, %p)\n", hinst
, debugstr_w(name
), size
, icon
);
1983 if (size
== LIM_SMALL
)
1985 cx
= GetSystemMetrics(SM_CXSMICON
);
1986 cy
= GetSystemMetrics(SM_CYSMICON
);
1988 else if (size
== LIM_LARGE
)
1990 cx
= GetSystemMetrics(SM_CXICON
);
1991 cy
= GetSystemMetrics(SM_CYICON
);
1996 return E_INVALIDARG
;
1999 return LoadIconWithScaleDown(hinst
, name
, cx
, cy
, icon
);