Click to See Complete Forum and Search --> : Toolbar buttons:bitmap + text


Cooker
August 21st, 2004, 06:47 AM
Hello,
I creat a toolbar and buttons with bitmap and text.
I would like to make the text next to the buttons,not below the buttons.
But i don't know why the program make the text below the buttons.
The source code:

#define NUM_BUTTONS 3
#define MAX_LEN 128
HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
TBADDBITMAP tbab;
TBBUTTON tbb[NUM_BUTTONS];
INITCOMMONCONTROLSEX icex;
char szBuf[MAX_LEN] ;
int cch;
int iNew, iOpen, iSaveas;



// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
tbab.hInst = GetModuleHandle(NULL);
tbab.nID = IDR_TOOLBAR1;

// 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 = HINST_COMMCTRL;
tbab.nID = IDB_STD_SMALL_COLOR;
SendMessage(hwndTB, TB_ADDBITMAP, 0, (LPARAM)&tbab);


LoadString(GetModuleHandle(NULL), IDS_NEW, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iNew = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);

LoadString(GetModuleHandle(NULL), IDS_OPEN, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iOpen = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);


LoadString(GetModuleHandle(NULL), IDS_SAVEAS, szBuf, MAX_LEN-1);
cch = strlen(szBuf);
szBuf[cch+1] = '\0';
iSaveas = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf);


ZeroMemory(tbb, sizeof(tbb));
tbb[0].iBitmap = STD_FILENEW;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].idCommand = ID_FILE_NEW;
tbb[0].iString = (int)iNew;

tbb[1].iBitmap = STD_FILEOPEN;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].idCommand = ID_FILE_OPEN;
tbb[1].iString = (int)iOpen;

tbb[2].iBitmap = STD_FILESAVE;
tbb[2].fsState = TBSTATE_ENABLED;
tbb[2].fsStyle = TBSTYLE_BUTTON;
tbb[2].idCommand = ID_FILE_SAVEAS;
tbb[2].iString = (int)iSaveas;

SendMessage(hwndTB, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
return hwndTB;

}

How do i modify the program???
Thanks a lot! :)
The project is attached.

Cooker
August 21st, 2004, 10:28 PM
Add the TBSTYTLE_LIST

hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER |TBSTYTLE_LIST , 0, 0, 0, 0, hwndParent,
(HMENU) IDR_TOOLBAR1, GetModuleHandle(NULL), NULL);

ShelleyWang
August 22nd, 2004, 02:12 AM
Add the TBSTYTLE_LIST

hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER |TBSTYTLE_LIST , 0, 0, 0, 0, hwndParent,
(HMENU) IDR_TOOLBAR1, GetModuleHandle(NULL), NULL);

should be TBSTYLE_LIST not TBSTYTLE_LIST

Cooker
August 22nd, 2004, 02:21 AM
should be TBSTYLE_LIST not TBSTYTLE_LIST
Sorry,I type wrongly. :cry: