Click to See Complete Forum and Search --> : Toolbars


HerbDX
October 17th, 2004, 09:15 AM
Sorry this may sound a bit stupid, but i'm having trouble adding buttons to my toolbar, it appears fine with this code:

rdPtr->hWndTBX = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | CCS_ADJUSTABLE | WS_VISIBLE,
rdPtr->rHo.hoX - rhPtr->rhWindowX,
rdPtr->rHo.hoY - rhPtr->rhWindowY,
rdPtr->rHo.hoImgWidth,
rdPtr->rHo.hoImgHeight,
ryPtr->ryHeditWin,
NULL,
rhPtr->rh4.rh4Instance,
NULL);


But then in my function when I try and add a button:

short WINAPI DLLExport AddButton(LPRDATA rdPtr, long param1, long param2)
{

char pszBuf[128];
memcpy(pszBuf,(const void *)param2,127);


TBBUTTON tbb[1];


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


tbb[0].iBitmap = 0;
tbb[0].idCommand = NULL;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_SEP;
tbb[0].dwData = 0;
tbb[0].iString = (int) pszBuf; // Text is in a buffer.




SendMessage(rdPtr->hWndTBX, TB_ADDBUTTONS, 1, (LPARAM) (LPTBBUTTON) &tbb);


SendMessage(rdPtr->hWndTBX, TB_AUTOSIZE, 0, 0);


return 0;
}


Absolutely nothing happens, i've messageboxed the ADDBUTTONS message and it returns true, so in theory it should show up, but it doesn't

Thanks

NoHero
October 17th, 2004, 09:25 AM
Can you reformat your message by using code tags? Otherwise I won't take a look at your code.

p.s.: there is a CreateToolbar() function in comdlg32.dll ...

HerbDX
October 17th, 2004, 09:28 AM
That function is obselete now, and CreateWindowEx works fine as I said, the button adding doesn't work.

NoHero
October 17th, 2004, 09:33 AM
tbb[0].iBitmap = 0;
tbb[0].idCommand = NULL;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_SEP;
tbb[0].dwData = 0;
tbb[0].iString = (int) pszBuf; // Text is in a buffer.




MSDN
TBSTYLE_SEP Creates a separator, providing a small gap between button groups. A button that has this style does not receive user input.


I think you should use TBSTYLE_BUTTON instead, because with the new windows style a seperator is just a space between to buttons. So its diffucult to see them.


tbb[0].iBitmap = 0;
tbb[0].idCommand = NULL;
tbb[0].fsState = TBSTATE_ENABLED;
tbb[0].fsStyle = TBSTYLE_BUTTON;
tbb[0].dwData = 0;
tbb[0].iString = (int) pszBuf; // Text is in a buffer.


Does this work?

HerbDX
October 17th, 2004, 10:37 AM
Seperators are very visible, and turning it into a button makes no difference, nothing is showing up still..

kawasaki056
October 18th, 2004, 02:14 AM
I think proper value is needed in tbb[0].idCommand .

it's not sure but perhaps I have experienced that , any window is not created correctly without proper ID. except for special case. please try it. or , check return value..// <= it's the good idea.

NoHero
October 18th, 2004, 11:01 AM
I think proper value is needed in tbb[0].idCommand .

it's not sure but perhaps I have experienced that , any window is not created correctly without proper ID. except for special case. please try it. or , check return value..// <= it's the good idea.

A seperator does not need an ID. But a button does. So if he want to create a seperator the id doesn't have to contain a valid value.

kawasaki056
October 18th, 2004, 02:06 PM
may be this ?

SendMessage( hTool , TB_SETBUTTONSIZE , 0L , MAKELONG( cx , cy ) ) ;

and if not try this too

SendMessage( hTool , TB_AUTOSIZE , 0L , 0L ) ;