March 28, 2024, 06:05:15 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Unwanted space in wrapable toolbar

Started by sapero, December 24, 2008, 09:13:09 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

sapero

I have a wrapable toolbar with custom drawn buttons, without text labels. If it wraps, there is added unused space at the bottom side (see attached image).
Toolbar styles: CHILD VISIBLE FLAT WRAPABLE TOOLTIPS NODIVIDER TRANSPARENT.
Sizing handler:sub OnSize()
{
RECT rc;
RECT rcToolbar;
RECT rcStatusbar;

GetClientRect(g_hwndApp, &rc);

SendMessage(g_hwndToolbar, TB_AUTOSIZE, 0, 0);
GetWindowRect(g_hwndToolbar, &rcToolbar);
int ToolbarHeight = rcToolbar.bottom - rcToolbar.top;

SendMessage(g_hwndSbr, WM_SIZE, 0, 0);
GetClientRect(g_hwndSbr, &rcStatusbar);
MoveWindow(g_hwndMdi, 0, ToolbarHeight, rc.right, rc.bottom-ToolbarHeight-rcStatusbar.bottom, TRUE);
}

Am I missing something?

LarryMc

Sapero

It's almost scarey when YOU post a QUESTION!! ;)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Interesting.  Do you have a separator as the last item in the toolbar?

Try sending it a TB_SETROWS wparam = MAKEWPARAM (1, 1), lparam = NULL after resizing to see if it stays at 4 rows.

Paul.

Ionic Wind Support Team

pistol350

Quote from: Larry McCaughn on December 24, 2008, 10:37:31 AM
Sapero

It's almost scarey when YOU post a QUESTION!! ;)

Larry

I'm relieved to know that i'm not the only one to sometimes have that same feeling.  ;)
Regards,

Peter B.

sapero

Hehe, I search always before posting, and having about 6 SDK's and a ton of headers (and google ofc) searching is much faster than waiting for a reply.

Paul, TB_SETROWS did not help. I've tried also other messages, but finaly decided to size the toolbar in WM_WINDOWPOSCHANGING. I'll post the solution later.

sapero

December 24, 2008, 01:35:12 PM #5 Last Edit: December 24, 2008, 01:52:49 PM by sapero
This is the easiest solution:int g_ToolbarHeight;

sub OnSize()
{
RECT rc;
GetClientRect(g_hwndApp, &rc);

g_ToolbarHeight = 26; // one row
// set it to 29 if the CCS_NODIVIDER style is not set

if (rc.right < 707) // last button right border
{
g_ToolbarHeight += 29; // two rows
}
if (rc.right < 540)
{
g_ToolbarHeight += 29; // three rows
}
SendMessage(g_hwndToolbar, TB_AUTOSIZE, 0, 0);

// resize other windows
}

sub ToolbarSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam),LRESULT
{
if (uMsg == WM_WINDOWPOSCHANGING)
{
*(WINDOWPOS)lParam.cy = g_ToolbarHeight;
}
return CallWindowProc(g_wndprocToolbar, hWnd, uMsg, wParam, lParam);
}


To be more professional we should calculate the number of buttons for each row:sub CalcToolbarHeight(int maxWidth),int
{
RECT rc;
int height = 26; // or 29 if CCS_NODIVIDER style is not set
int items = SendMessage(g_hwndToolbar, TB_BUTTONCOUNT, 0, 0);
int sum = 0;

for (int n=0; n<items; n++)
{
SendMessage(g_hwndToolbar, TB_GETITEMRECT, n, &rc);
int ButtonWidth = rc.right - rc.left;
sum += ButtonWidth;

if (sum > maxWidth)
{
sum = ButtonWidth;
height += 29; // next row
}
}
return height;
}