Line Break in Toolbar CAPTION

79 views
Skip to first unread message

valt...@valtecom.com.br

unread,
Jul 29, 2026, 1:36:22 PMJul 29
to Harbour Minigui
Good afternoon, group members,

I'm facing a situation where, in some toolbars, the CAPTION text of a BUTTON exceeds the button's width, and there's a need to break the line. I tried using CRLF like this: CAPTION 'Text A' + CRLF + 'Text', but the line break doesn't occur. I checked the examples in the SAMPLES folder and didn't find it.

Does this option not exist?

Thank you.

Valteçom
Uberaba MG Brazil

Grigory Filatov

unread,
Jul 29, 2026, 1:54:56 PMJul 29
to Harbour Minigui
Dear Valteçom,

> Does this option not exist?

Short answer: generally, no—not with the standard Windows toolbar control (TOOLBARCLASSNAME / common controls).

The standard toolbar button text is rendered by the common controls library and does not interpret \n or CR/LF as a line break. If you pass:

"Open" + CRLF + "File"

or

TEXT("Open\r\nFile")

the control will either:

  • display only one line,

  • replace the line break with a space,

  • or ignore it completely (depending on the comctl32 version).

What the WinAPI provides

The toolbar control supports:

  • TBSTYLE_LIST (image beside text)

  • BTNS_SHOWTEXT

  • multiline tooltips (TTM controls)

  • wrapping of toolbar rows (TBSTYLE_WRAPABLE)

However, it does not support multiline button captions.

Possible workarounds1. Owner-drawn / Custom Draw (recommended if you really need it)

You can make the toolbar owner-drawn:

TBSTYLE_CUSTOMERASE NM_CUSTOMDRAW

or create owner-drawn buttons and paint the caption yourself using

DrawText( hdc, TEXT("Open\nFile"), -1, &rc, DT_CENTER | DT_WORDBREAK | DT_VCENTER );

This gives complete control but essentially means replacing the toolbar's text rendering.


2. Use Unicode characters

Some developers use characters such as

Open File

or

Open/File

or

Open↵File

These are visual tricks only—not actual multiline captions.


3. Use larger buttons

Windows Explorer, Office, and Visual Studio avoid multiline toolbar text by using:

  • larger buttons

  • icons

  • short captions

This is the most compatible approach.


4. Replace the toolbar

If true multiline captions are required, a toolbar is probably not the ideal control.

A custom panel containing:

  • image

  • static text

  • click handling

can mimic a toolbar while allowing arbitrary text layout.

Can it be hacked via WinAPI messages?

Unfortunately, no.

Messages like

TB_SETBUTTONINFO TB_ADDBUTTONS TB_SETBUTTONSIZE TB_AUTOSIZE

only affect:

  • text

  • image

  • size

  • state

There is no style or message equivalent to:

BS_MULTILINE

that exists for push buttons.

For HMG Extended

Since HMG's TOOLBAR is a wrapper around the standard Windows toolbar control, there is currently no WinAPI flag that can enable multiline captions.

If you wanted to add this capability to HMG itself, the practical options would be:

  1. Implement NM_CUSTOMDRAW support and draw button captions with DrawText(..., DT_WORDBREAK).

  2. Create a new custom toolbar control (similar to the existing ButtonEx implementation) that behaves like a toolbar but supports multiline text.

  3. Use regular BUTTONEX controls arranged to resemble a toolbar. BUTTONEX already offers much greater flexibility than the standard toolbar and is likely the easiest route if multiline captions are important.

So, from a WinAPI perspective, the answer is no: the standard toolbar control does not support line breaks in button captions, and there is no documented message or style to enable that behavior. Any solution requires custom drawing or replacing the control.


среда, 29 июля 2026 г. в 19:36:22 UTC+2, valt...@valtecom.com.br:

Ivanil Marcelino

unread,
Jul 30, 2026, 7:35:05 AMJul 30
to Harbour Minigui
Bom dia;

você pode adicionar a propriedade  AUTOSIZE ao button ; dessa forma o botão ira se ajustar ao tamanho do caption sem perder informação,


Ivanil

Diomedes Amparo

unread,
Aug 1, 2026, 7:25:50 AM (13 days ago) Aug 1
to Ivanil Marcelino, Harbour Minigui
ola amigos
bom dia

para teste eu faço desta forma:
DEFINE WINDOW FRM_EMPRESA ROW 130 COL 010 WIDTH 1326 HEIGHT 590  MODAL NOSIZE NOSYSMENU NOCAPTION BACKCOLOR {243,243,243}
 DEFINE BUTTONEX BTGERAL
  ROW 000
  COL 000
  WIDTH 1326
  HEIGHT 030
  CAPTION ALLTRIM( ROWS_EMPRESA_QUERY:FIELDGET("EMP_RAZAO") )
  ACTION FRM_EMPRESA.TXTFANTASIA.SETFOCUS
  PICTURE  "EMPRESA.ICO"
  FONTNAME "Arial"
  FONTSIZE 20
  FONTBOLD .T.
  BACKCOLOR {0,150,255}
  FONTCOLOR WHITE
  FLAT .T.
  NOTABSTOP .T.
  GRADIENTFILL { { 1, { 0,150,255 }, { 000,000,255 } } }
 END BUTTONEX

--
Visit our website on https://www.hmgextended.com/ or https://www.hmgextended.org/
---
You received this message because you are subscribed to the Google Groups "Harbour Minigui" group.
To unsubscribe from this group and stop receiving emails from it, send an email to minigui-foru...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/minigui-forum/a5016411-0cc7-418e-908b-d66b6874e6ccn%40googlegroups.com.

Diomedes Amparo

unread,
Aug 1, 2026, 9:59:36 AM (13 days ago) Aug 1
to Ivanil Marcelino, Harbour Minigui
ola amigos
só um detalhe na propriedade  HEIGHT deve colocar um valor maior tipo 60 e em 
CAPTION ALLTRIM( ROWS_EMPRESA_QUERY:FIELDGET("EMP_RAZAO") ) + QUEBRA + "TESTE DE QUEBRA DE LINHA"

funciona perfeitamente.
Reply all
Reply to author
Forward
0 new messages