Click to See Complete Forum and Search --> : Mix bitmap button on toolbar


Cooker
December 20th, 2004, 12:18 AM
Hi,
I add three buttons on toolbar.
The first two are non-system-defined button bitmaps,and the third one is system-defined button bitmaps. I think the result will be result.jpg.
But I don't know why I get the result (orinin.jpg).
The CreateToolbar function:

HWND CreateToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[NUM_BUTTONS];
INITCOMMONCONTROLSEX icex;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);

// Create a toolbar.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 0, 0,
hwndParent, (HMENU) IDR_TOOLBAR1,
GetModuleHandle(NULL), NULL);

// Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);

tbab.hInst = GetModuleHandle(NULL);
tbab.nID = IDR_TOOLBAR1;

SendMessage(hwndTB, TB_ADDBITMAP, (WPARAM) NUM_BUTTONS,(LPARAM) (LPTBBUTTON) &tbab);

tbb[0].iBitmap = 0;
tbb[0].idCommand = ID_TOOLBAR_PLAY;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0L;
tbb[0].iString = 0;

tbb[1].iBitmap = 1;
tbb[1].idCommand = ID_TOOLBAR_STOP;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0L;
tbb[1].iString = 0;

tbb[2].iBitmap = STD_FILENEW;
tbb[2].idCommand = ID_TOOLBAR_FILENEW;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].dwData = 0L;
tbb[2].iString = 0;

SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS ,(LPARAM) (LPTBBUTTON) &tbb);

return hwndTB;
}

Could someone help me to modify it ?
Thank you! :)

NoHero
December 20th, 2004, 01:22 PM
I have searched through the MSDN quite a bit to find these default values, and I think I got the answer:


You use these values to specify an image index within a standard image list that was loaded with the TB_LOADIMAGES message. The index values correspond to images within standard image lists that the control creates for your convenience. The images depict actions that Windows applications commonly perform.


This was found here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/image_indexes.asp). So you need to send TB_LOADIMAGES (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/messages/tb_loadimages.asp) first so the toolbar can load the standard images into its image list. I haven't tested it out though. But I am shure it will work after this addition.

Cooker
January 12th, 2005, 10:28 AM
I have searched through the MSDN quite a bit to find these default values, and I think I got the answer:



This was found here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/image_indexes.asp). So you need to send TB_LOADIMAGES (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/messages/tb_loadimages.asp) first so the toolbar can load the standard images into its image list. I haven't tested it out though. But I am shure it will work after this addition.
Hi,
I try this:

...
SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS ,(LPARAM) (LPTBBUTTON) &tbb);

SendMessage(hwndTB, TB_LOADIMAGES, (WPARAM) IDB_STD_SMALL_COLOR, (LPARAM) (HINSTANCE) HINST_COMMCTRL );
...

But I find that the image of third button isn't the STD_FILENEW.
What shall I do?
Thank you!

NoHero
January 12th, 2005, 10:33 AM
Could you post your full code again, so I may take a look at code I can test on my own?

Cooker
January 12th, 2005, 10:40 AM
Could you post your full code again, so I may take a look at code I can test on my own?
Attacted!!

NoHero
January 12th, 2005, 10:48 AM
You must send the message to load the default images before you add the buttons! :rolleyes:


HWND CreateToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[NUM_BUTTONS];
INITCOMMONCONTROLSEX icex;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);

// Create a toolbar.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 0, 0,
hwndParent, (HMENU) IDR_TOOLBAR1,
GetModuleHandle(NULL), NULL);

// Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
SendMessage(hwndTB, TB_LOADIMAGES, (WPARAM) IDB_STD_SMALL_COLOR, (LPARAM) (HINSTANCE) HINST_COMMCTRL );

// Now let's add the buttons!

tbab.hInst = GetModuleHandle(NULL);
tbab.nID = IDR_TOOLBAR1;

SendMessage(hwndTB, TB_ADDBITMAP, (WPARAM) NUM_BUTTONS,(LPARAM) (LPTBBUTTON) &tbab);

tbb[0].iBitmap = 0;
tbb[0].idCommand = ID_TOOLBAR_PLAY;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0L;
tbb[0].iString = 0;

tbb[1].iBitmap = 1;
tbb[1].idCommand = ID_TOOLBAR_STOP;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0L;
tbb[1].iString = 0;

tbb[2].iBitmap = STD_FILENEW;
tbb[2].idCommand = ID_TOOLBAR_FILENEW;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].dwData = 0L;
tbb[2].iString = 0;

SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS ,(LPARAM) (LPTBBUTTON) &tbb);

return hwndTB;
}

Cooker
January 12th, 2005, 10:58 AM
You must send the message to load the default images before you add the buttons! :rolleyes:


HWND CreateToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[NUM_BUTTONS];
INITCOMMONCONTROLSEX icex;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);

// Create a toolbar.
hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 0, 0,
hwndParent, (HMENU) IDR_TOOLBAR1,
GetModuleHandle(NULL), NULL);

// Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility.
SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
SendMessage(hwndTB, TB_LOADIMAGES, (WPARAM) IDB_STD_SMALL_COLOR, (LPARAM) (HINSTANCE) HINST_COMMCTRL );

// Now let's add the buttons!

tbab.hInst = GetModuleHandle(NULL);
tbab.nID = IDR_TOOLBAR1;

SendMessage(hwndTB, TB_ADDBITMAP, (WPARAM) NUM_BUTTONS,(LPARAM) (LPTBBUTTON) &tbab);

tbb[0].iBitmap = 0;
tbb[0].idCommand = ID_TOOLBAR_PLAY;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0L;
tbb[0].iString = 0;

tbb[1].iBitmap = 1;
tbb[1].idCommand = ID_TOOLBAR_STOP;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].dwData = 0L;
tbb[1].iString = 0;

tbb[2].iBitmap = STD_FILENEW;
tbb[2].idCommand = ID_TOOLBAR_FILENEW;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].dwData = 0L;
tbb[2].iString = 0;

SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS ,(LPARAM) (LPTBBUTTON) &tbb);

return hwndTB;
}

Finally,the the first two images of buttion aren't the user-defined.

NoHero
January 12th, 2005, 11:06 AM
Of course.


// windows declarations
#define STD_CUT 0
#define STD_COPY 1


And the following two code peaces will be similiar:

First:


tbb[0].iBitmap = 0;
tbb[1].iBitmap = 1;


Second:


tbb[0].iBitmap = STD_CUT;
tbb[1].iBitmap = STD_COPY;


And since I cannot find any other code that loads application defined image resources, the subsystem will be use the STD_ ones. Beside the default internal one you need one you created on your own to hold application defined images.

Cooker
January 12th, 2005, 08:52 PM
Of course.


// windows declarations
#define STD_CUT 0
#define STD_COPY 1


And the following two code peaces will be similiar:

First:


tbb[0].iBitmap = 0;
tbb[1].iBitmap = 1;


Second:


tbb[0].iBitmap = STD_CUT;
tbb[1].iBitmap = STD_COPY;


And since I cannot find any other code that loads application defined image resources, the subsystem will be use the STD_ ones. Beside the default internal one you need one you created on your own to hold application defined images.
Anyway,thanks for your help!
Could someone share your experience???
Thanks!