2 * Common controls functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1998 Eric Kohl
17 #include "ipaddress.h"
20 #include "nativefont.h"
31 #include "winversion.h"
36 HANDLE32 COMCTL32_hHeap
= (HANDLE32
)NULL
;
37 DWORD COMCTL32_dwProcessesAttached
= 0;
38 LPSTR COMCTL32_aSubclass
= (LPSTR
)NULL
;
41 /***********************************************************************
42 * COMCTL32_LibMain [Internal] Initializes the internal 'COMCTL32.DLL'.
45 * hinstDLL [I] handle to the 'dlls' instance
47 * lpvReserved [I] reserverd, must be NULL
55 COMCTL32_LibMain (HINSTANCE32 hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
57 TRACE (commctrl
, "%x,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
60 case DLL_PROCESS_ATTACH
:
61 if (COMCTL32_dwProcessesAttached
== 0) {
62 /* create private heap */
63 COMCTL32_hHeap
= HeapCreate (0, 0x10000, 0);
64 TRACE (commctrl
, "Heap created: 0x%x\n", COMCTL32_hHeap
);
66 /* add global subclassing atom (used by 'tooltip' and 'updown') */
67 COMCTL32_aSubclass
= (LPSTR
)(DWORD
)GlobalAddAtom32A ("CC32SubclassInfo");
68 TRACE (commctrl
, "Subclassing atom added: %p\n",
71 /* register all Win95 common control classes */
85 COMCTL32_dwProcessesAttached
++;
88 case DLL_PROCESS_DETACH
:
89 COMCTL32_dwProcessesAttached
--;
90 if (COMCTL32_dwProcessesAttached
== 0) {
91 /* unregister all common control classes */
92 ANIMATE_Unregister ();
93 COMBOEX_Unregister ();
94 DATETIME_Unregister ();
97 IPADDRESS_Unregister ();
98 LISTVIEW_Unregister ();
99 MONTHCAL_Unregister ();
100 NATIVEFONT_Unregister ();
102 PROGRESS_Unregister ();
104 STATUS_Unregister ();
106 TOOLBAR_Unregister ();
107 TOOLTIPS_Unregister ();
108 TRACKBAR_Unregister ();
109 TREEVIEW_Unregister ();
110 UPDOWN_Unregister ();
112 /* delete global subclassing atom */
113 GlobalDeleteAtom (LOWORD(COMCTL32_aSubclass
));
114 TRACE (commctrl
, "Subclassing atom deleted: %p\n",
116 COMCTL32_aSubclass
= (LPSTR
)NULL
;
118 /* destroy private heap */
119 HeapDestroy (COMCTL32_hHeap
);
120 TRACE (commctrl
, "Heap destroyed: 0x%x\n", COMCTL32_hHeap
);
121 COMCTL32_hHeap
= (HANDLE32
)NULL
;
130 /***********************************************************************
131 * MenuHelp [COMCTL32.2]
137 * hMainMenu [I] handle to the applications main menu
139 * hwndStatus [I] handle to the status bar window
140 * lpwIDs [I] pointer to an array of intergers (see NOTES)
146 * The official documentation is incomplete!
150 MenuHelp (UINT32 uMsg
, WPARAM32 wParam
, LPARAM lParam
, HMENU32 hMainMenu
,
151 HINSTANCE32 hInst
, HWND32 hwndStatus
, LPUINT32 lpwIDs
)
155 if (!IsWindow32 (hwndStatus
))
160 TRACE (commctrl
, "WM_MENUSELECT wParam=0x%X lParam=0x%lX\n",
163 if ((HIWORD(wParam
) == 0xFFFF) && (lParam
== 0)) {
164 /* menu was closed */
165 TRACE (commctrl
, "menu was closed!\n");
166 SendMessage32A (hwndStatus
, SB_SIMPLE
, FALSE
, 0);
169 /* menu item was selected */
170 if (HIWORD(wParam
) & MF_POPUP
)
171 uMenuID
= (UINT32
)*(lpwIDs
+1);
173 uMenuID
= (UINT32
)LOWORD(wParam
);
174 TRACE (commctrl
, "uMenuID = %u\n", uMenuID
);
179 if (!LoadString32A (hInst
, uMenuID
, szText
, 256))
182 SendMessage32A (hwndStatus
, SB_SETTEXT32A
,
183 255 | SBT_NOBORDERS
, (LPARAM
)szText
);
184 SendMessage32A (hwndStatus
, SB_SIMPLE
, TRUE
, 0);
190 FIXME (commctrl
, "Invalid Message 0x%x!\n", uMsg
);
196 /***********************************************************************
197 * ShowHideMenuCtl [COMCTL32.3]
199 * Shows or hides controls and updates the corresponding menu item.
202 * hwnd [I] handle to the client window.
203 * uFlags [I] menu command id.
204 * lpInfo [I] pointer to an array of integers. (See NOTES.)
211 * The official documentation is incomplete! This has been fixed.
214 * The array of integers contains pairs of values. BOTH values of
215 * the first pair must be the handles to application's main menu.
216 * Each subsequent pair consists of a menu id and control id.
220 ShowHideMenuCtl (HWND32 hwnd
, UINT32 uFlags
, LPINT32 lpInfo
)
224 TRACE (commctrl
, "%x, %x, %p\n", hwnd
, uFlags
, lpInfo
);
229 if (!(lpInfo
[0]) || !(lpInfo
[1]))
232 /* search for control */
233 lpMenuId
= &lpInfo
[2];
234 while (*lpMenuId
!= uFlags
)
237 if (GetMenuState32 (lpInfo
[1], uFlags
, MF_BYCOMMAND
) & MFS_CHECKED
) {
238 /* uncheck menu item */
239 CheckMenuItem32 (lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_UNCHECKED
);
243 SetWindowPos32 (GetDlgItem32 (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
247 /* check menu item */
248 CheckMenuItem32 (lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_CHECKED
);
252 SetWindowPos32 (GetDlgItem32 (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
260 /***********************************************************************
261 * GetEffectiveClientRect [COMCTL32.4]
264 * hwnd [I] handle to the client window.
265 * lpRect [O] pointer to the rectangle of the client window
266 * lpInfo [I] pointer to an array of integers
272 * The official documentation is incomplete!
276 GetEffectiveClientRect (HWND32 hwnd
, LPRECT32 lpRect
, LPINT32 lpInfo
)
282 TRACE (commctrl
, "(0x%08lx 0x%08lx 0x%08lx)\n",
283 (DWORD
)hwnd
, (DWORD
)lpRect
, (DWORD
)lpInfo
);
285 GetClientRect32 (hwnd
, lpRect
);
293 hwndCtrl
= GetDlgItem32 (hwnd
, *lpRun
);
294 if (GetWindowLong32A (hwndCtrl
, GWL_STYLE
) & WS_VISIBLE
) {
295 TRACE (commctrl
, "control id 0x%x\n", *lpRun
);
296 GetWindowRect32 (hwndCtrl
, &rcCtrl
);
297 MapWindowPoints32 ((HWND32
)0, hwnd
, (LPPOINT32
)&rcCtrl
, 2);
298 SubtractRect32 (lpRect
, lpRect
, &rcCtrl
);
305 /***********************************************************************
306 * DrawStatusText32A [COMCTL32.5]
308 * Draws text with borders, like in a status bar.
311 * hdc [I] handle to the window's display context
312 * lprc [I] pointer to a rectangle
313 * text [I] pointer to the text
321 DrawStatusText32A (HDC32 hdc
, LPRECT32 lprc
, LPCSTR text
, UINT32 style
)
324 UINT32 border
= BDR_SUNKENOUTER
;
326 if (style
== SBT_POPOUT
)
327 border
= BDR_RAISEDOUTER
;
328 else if (style
== SBT_NOBORDERS
)
331 DrawEdge32 (hdc
, &r
, border
, BF_RECT
|BF_ADJUST
|BF_MIDDLE
);
335 int oldbkmode
= SetBkMode32 (hdc
, TRANSPARENT
);
337 DrawText32A (hdc
, text
, lstrlen32A(text
),
338 &r
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
);
339 if (oldbkmode
!= TRANSPARENT
)
340 SetBkMode32(hdc
, oldbkmode
);
345 /***********************************************************************
346 * DrawStatusText32W [COMCTL32.28]
348 * Draws text with borders, like in a status bar.
351 * hdc [I] handle to the window's display context
352 * lprc [I] pointer to a rectangle
353 * text [I] pointer to the text
361 DrawStatusText32W (HDC32 hdc
, LPRECT32 lprc
, LPCWSTR text
, UINT32 style
)
363 LPSTR p
= HEAP_strdupWtoA (GetProcessHeap (), 0, text
);
364 DrawStatusText32A (hdc
, lprc
, p
, style
);
365 HeapFree (GetProcessHeap (), 0, p
);
369 /***********************************************************************
370 * DrawStatusText32AW [COMCTL32.27]
372 * Draws text with borders, like in a status bar.
375 * hdc [I] handle to the window's display context
376 * lprc [I] pointer to a rectangle
377 * text [I] pointer to the text
384 * Calls DrawStatusText32A() or DrawStatusText32W().
388 DrawStatusText32AW (HDC32 hdc
, LPRECT32 lprc
, LPVOID text
, UINT32 style
)
390 if (VERSION_OsIsUnicode())
391 DrawStatusText32W (hdc
, lprc
, (LPCWSTR
)text
, style
);
392 DrawStatusText32A (hdc
, lprc
, (LPCSTR
)text
, style
);
396 /***********************************************************************
397 * CreateStatusWindow32A [COMCTL32.6]
399 * Creates a status bar
404 * parent [I] handle to the parent window
405 * wid [I] control id of the status bar
408 * Success: handle to the control
413 CreateStatusWindow32A (INT32 style
, LPCSTR text
, HWND32 parent
, UINT32 wid
)
415 return CreateWindow32A(STATUSCLASSNAME32A
, text
, style
,
416 CW_USEDEFAULT32
, CW_USEDEFAULT32
,
417 CW_USEDEFAULT32
, CW_USEDEFAULT32
,
422 /***********************************************************************
423 * CreateStatusWindow32W [COMCTL32.22] Creates a status bar control
428 * parent [I] handle to the parent window
429 * wid [I] control id of the status bar
432 * Success: handle to the control
437 CreateStatusWindow32W (INT32 style
, LPCWSTR text
, HWND32 parent
, UINT32 wid
)
439 return CreateWindow32W(STATUSCLASSNAME32W
, text
, style
,
440 CW_USEDEFAULT32
, CW_USEDEFAULT32
,
441 CW_USEDEFAULT32
, CW_USEDEFAULT32
,
446 /***********************************************************************
447 * CreateStatusWindow32AW [COMCTL32.21] Creates a status bar control
452 * parent [I] handle to the parent window
453 * wid [I] control id of the status bar
456 * Success: handle to the control
461 CreateStatusWindow32AW (INT32 style
, LPVOID text
, HWND32 parent
, UINT32 wid
)
463 if (VERSION_OsIsUnicode())
464 return CreateStatusWindow32W (style
, (LPCWSTR
)text
, parent
, wid
);
465 return CreateStatusWindow32A (style
, (LPCSTR
)text
, parent
, wid
);
469 /***********************************************************************
470 * CreateUpDownControl [COMCTL32.16] Creates an Up-Down control
487 * Success: handle to the control
492 CreateUpDownControl (DWORD style
, INT32 x
, INT32 y
, INT32 cx
, INT32 cy
,
493 HWND32 parent
, INT32 id
, HINSTANCE32 inst
,
494 HWND32 buddy
, INT32 maxVal
, INT32 minVal
, INT32 curVal
)
497 CreateWindow32A (UPDOWN_CLASS32A
, 0, style
, x
, y
, cx
, cy
,
498 parent
, id
, inst
, 0);
500 SendMessage32A (hUD
, UDM_SETBUDDY
, buddy
, 0);
501 SendMessage32A (hUD
, UDM_SETRANGE
, 0, MAKELONG(maxVal
, minVal
));
502 SendMessage32A (hUD
, UDM_SETPOS
, 0, MAKELONG(curVal
, 0));
509 /***********************************************************************
510 * InitCommonControls [COMCTL32.17]
512 * Registers the common controls.
521 * This function is just a dummy.
522 * The Win95 controls are registered at the DLL's initialization.
523 * To register other controls InitCommonControlsEx must be used.
527 InitCommonControls (VOID
)
532 /***********************************************************************
533 * InitCommonControlsEx [COMCTL32.81]
535 * Registers the common controls.
538 * lpInitCtrls [I] pointer to an INITCOMMONCONTROLS structure.
545 * Only the additinal common controls are registered by this function.
546 * The Win95 controls are registered at the DLL's initialization.
550 InitCommonControlsEx (LPINITCOMMONCONTROLSEX lpInitCtrls
)
557 if (lpInitCtrls
->dwSize
!= sizeof(INITCOMMONCONTROLSEX
))
560 TRACE(commctrl
,"(0x%08lx)\n", lpInitCtrls
->dwICC
);
562 for (cCount
= 0; cCount
< 32; cCount
++) {
563 dwMask
= 1 << cCount
;
564 if (!(lpInitCtrls
->dwICC
& dwMask
))
567 switch (lpInitCtrls
->dwICC
& dwMask
) {
568 /* dummy initialization */
569 case ICC_ANIMATE_CLASS
:
570 case ICC_BAR_CLASSES
:
571 case ICC_LISTVIEW_CLASSES
:
572 case ICC_TREEVIEW_CLASSES
:
573 case ICC_TAB_CLASSES
:
574 case ICC_UPDOWN_CLASS
:
575 case ICC_PROGRESS_CLASS
:
576 case ICC_HOTKEY_CLASS
:
579 /* advanced classes - not included in Win95 */
580 case ICC_DATE_CLASSES
:
581 MONTHCAL_Register ();
582 DATETIME_Register ();
585 case ICC_USEREX_CLASSES
:
589 case ICC_COOL_CLASSES
:
593 case ICC_INTERNET_CLASSES
:
594 IPADDRESS_Register ();
597 case ICC_PAGESCROLLER_CLASS
:
601 case ICC_NATIVEFNTCTL_CLASS
:
602 NATIVEFONT_Register ();
606 FIXME (commctrl
, "Unknown class! dwICC=0x%lX\n", dwMask
);
615 /***********************************************************************
616 * CreateToolbarEx [COMCTL32.32] Creates a tool bar window
634 * Success: handle to the tool bar control
639 CreateToolbarEx (HWND32 hwnd
, DWORD style
, UINT32 wID
, INT32 nBitmaps
,
640 HINSTANCE32 hBMInst
, UINT32 wBMID
, LPCTBBUTTON lpButtons
,
641 INT32 iNumButtons
, INT32 dxButton
, INT32 dyButton
,
642 INT32 dxBitmap
, INT32 dyBitmap
, UINT32 uStructSize
)
645 CreateWindowEx32A (0, TOOLBARCLASSNAME32A
, "", style
, 0, 0, 0, 0,
646 hwnd
, (HMENU32
)wID
, 0, NULL
);
650 SendMessage32A (hwndTB
, TB_BUTTONSTRUCTSIZE
,
651 (WPARAM32
)uStructSize
, 0);
653 /* set bitmap and button size */
654 if (hBMInst
== HINST_COMMCTRL
) {
656 SendMessage32A (hwndTB
, TB_SETBITMAPSIZE
, 0,
658 SendMessage32A (hwndTB
, TB_SETBUTTONSIZE
, 0,
662 SendMessage32A (hwndTB
, TB_SETBITMAPSIZE
, 0,
664 SendMessage32A (hwndTB
, TB_SETBUTTONSIZE
, 0,
669 SendMessage32A (hwndTB
, TB_SETBITMAPSIZE
, 0,
670 MAKELPARAM((WORD
)dyBitmap
, (WORD
)dxBitmap
));
671 SendMessage32A (hwndTB
, TB_SETBUTTONSIZE
, 0,
672 MAKELPARAM((WORD
)dyButton
, (WORD
)dxButton
));
676 tbab
.hInst
= hBMInst
;
678 SendMessage32A (hwndTB
, TB_ADDBITMAP
,
679 (WPARAM32
)nBitmaps
, (LPARAM
)&tbab
);
682 SendMessage32A (hwndTB
, TB_ADDBUTTONS32A
,
683 (WPARAM32
)iNumButtons
, (LPARAM
)lpButtons
);
690 /***********************************************************************
691 * CreateMappedBitmap [COMCTL32.8]
701 * Success: bitmap handle
706 CreateMappedBitmap (HINSTANCE32 hInstance
, INT32 idBitmap
, UINT32 wFlags
,
707 LPCOLORMAP lpColorMap
, INT32 iNumMaps
)
711 LPBITMAPINFOHEADER lpBitmap
, lpBitmapInfo
;
712 UINT32 nSize
, nColorTableSize
;
714 INT32 iColor
, i
, iMaps
, nWidth
, nHeight
;
717 LPCOLORMAP sysColorMap
;
718 COLORMAP internalColorMap
[4] =
719 {{0x000000, 0}, {0x808080, 0}, {0xC0C0C0, 0}, {0xFFFFFF, 0}};
721 /* initialize pointer to colortable and default color table */
724 sysColorMap
= lpColorMap
;
727 internalColorMap
[0].to
= GetSysColor32 (COLOR_BTNTEXT
);
728 internalColorMap
[1].to
= GetSysColor32 (COLOR_BTNSHADOW
);
729 internalColorMap
[2].to
= GetSysColor32 (COLOR_BTNFACE
);
730 internalColorMap
[3].to
= GetSysColor32 (COLOR_BTNHIGHLIGHT
);
732 sysColorMap
= (LPCOLORMAP
)internalColorMap
;
735 hRsrc
= FindResource32A (hInstance
, (LPSTR
)idBitmap
, RT_BITMAP32A
);
738 hglb
= LoadResource32 (hInstance
, hRsrc
);
741 lpBitmap
= (LPBITMAPINFOHEADER
)LockResource32 (hglb
);
742 if (lpBitmap
== NULL
)
745 nColorTableSize
= (1 << lpBitmap
->biBitCount
);
746 nSize
= lpBitmap
->biSize
+ nColorTableSize
* sizeof(RGBQUAD
);
747 lpBitmapInfo
= (LPBITMAPINFOHEADER
)GlobalAlloc32 (GMEM_FIXED
, nSize
);
748 if (lpBitmapInfo
== NULL
)
750 RtlMoveMemory (lpBitmapInfo
, lpBitmap
, nSize
);
752 pColorTable
= (DWORD
*)(((LPBYTE
)lpBitmapInfo
)+(UINT32
)lpBitmapInfo
->biSize
);
754 for (iColor
= 0; iColor
< nColorTableSize
; iColor
++) {
755 for (i
= 0; i
< iMaps
; i
++) {
756 if (pColorTable
[iColor
] == sysColorMap
[i
].from
) {
758 if (wFlags
& CBS_MASKED
) {
759 if (sysColorMap
[i
].to
!= COLOR_BTNTEXT
)
760 pColorTable
[iColor
] = RGB(255, 255, 255);
764 pColorTable
[iColor
] = sysColorMap
[i
].to
;
770 nWidth
= (INT32
)lpBitmapInfo
->biWidth
;
771 nHeight
= (INT32
)lpBitmapInfo
->biHeight
;
772 hdcScreen
= GetDC32 ((HWND32
)0);
773 hbm
= CreateCompatibleBitmap32 (hdcScreen
, nWidth
, nHeight
);
775 HDC32 hdcDst
= CreateCompatibleDC32 (hdcScreen
);
776 HBITMAP32 hbmOld
= SelectObject32 (hdcDst
, hbm
);
777 LPBYTE lpBits
= (LPBYTE
)(lpBitmap
+ 1);
778 lpBits
+= (1 << (lpBitmapInfo
->biBitCount
)) * sizeof(RGBQUAD
);
779 StretchDIBits32 (hdcDst
, 0, 0, nWidth
, nHeight
, 0, 0, nWidth
, nHeight
,
780 lpBits
, (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
,
782 SelectObject32 (hdcDst
, hbmOld
);
785 ReleaseDC32 ((HWND32
)0, hdcScreen
);
786 GlobalFree32 ((HGLOBAL32
)lpBitmapInfo
);
787 FreeResource32 (hglb
);
793 /***********************************************************************
794 * CreateToolbar [COMCTL32.7] Creates a tool bar control
807 * Success: handle to the tool bar control
811 * Do not use this functions anymore. Use CreateToolbarEx instead.
815 CreateToolbar (HWND32 hwnd
, DWORD style
, UINT32 wID
, INT32 nBitmaps
,
816 HINSTANCE32 hBMInst
, UINT32 wBMID
,
817 LPCOLDTBBUTTON lpButtons
,INT32 iNumButtons
)
819 return CreateToolbarEx (hwnd
, style
| CCS_NODIVIDER
, wID
, nBitmaps
,
820 hBMInst
, wBMID
, (LPCTBBUTTON
)lpButtons
,
821 iNumButtons
, 0, 0, 0, 0, sizeof (OLDTBBUTTON
));
825 /***********************************************************************
826 * DllGetVersion [COMCTL32.25]
828 * Retrieves version information of the 'COMCTL32.DLL'
831 * pdvi [O] pointer to version information structure.
835 * Failure: E_INVALIDARG
838 * Returns version of a comctl32.dll from IE4.01 SP1.
842 COMCTL32_DllGetVersion (DLLVERSIONINFO
*pdvi
)
844 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) {
845 WARN (commctrl
, "wrong DLLVERSIONINFO size from app");
849 pdvi
->dwMajorVersion
= 4;
850 pdvi
->dwMinorVersion
= 72;
851 pdvi
->dwBuildNumber
= 3110;
852 pdvi
->dwPlatformID
= 1;
854 TRACE (commctrl
, "%lu.%lu.%lu.%lu\n",
855 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
856 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);