Hi.
I have a small problem.
I want the buttons of my toolbar look like when the toolbar has the style TBSTYLE_FLAT. But when i use this style, the background becomes transparent. But i don't want the background to become transparent. How can i make a toolbar in which the buttons look like with a TBSTYLE_FLAT style but with no transparent background?
Posted on 2001-12-21 12:43:14 by darester
to say it more simply:
i want to make a toolbar with transparent buttons but not transparent background (the baxkground shall stay gray (COLOR_BTNFACE), which is the standard background color of a toolbar).
Posted on 2001-12-21 13:20:47 by darester
Hi darester,

Just went through this myself. The trick seems to be to create a Rebar control first and place your toolbar on it as a child. The rebar is the toolbar's background and is painted in a WM_PAINT messaging loop.

You should check out the latest SDK documentation on the new Comctl32.dll functions. Create a Rebar with CreateWindowEx and the "ReBarWindow32" Class Name. Then initialize the Toolbar TBBUTTON structures for each of your buttons and separators. Strings you can put in an .rc STRINGTABLE and load into the TBBUTTON.iString fields with LoadString. Then create the toolbar with



invoke CreateToolbarEx, hWnd,\
TBSTYLE_FLAT + TBSTYLE_AUTOSIZE +\
WS_CHILD + WS_VISIBLE,\
NULL,5, NULL, hToolBarBmp,\
ADDR TBButtons,0, 16, 16 , 16, 16 , SIZEOF(TBBUTTON)

mov rbi.hwndChild, eax ; hwnd to toolbar (child of rebar)


At this point you haven't added the buttons really (iNumButtons = 0). Then send a message to add the rebar and the buttons:


invoke SendMessage, hWnd_Rebar, RB_INSERTBAND, 0,ADDR rbi
invoke SendMessage, rbi.hwndChild, TB_ADDBUTTONS, 8, ADDR TBButtons


You handle painting the rebar background in the WM_PAINT message. Since it's nice to have the messaging loop working while you're messing with the rest of the code, here's a WM_PAINT routine that works with the flat style toolbar that I scammed from some source from this board ;-)



.ELSEIF uMsg == WM_PAINT

invoke BeginPaint,hWnd, OFFSET Paint_Struct
mov hDC, eax

invoke GetWindowRect, hWnd_Rebar, OFFSET Rect_Struct
mov eax, Rect_Struct.bottom
sub eax, Rect_Struct.top
push eax
invoke GetClientRect, hWnd, OFFSET Rect_Struct
pop Rect_Struct.top
invoke DrawEdge, hDC, OFFSET Rect_Struct, EDGE_SUNKEN, BF_RECT
inc Rect_Struct.top
inc Rect_Struct.left
invoke FillRect, hDC, OFFSET Rect_Struct, COLOR_BTNFACE

invoke EndPaint ,hWnd, OFFSET Paint_Struct
mov eax, TRUE
ret


You'll need to begin with declaring the ICC_COOL_CLASSES version of InitCommonControlsEx



mov icex.dwSize,sizeof INITCOMMONCONTROLSEX
mov icex.dwICC, ICC_COOL_CLASSES ; ICC_BAR_CLASSES (base class)
invoke InitCommonControlsEx,addr icex


Also, some of the more recent features such as DropDown buttons don't seem to be supported in the MASMv.7 windows.inc, so these structures would need defining.


Hope this helps,

Kayaker
Posted on 2001-12-21 16:59:56 by Kayaker
thanks a lot my friend. you really helped me out!
Posted on 2001-12-21 17:56:04 by darester
I am making my toolbar with CreateWindowEx



;---------- [Create the Toolbar Window] ----------
INVOKE CreateWindowEx, 0, addr ToolClass, 0,
WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS or CCS_NOPARENTALIGN or\
CCS_NORESIZE or CCS_ADJUSTABLE or TBSTYLE_FLAT or WS_BORDER,\
0, -2, 1200, 26, hwnd, 0, hInst, 0
.if !eax
;Do message
jmp Ret0
.endif
mov hWndTool, eax

;---------- [Create the ImageList] ----------
INVOKE ImageList_Create, 16, 16, ILC_COLOR32, 8, 0
mov hImageList, eax

;---------- [Load The Bitmaps] ----------
mov ID, 701 ; Bitmap ID start address
mov Cnt, 8 ; Number of bitmaps
.while (Cnt)
INVOKE LoadImage,hInst,ID,IMAGE_BITMAP,16,16, LR_LOADMAP3DCOLORS

;last param changes backgroundcolor
;LR_LOADMAP3DCOLORS :

; Searches the color table for the image and replaces the
;following shades of gray with the corresponding 3D color

;Color Replaced with
;Dk Gray, RGB(128,128,128) COLOR_3DSHADOW
;Gray, RGB(192,192,192) COLOR_3DFACE
;Lt Gray, RGB(223,223,223) COLOR_3DLIGHT
mov hTbBmp, eax
INVOKE ImageList_Add, hImageList, hTbBmp, NULL
INVOKE DeleteObject, hTbBmp
inc ID
dec Cnt
.endw
INVOKE SendMessage, hWndTool, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0
INVOKE SendMessage, hWndTool, TB_SETIMAGELIST, 0, hImageList

------- [Size the Bitmap and Button] ----------
mov ecx, 16 ; loword = bitmap Width
mov eax, 16 ; hiword = bitmap Height
shl eax, 16
mov ax, cx
mov bSize, eax
INVOKE SendMessage, hWndTool, TB_SETBITMAPSIZE, 0, bSize
INVOKE SendMessage, hWndTool, TB_SETBUTTONSIZE, 0, bSize

;---------- [Create the Toolbar structures] ----------
TBButt hWndTool, 0, 1001, 0
TBButt hWndTool, 1, 1002, 0
TBButt hWndTool, 2, 1003, 0
TBSep hWndTool
TBButt hWndTool, 3, 1005, 0
TBButt hWndTool, 4, 1006, 0
TBButt hWndTool, 5, 1007, 0
TBButt hWndTool, 6, 1008, 0
TBSep hWndTool
TBButt hWndTool, 7, 2001, 0




I make my button background color gray and load with this parameter.It worked on Win9x and WinXP same.Hope it helps.
Posted on 2001-12-21 18:22:32 by LaptoniC
I've found an ez way to do this with no side effects (yet).

when createing the window class use:
hbrBackground, COLOR_BTNFACE+1
Posted on 2001-12-23 23:01:25 by Guest