Don't return overflow if no class buffer was specified.
[wine/dcerpc.git] / dlls / comctl32 / commctrl.c
blob1a999b729ba1fa8a3f11419c8b93f58dce18e723
1 /*
2 * Common controls functions
4 * Copyright 1997 Dimitrie O. Paun
5 * Copyright 1998,2000 Eric Kohl
7 */
9 #include <string.h>
10 #include <stdlib.h>
12 #include "winbase.h"
13 #include "commctrl.h"
14 #include "winerror.h"
15 #include "winreg.h"
16 #define NO_SHLWAPI_STREAM
17 #include "shlwapi.h"
18 #include "comctl32.h"
19 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(commctrl);
23 extern void ANIMATE_Register(void);
24 extern void ANIMATE_Unregister(void);
25 extern void COMBOEX_Register(void);
26 extern void COMBOEX_Unregister(void);
27 extern void DATETIME_Register(void);
28 extern void DATETIME_Unregister(void);
29 extern void FLATSB_Register(void);
30 extern void FLATSB_Unregister(void);
31 extern void HEADER_Register(void);
32 extern void HEADER_Unregister(void);
33 extern void HOTKEY_Register(void);
34 extern void HOTKEY_Unregister(void);
35 extern void IPADDRESS_Register(void);
36 extern void IPADDRESS_Unregister(void);
37 extern void LISTVIEW_Register(void);
38 extern void LISTVIEW_Unregister(void);
39 extern void MONTHCAL_Register(void);
40 extern void MONTHCAL_Unregister(void);
41 extern void NATIVEFONT_Register(void);
42 extern void NATIVEFONT_Unregister(void);
43 extern void PAGER_Register(void);
44 extern void PAGER_Unregister(void);
45 extern void PROGRESS_Register(void);
46 extern void PROGRESS_Unregister(void);
47 extern void REBAR_Register(void);
48 extern void REBAR_Unregister(void);
49 extern void STATUS_Register(void);
50 extern void STATUS_Unregister(void);
51 extern void TAB_Register(void);
52 extern void TAB_Unregister(void);
53 extern void TOOLBAR_Register(void);
54 extern void TOOLBAR_Unregister(void);
55 extern void TOOLTIPS_Register(void);
56 extern void TOOLTIPS_Unregister(void);
57 extern void TRACKBAR_Register(void);
58 extern void TRACKBAR_Unregister(void);
59 extern void TREEVIEW_Register(void);
60 extern void TREEVIEW_Unregister(void);
61 extern void UPDOWN_Register(void);
62 extern void UPDOWN_Unregister(void);
65 HANDLE COMCTL32_hHeap = (HANDLE)NULL;
66 LPSTR COMCTL32_aSubclass = (LPSTR)NULL;
67 HMODULE COMCTL32_hModule = 0;
68 LANGID COMCTL32_uiLang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
69 HBRUSH COMCTL32_hPattern55AABrush = (HANDLE)NULL;
71 static HBITMAP COMCTL32_hPattern55AABitmap = (HANDLE)NULL;
73 static const WORD wPattern55AA[] =
75 0x5555, 0xaaaa, 0x5555, 0xaaaa,
76 0x5555, 0xaaaa, 0x5555, 0xaaaa
80 /***********************************************************************
81 * COMCTL32_LibMain [Internal] Initializes the internal 'COMCTL32.DLL'.
83 * PARAMS
84 * hinstDLL [I] handle to the 'dlls' instance
85 * fdwReason [I]
86 * lpvReserved [I] reserverd, must be NULL
88 * RETURNS
89 * Success: TRUE
90 * Failure: FALSE
93 BOOL WINAPI
94 COMCTL32_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
96 TRACE("%x,%lx,%p\n", hinstDLL, fdwReason, lpvReserved);
98 switch (fdwReason) {
99 case DLL_PROCESS_ATTACH:
100 COMCTL32_hModule = (HMODULE)hinstDLL;
102 /* create private heap */
103 COMCTL32_hHeap = HeapCreate (0, 0x10000, 0);
104 TRACE("Heap created: 0x%x\n", COMCTL32_hHeap);
106 /* add global subclassing atom (used by 'tooltip' and 'updown') */
107 COMCTL32_aSubclass = (LPSTR)(DWORD)GlobalAddAtomA ("CC32SubclassInfo");
108 TRACE("Subclassing atom added: %p\n", COMCTL32_aSubclass);
110 /* create local pattern brush */
111 COMCTL32_hPattern55AABitmap = CreateBitmap (8, 8, 1, 1, wPattern55AA);
112 COMCTL32_hPattern55AABrush = CreatePatternBrush (COMCTL32_hPattern55AABitmap);
114 /* register all Win95 common control classes */
115 ANIMATE_Register ();
116 FLATSB_Register ();
117 HEADER_Register ();
118 HOTKEY_Register ();
119 LISTVIEW_Register ();
120 PROGRESS_Register ();
121 STATUS_Register ();
122 TAB_Register ();
123 TOOLBAR_Register ();
124 TOOLTIPS_Register ();
125 TRACKBAR_Register ();
126 TREEVIEW_Register ();
127 UPDOWN_Register ();
128 break;
130 case DLL_PROCESS_DETACH:
131 /* unregister all common control classes */
132 ANIMATE_Unregister ();
133 COMBOEX_Unregister ();
134 DATETIME_Unregister ();
135 FLATSB_Unregister ();
136 HEADER_Unregister ();
137 HOTKEY_Unregister ();
138 IPADDRESS_Unregister ();
139 LISTVIEW_Unregister ();
140 MONTHCAL_Unregister ();
141 NATIVEFONT_Unregister ();
142 PAGER_Unregister ();
143 PROGRESS_Unregister ();
144 REBAR_Unregister ();
145 STATUS_Unregister ();
146 TAB_Unregister ();
147 TOOLBAR_Unregister ();
148 TOOLTIPS_Unregister ();
149 TRACKBAR_Unregister ();
150 TREEVIEW_Unregister ();
151 UPDOWN_Unregister ();
153 /* delete local pattern brush */
154 DeleteObject (COMCTL32_hPattern55AABrush);
155 COMCTL32_hPattern55AABrush = (HANDLE)NULL;
156 DeleteObject (COMCTL32_hPattern55AABitmap);
157 COMCTL32_hPattern55AABitmap = (HANDLE)NULL;
159 /* delete global subclassing atom */
160 GlobalDeleteAtom (LOWORD(COMCTL32_aSubclass));
161 TRACE("Subclassing atom deleted: %p\n", COMCTL32_aSubclass);
162 COMCTL32_aSubclass = (LPSTR)NULL;
164 /* destroy private heap */
165 HeapDestroy (COMCTL32_hHeap);
166 TRACE("Heap destroyed: 0x%x\n", COMCTL32_hHeap);
167 COMCTL32_hHeap = (HANDLE)NULL;
168 break;
171 return TRUE;
175 /***********************************************************************
176 * MenuHelp [COMCTL32.2]
178 * PARAMS
179 * uMsg [I] message (WM_MENUSELECT) (see NOTES)
180 * wParam [I] wParam of the message uMsg
181 * lParam [I] lParam of the message uMsg
182 * hMainMenu [I] handle to the application's main menu
183 * hInst [I] handle to the module that contains string resources
184 * hwndStatus [I] handle to the status bar window
185 * lpwIDs [I] pointer to an array of integers (see NOTES)
187 * RETURNS
188 * No return value
190 * NOTES
191 * The official documentation is incomplete!
192 * This is the correct documentation:
194 * uMsg:
195 * MenuHelp() does NOT handle WM_COMMAND messages! It only handles
196 * WM_MENUSELECT messages.
198 * lpwIDs:
199 * (will be written ...)
202 VOID WINAPI
203 MenuHelp (UINT uMsg, WPARAM wParam, LPARAM lParam, HMENU hMainMenu,
204 HINSTANCE hInst, HWND hwndStatus, LPUINT lpwIDs)
206 UINT uMenuID = 0;
208 if (!IsWindow (hwndStatus))
209 return;
211 switch (uMsg) {
212 case WM_MENUSELECT:
213 TRACE("WM_MENUSELECT wParam=0x%X lParam=0x%lX\n",
214 wParam, lParam);
216 if ((HIWORD(wParam) == 0xFFFF) && (lParam == 0)) {
217 /* menu was closed */
218 TRACE("menu was closed!\n");
219 SendMessageA (hwndStatus, SB_SIMPLE, FALSE, 0);
221 else {
222 /* menu item was selected */
223 if (HIWORD(wParam) & MF_POPUP)
224 uMenuID = (UINT)*(lpwIDs+1);
225 else
226 uMenuID = (UINT)LOWORD(wParam);
227 TRACE("uMenuID = %u\n", uMenuID);
229 if (uMenuID) {
230 CHAR szText[256];
232 if (!LoadStringA (hInst, uMenuID, szText, 256))
233 szText[0] = '\0';
235 SendMessageA (hwndStatus, SB_SETTEXTA,
236 255 | SBT_NOBORDERS, (LPARAM)szText);
237 SendMessageA (hwndStatus, SB_SIMPLE, TRUE, 0);
240 break;
242 case WM_COMMAND :
243 TRACE("WM_COMMAND wParam=0x%X lParam=0x%lX\n",
244 wParam, lParam);
245 /* WM_COMMAND is not invalid since it is documented
246 * in the windows api reference. So don't output
247 * any FIXME for WM_COMMAND
249 WARN("We don't care about the WM_COMMAND\n");
250 break;
252 default:
253 FIXME("Invalid Message 0x%x!\n", uMsg);
254 break;
259 /***********************************************************************
260 * ShowHideMenuCtl [COMCTL32.3]
262 * Shows or hides controls and updates the corresponding menu item.
264 * PARAMS
265 * hwnd [I] handle to the client window.
266 * uFlags [I] menu command id.
267 * lpInfo [I] pointer to an array of integers. (See NOTES.)
269 * RETURNS
270 * Success: TRUE
271 * Failure: FALSE
273 * NOTES
274 * The official documentation is incomplete!
275 * This is the correct documentation:
277 * hwnd
278 * Handle to the window that contains the menu and controls.
280 * uFlags
281 * Identifier of the menu item to receive or loose a check mark.
283 * lpInfo
284 * The array of integers contains pairs of values. BOTH values of
285 * the first pair must be the handles to the application's main menu.
286 * Each subsequent pair consists of a menu id and control id.
289 BOOL WINAPI
290 ShowHideMenuCtl (HWND hwnd, UINT uFlags, LPINT lpInfo)
292 LPINT lpMenuId;
294 TRACE("%x, %x, %p\n", hwnd, uFlags, lpInfo);
296 if (lpInfo == NULL)
297 return FALSE;
299 if (!(lpInfo[0]) || !(lpInfo[1]))
300 return FALSE;
302 /* search for control */
303 lpMenuId = &lpInfo[2];
304 while (*lpMenuId != uFlags)
305 lpMenuId += 2;
307 if (GetMenuState (lpInfo[1], uFlags, MF_BYCOMMAND) & MFS_CHECKED) {
308 /* uncheck menu item */
309 CheckMenuItem (lpInfo[0], *lpMenuId, MF_BYCOMMAND | MF_UNCHECKED);
311 /* hide control */
312 lpMenuId++;
313 SetWindowPos (GetDlgItem (hwnd, *lpMenuId), 0, 0, 0, 0, 0,
314 SWP_HIDEWINDOW);
316 else {
317 /* check menu item */
318 CheckMenuItem (lpInfo[0], *lpMenuId, MF_BYCOMMAND | MF_CHECKED);
320 /* show control */
321 lpMenuId++;
322 SetWindowPos (GetDlgItem (hwnd, *lpMenuId), 0, 0, 0, 0, 0,
323 SWP_SHOWWINDOW);
326 return TRUE;
330 /***********************************************************************
331 * GetEffectiveClientRect [COMCTL32.4]
333 * PARAMS
334 * hwnd [I] handle to the client window.
335 * lpRect [O] pointer to the rectangle of the client window
336 * lpInfo [I] pointer to an array of integers (see NOTES)
338 * RETURNS
339 * No return value.
341 * NOTES
342 * The official documentation is incomplete!
343 * This is the correct documentation:
345 * lpInfo
346 * (will be written...)
349 VOID WINAPI
350 GetEffectiveClientRect (HWND hwnd, LPRECT lpRect, LPINT lpInfo)
352 RECT rcCtrl;
353 INT *lpRun;
354 HWND hwndCtrl;
356 TRACE("(0x%08lx 0x%08lx 0x%08lx)\n",
357 (DWORD)hwnd, (DWORD)lpRect, (DWORD)lpInfo);
359 GetClientRect (hwnd, lpRect);
360 lpRun = lpInfo;
362 do {
363 lpRun += 2;
364 if (*lpRun == 0)
365 return;
366 lpRun++;
367 hwndCtrl = GetDlgItem (hwnd, *lpRun);
368 if (GetWindowLongA (hwndCtrl, GWL_STYLE) & WS_VISIBLE) {
369 TRACE("control id 0x%x\n", *lpRun);
370 GetWindowRect (hwndCtrl, &rcCtrl);
371 MapWindowPoints ((HWND)0, hwnd, (LPPOINT)&rcCtrl, 2);
372 SubtractRect (lpRect, lpRect, &rcCtrl);
374 lpRun++;
375 } while (*lpRun);
379 /***********************************************************************
380 * DrawStatusTextW [COMCTL32.28]
382 * Draws text with borders, like in a status bar.
384 * PARAMS
385 * hdc [I] handle to the window's display context
386 * lprc [I] pointer to a rectangle
387 * text [I] pointer to the text
388 * style [I] drawing style
390 * RETURNS
391 * No return value.
393 * NOTES
394 * The style variable can have one of the following values:
395 * (will be written ...)
398 VOID WINAPI
399 DrawStatusTextW (HDC hdc, LPRECT lprc, LPCWSTR text, UINT style)
401 RECT r = *lprc;
402 UINT border = BDR_SUNKENOUTER;
404 if (style & SBT_POPOUT)
405 border = BDR_RAISEDOUTER;
406 else if (style & SBT_NOBORDERS)
407 border = 0;
409 DrawEdge (hdc, &r, border, BF_RECT|BF_ADJUST|BF_MIDDLE);
411 /* now draw text */
412 if (text) {
413 int oldbkmode = SetBkMode (hdc, TRANSPARENT);
414 r.left += 3;
415 DrawTextW (hdc, text, lstrlenW(text),
416 &r, DT_LEFT|DT_VCENTER|DT_SINGLELINE);
417 if (oldbkmode != TRANSPARENT)
418 SetBkMode(hdc, oldbkmode);
423 /***********************************************************************
424 * DrawStatusText [COMCTL32.27]
425 * DrawStatusTextA [COMCTL32.5]
427 * Draws text with borders, like in a status bar.
429 * PARAMS
430 * hdc [I] handle to the window's display context
431 * lprc [I] pointer to a rectangle
432 * text [I] pointer to the text
433 * style [I] drawing style
435 * RETURNS
436 * No return value.
439 VOID WINAPI
440 DrawStatusTextA (HDC hdc, LPRECT lprc, LPCSTR text, UINT style)
442 INT len;
443 LPWSTR textW = NULL;
445 if ( text ) {
446 if ( (len = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 )) ) {
447 if ( (textW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )) )
448 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, len );
451 DrawStatusTextW( hdc, lprc, textW, style );
452 HeapFree( GetProcessHeap(), 0, textW );
456 /***********************************************************************
457 * CreateStatusWindow [COMCTL32.21]
458 * CreateStatusWindowA [COMCTL32.6]
460 * Creates a status bar
462 * PARAMS
463 * style [I] window style
464 * text [I] pointer to the window text
465 * parent [I] handle to the parent window
466 * wid [I] control id of the status bar
468 * RETURNS
469 * Success: handle to the status window
470 * Failure: 0
473 HWND WINAPI
474 CreateStatusWindowA (INT style, LPCSTR text, HWND parent, UINT wid)
476 return CreateWindowA(STATUSCLASSNAMEA, text, style,
477 CW_USEDEFAULT, CW_USEDEFAULT,
478 CW_USEDEFAULT, CW_USEDEFAULT,
479 parent, wid, 0, 0);
483 /***********************************************************************
484 * CreateStatusWindowW [COMCTL32.22] Creates a status bar control
486 * PARAMS
487 * style [I] window style
488 * text [I] pointer to the window text
489 * parent [I] handle to the parent window
490 * wid [I] control id of the status bar
492 * RETURNS
493 * Success: handle to the status window
494 * Failure: 0
497 HWND WINAPI
498 CreateStatusWindowW (INT style, LPCWSTR text, HWND parent, UINT wid)
500 return CreateWindowW(STATUSCLASSNAMEW, text, style,
501 CW_USEDEFAULT, CW_USEDEFAULT,
502 CW_USEDEFAULT, CW_USEDEFAULT,
503 parent, wid, 0, 0);
507 /***********************************************************************
508 * CreateUpDownControl [COMCTL32.16] Creates an up-down control
510 * PARAMS
511 * style [I] window styles
512 * x [I] horizontal position of the control
513 * y [I] vertical position of the control
514 * cx [I] with of the control
515 * cy [I] height of the control
516 * parent [I] handle to the parent window
517 * id [I] the control's identifier
518 * inst [I] handle to the application's module instance
519 * buddy [I] handle to the buddy window, can be NULL
520 * maxVal [I] upper limit of the control
521 * minVal [I] lower limit of the control
522 * curVal [I] current value of the control
524 * RETURNS
525 * Success: handle to the updown control
526 * Failure: 0
529 HWND WINAPI
530 CreateUpDownControl (DWORD style, INT x, INT y, INT cx, INT cy,
531 HWND parent, INT id, HINSTANCE inst,
532 HWND buddy, INT maxVal, INT minVal, INT curVal)
534 HWND hUD =
535 CreateWindowA (UPDOWN_CLASSA, 0, style, x, y, cx, cy,
536 parent, id, inst, 0);
537 if (hUD) {
538 SendMessageA (hUD, UDM_SETBUDDY, buddy, 0);
539 SendMessageA (hUD, UDM_SETRANGE, 0, MAKELONG(maxVal, minVal));
540 SendMessageA (hUD, UDM_SETPOS, 0, MAKELONG(curVal, 0));
543 return hUD;
547 /***********************************************************************
548 * InitCommonControls [COMCTL32.17]
550 * Registers the common controls.
552 * PARAMS
553 * No parameters.
555 * RETURNS
556 * No return values.
558 * NOTES
559 * This function is just a dummy.
560 * The Win95 controls are registered at the DLL's initialization.
561 * To register other controls InitCommonControlsEx() must be used.
564 VOID WINAPI
565 InitCommonControls (void)
570 /***********************************************************************
571 * InitCommonControlsEx [COMCTL32.84]
573 * Registers the common controls.
575 * PARAMS
576 * lpInitCtrls [I] pointer to an INITCOMMONCONTROLS structure.
578 * RETURNS
579 * Success: TRUE
580 * Failure: FALSE
582 * NOTES
583 * Only the additional common controls are registered by this function.
584 * The Win95 controls are registered at the DLL's initialization.
587 BOOL WINAPI
588 InitCommonControlsEx (LPINITCOMMONCONTROLSEX lpInitCtrls)
590 INT cCount;
591 DWORD dwMask;
593 if (!lpInitCtrls)
594 return FALSE;
595 if (lpInitCtrls->dwSize != sizeof(INITCOMMONCONTROLSEX))
596 return FALSE;
598 TRACE("(0x%08lx)\n", lpInitCtrls->dwICC);
600 for (cCount = 0; cCount < 32; cCount++) {
601 dwMask = 1 << cCount;
602 if (!(lpInitCtrls->dwICC & dwMask))
603 continue;
605 switch (lpInitCtrls->dwICC & dwMask) {
606 /* dummy initialization */
607 case ICC_ANIMATE_CLASS:
608 case ICC_BAR_CLASSES:
609 case ICC_LISTVIEW_CLASSES:
610 case ICC_TREEVIEW_CLASSES:
611 case ICC_TAB_CLASSES:
612 case ICC_UPDOWN_CLASS:
613 case ICC_PROGRESS_CLASS:
614 case ICC_HOTKEY_CLASS:
615 break;
617 /* advanced classes - not included in Win95 */
618 case ICC_DATE_CLASSES:
619 MONTHCAL_Register ();
620 DATETIME_Register ();
621 break;
623 case ICC_USEREX_CLASSES:
624 COMBOEX_Register ();
625 break;
627 case ICC_COOL_CLASSES:
628 REBAR_Register ();
629 break;
631 case ICC_INTERNET_CLASSES:
632 IPADDRESS_Register ();
633 break;
635 case ICC_PAGESCROLLER_CLASS:
636 PAGER_Register ();
637 break;
639 case ICC_NATIVEFNTCTL_CLASS:
640 NATIVEFONT_Register ();
641 break;
643 default:
644 FIXME("Unknown class! dwICC=0x%lX\n", dwMask);
645 break;
649 return TRUE;
653 /***********************************************************************
654 * CreateToolbarEx [COMCTL32.23] Creates a tool bar window
656 * PARAMS
657 * hwnd
658 * style
659 * wID
660 * nBitmaps
661 * hBMInst
662 * wBMID
663 * lpButtons
664 * iNumButtons
665 * dxButton
666 * dyButton
667 * dxBitmap
668 * dyBitmap
669 * uStructSize
671 * RETURNS
672 * Success: handle to the tool bar control
673 * Failure: 0
676 HWND WINAPI
677 CreateToolbarEx (HWND hwnd, DWORD style, UINT wID, INT nBitmaps,
678 HINSTANCE hBMInst, UINT wBMID, LPCTBBUTTON lpButtons,
679 INT iNumButtons, INT dxButton, INT dyButton,
680 INT dxBitmap, INT dyBitmap, UINT uStructSize)
682 HWND hwndTB;
684 /* If not position is specified then put it at the top */
685 if ((style & CCS_BOTTOM) == 0) {
686 style|=CCS_TOP;
689 hwndTB =
690 CreateWindowExA (0, TOOLBARCLASSNAMEA, "", style|WS_CHILD, 0, 0, 0, 0,
691 hwnd, (HMENU)wID, 0, NULL);
692 if(hwndTB) {
693 TBADDBITMAP tbab;
695 SendMessageA (hwndTB, TB_BUTTONSTRUCTSIZE,
696 (WPARAM)uStructSize, 0);
698 /* set bitmap and button size */
699 /*If CreateToolbarEx receives 0, windows sets default values*/
700 if (dxBitmap <= 0)
701 dxBitmap = 16;
702 if (dyBitmap <= 0)
703 dyBitmap = 15;
704 SendMessageA (hwndTB, TB_SETBITMAPSIZE, 0,
705 MAKELPARAM((WORD)dxBitmap, (WORD)dyBitmap));
707 if (dxButton <= 0)
708 dxButton = 24;
709 if (dyButton <= 0)
710 dyButton = 22;
711 SendMessageA (hwndTB, TB_SETBUTTONSIZE, 0,
712 MAKELPARAM((WORD)dxButton, (WORD)dyButton));
715 /* add bitmaps */
716 if (nBitmaps > 0)
718 tbab.hInst = hBMInst;
719 tbab.nID = wBMID;
721 SendMessageA (hwndTB, TB_ADDBITMAP,
722 (WPARAM)nBitmaps, (LPARAM)&tbab);
724 /* add buttons */
725 if(iNumButtons > 0)
726 SendMessageA (hwndTB, TB_ADDBUTTONSA,
727 (WPARAM)iNumButtons, (LPARAM)lpButtons);
730 return hwndTB;
734 /***********************************************************************
735 * CreateMappedBitmap [COMCTL32.8]
737 * PARAMS
738 * hInstance [I]
739 * idBitmap [I]
740 * wFlags [I]
741 * lpColorMap [I]
742 * iNumMaps [I]
744 * RETURNS
745 * Success: handle to the new bitmap
746 * Failure: 0
749 HBITMAP WINAPI
750 CreateMappedBitmap (HINSTANCE hInstance, INT idBitmap, UINT wFlags,
751 LPCOLORMAP lpColorMap, INT iNumMaps)
753 HGLOBAL hglb;
754 HRSRC hRsrc;
755 LPBITMAPINFOHEADER lpBitmap, lpBitmapInfo;
756 UINT nSize, nColorTableSize;
757 RGBQUAD *pColorTable;
758 INT iColor, i, iMaps, nWidth, nHeight;
759 HDC hdcScreen;
760 HBITMAP hbm;
761 LPCOLORMAP sysColorMap;
762 COLORREF cRef;
763 COLORMAP internalColorMap[4] =
764 {{0x000000, 0}, {0x808080, 0}, {0xC0C0C0, 0}, {0xFFFFFF, 0}};
766 /* initialize pointer to colortable and default color table */
767 if (lpColorMap) {
768 iMaps = iNumMaps;
769 sysColorMap = lpColorMap;
771 else {
772 internalColorMap[0].to = GetSysColor (COLOR_BTNTEXT);
773 internalColorMap[1].to = GetSysColor (COLOR_BTNSHADOW);
774 internalColorMap[2].to = GetSysColor (COLOR_BTNFACE);
775 internalColorMap[3].to = GetSysColor (COLOR_BTNHIGHLIGHT);
776 iMaps = 4;
777 sysColorMap = (LPCOLORMAP)internalColorMap;
780 hRsrc = FindResourceA (hInstance, (LPSTR)idBitmap, RT_BITMAPA);
781 if (hRsrc == 0)
782 return 0;
783 hglb = LoadResource (hInstance, hRsrc);
784 if (hglb == 0)
785 return 0;
786 lpBitmap = (LPBITMAPINFOHEADER)LockResource (hglb);
787 if (lpBitmap == NULL)
788 return 0;
790 nColorTableSize = (1 << lpBitmap->biBitCount);
791 nSize = lpBitmap->biSize + nColorTableSize * sizeof(RGBQUAD);
792 lpBitmapInfo = (LPBITMAPINFOHEADER)GlobalAlloc (GMEM_FIXED, nSize);
793 if (lpBitmapInfo == NULL)
794 return 0;
795 RtlMoveMemory (lpBitmapInfo, lpBitmap, nSize);
797 pColorTable = (RGBQUAD*)(((LPBYTE)lpBitmapInfo)+(UINT)lpBitmapInfo->biSize);
799 for (iColor = 0; iColor < nColorTableSize; iColor++) {
800 for (i = 0; i < iMaps; i++) {
801 cRef = RGB(pColorTable[iColor].rgbRed,
802 pColorTable[iColor].rgbGreen,
803 pColorTable[iColor].rgbBlue);
804 if ( cRef == sysColorMap[i].from) {
805 #if 0
806 if (wFlags & CBS_MASKED) {
807 if (sysColorMap[i].to != COLOR_BTNTEXT)
808 pColorTable[iColor] = RGB(255, 255, 255);
810 else
811 #endif
812 pColorTable[iColor].rgbBlue = GetBValue(sysColorMap[i].to);
813 pColorTable[iColor].rgbGreen = GetGValue(sysColorMap[i].to);
814 pColorTable[iColor].rgbRed = GetRValue(sysColorMap[i].to);
815 break;
819 nWidth = (INT)lpBitmapInfo->biWidth;
820 nHeight = (INT)lpBitmapInfo->biHeight;
821 hdcScreen = GetDC ((HWND)0);
822 hbm = CreateCompatibleBitmap (hdcScreen, nWidth, nHeight);
823 if (hbm) {
824 HDC hdcDst = CreateCompatibleDC (hdcScreen);
825 HBITMAP hbmOld = SelectObject (hdcDst, hbm);
826 LPBYTE lpBits = (LPBYTE)(lpBitmap + 1);
827 lpBits += (1 << (lpBitmapInfo->biBitCount)) * sizeof(RGBQUAD);
828 StretchDIBits (hdcDst, 0, 0, nWidth, nHeight, 0, 0, nWidth, nHeight,
829 lpBits, (LPBITMAPINFO)lpBitmapInfo, DIB_RGB_COLORS,
830 SRCCOPY);
831 SelectObject (hdcDst, hbmOld);
832 DeleteDC (hdcDst);
834 ReleaseDC ((HWND)0, hdcScreen);
835 GlobalFree ((HGLOBAL)lpBitmapInfo);
836 FreeResource (hglb);
838 return hbm;
842 /***********************************************************************
843 * CreateToolbar [COMCTL32.7] Creates a tool bar control
845 * PARAMS
846 * hwnd
847 * style
848 * wID
849 * nBitmaps
850 * hBMInst
851 * wBMID
852 * lpButtons
853 * iNumButtons
855 * RETURNS
856 * Success: handle to the tool bar control
857 * Failure: 0
859 * NOTES
860 * Do not use this functions anymore. Use CreateToolbarEx instead.
863 HWND WINAPI
864 CreateToolbar (HWND hwnd, DWORD style, UINT wID, INT nBitmaps,
865 HINSTANCE hBMInst, UINT wBMID,
866 LPCOLDTBBUTTON lpButtons,INT iNumButtons)
868 return CreateToolbarEx (hwnd, style | CCS_NODIVIDER, wID, nBitmaps,
869 hBMInst, wBMID, (LPCTBBUTTON)lpButtons,
870 iNumButtons, 0, 0, 0, 0, sizeof (OLDTBBUTTON));
874 /***********************************************************************
875 * DllGetVersion [COMCTL32.25]
877 * Retrieves version information of the 'COMCTL32.DLL'
879 * PARAMS
880 * pdvi [O] pointer to version information structure.
882 * RETURNS
883 * Success: S_OK
884 * Failure: E_INVALIDARG
886 * NOTES
887 * Returns version of a comctl32.dll from IE4.01 SP1.
890 HRESULT WINAPI
891 COMCTL32_DllGetVersion (DLLVERSIONINFO *pdvi)
893 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) {
894 WARN("wrong DLLVERSIONINFO size from app\n");
895 return E_INVALIDARG;
898 pdvi->dwMajorVersion = COMCTL32_VERSION;
899 pdvi->dwMinorVersion = COMCTL32_VERSION_MINOR;
900 pdvi->dwBuildNumber = 2919;
901 pdvi->dwPlatformID = 6304;
903 TRACE("%lu.%lu.%lu.%lu\n",
904 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
905 pdvi->dwBuildNumber, pdvi->dwPlatformID);
907 return S_OK;
910 /***********************************************************************
911 * DllInstall (COMCTL32.26)
913 HRESULT WINAPI COMCTL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
915 FIXME("(%s, %s): stub\n", bInstall?"TRUE":"FALSE",
916 debugstr_w(cmdline));
918 return S_OK;
921 /***********************************************************************
922 * _TrackMouseEvent [COMCTL32.91]
924 * Requests notification of mouse events
926 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
927 * to the hwnd specified in the ptme structure. After the event message
928 * is posted to the hwnd, the entry in the queue is removed.
930 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
931 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
932 * immediately and the TME_LEAVE flag being ignored.
934 * PARAMS
935 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
937 * RETURNS
938 * Success: non-zero
939 * Failure: zero
941 * IMPLEMENTATION moved to USER32.TrackMouseEvent
945 BOOL WINAPI
946 _TrackMouseEvent (TRACKMOUSEEVENT *ptme)
948 return TrackMouseEvent (ptme);
951 /*************************************************************************
952 * GetMUILanguage [COMCTL32.39]
954 * FIXME: What's this supposed to do? Apparently some i18n thing.
957 LANGID WINAPI GetMUILanguage (VOID)
959 return COMCTL32_uiLang;
963 /*************************************************************************
964 * InitMUILanguage [COMCTL32.85]
966 * FIXME: What's this supposed to do? Apparently some i18n thing.
970 VOID WINAPI InitMUILanguage (LANGID uiLang)
972 COMCTL32_uiLang = uiLang;
976 /***********************************************************************
977 * COMCTL32_CreateToolTip [NOT AN API]
979 * Creates a tooltip for the control specified in hwnd and does all
980 * necessary setup and notifications.
982 * PARAMS
983 * hwndOwner [I] Handle to the window that will own the tool tip.
985 * RETURNS
986 * Success: Handle of tool tip window.
987 * Failure: NULL
989 HWND
990 COMCTL32_CreateToolTip(HWND hwndOwner)
992 HWND hwndToolTip;
994 hwndToolTip = CreateWindowExA(0, TOOLTIPS_CLASSA, NULL, 0,
995 CW_USEDEFAULT, CW_USEDEFAULT,
996 CW_USEDEFAULT, CW_USEDEFAULT, hwndOwner,
997 0, 0, 0);
999 /* Send NM_TOOLTIPSCREATED notification */
1000 if (hwndToolTip)
1002 NMTOOLTIPSCREATED nmttc;
1003 /* true owner can be different if hwndOwner is a child window */
1004 HWND hwndTrueOwner = GetWindow(hwndToolTip, GW_OWNER);
1005 nmttc.hdr.hwndFrom = hwndTrueOwner;
1006 nmttc.hdr.idFrom = GetWindowLongA(hwndTrueOwner, GWL_ID);
1007 nmttc.hdr.code = NM_TOOLTIPSCREATED;
1008 nmttc.hwndToolTips = hwndToolTip;
1010 SendMessageA(GetParent(hwndTrueOwner), WM_NOTIFY,
1011 (WPARAM)GetWindowLongA(hwndTrueOwner, GWL_ID),
1012 (LPARAM)&nmttc);
1015 return hwndToolTip;