Cooker
August 21st, 2004, 10:37 PM
Hello,
I create a toolbar and three buttons,and I would like to add text on buttons.
But i find the text is truncated.
I want to make the whole text on buttons.
How shall I do it???
Thanks a lot! :)
#define NUM_BUTTONS 3
#define MAX_LEN 128
HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
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);
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 = -1;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].idCommand = ID_FILE_NEW;
tbb[0].iString = (int)iNew;
tbb[1].iBitmap = -1;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].idCommand = ID_FILE_OPEN;
tbb[1].iString = (int)iOpen;
tbb[2].iBitmap = -1;
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;
}
I create a toolbar and three buttons,and I would like to add text on buttons.
But i find the text is truncated.
I want to make the whole text on buttons.
How shall I do it???
Thanks a lot! :)
#define NUM_BUTTONS 3
#define MAX_LEN 128
HWND CreateAToolBar(HWND hwndParent)
{
HWND hwndTB;
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);
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 = -1;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].idCommand = ID_FILE_NEW;
tbb[0].iString = (int)iNew;
tbb[1].iBitmap = -1;
tbb[1].fsState = TBSTATE_ENABLED;
tbb[1].fsStyle = TBSTYLE_BUTTON;
tbb[1].idCommand = ID_FILE_OPEN;
tbb[1].iString = (int)iOpen;
tbb[2].iBitmap = -1;
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;
}