Button in title/caption bar of a window? Is it possible?

91 views
Skip to first unread message

Tony Kennedy

unread,
Jul 4, 2025, 7:19:02 AMJul 4
to wx-users
I need to implement something like a "pin" button to make a window always visible.

The ideal way would be to have a button in the caption area of a window. I've searched and cannot find a way to do this in wx, is this possible? Or do I need to implement platform specific code to do this?

Thanks in advance,

Tony.

Vadim Zeitlin

unread,
Jul 5, 2025, 5:49:52 PMJul 5
to wx-u...@googlegroups.com
On Fri, 4 Jul 2025 04:19:01 -0700 (PDT) Tony Kennedy wrote:

TK> I need to implement something like a "pin" button to make a window always
TK> visible.
TK>
TK> The ideal way would be to have a button in the caption area of a window.
TK> I've searched and cannot find a way to do this in wx, is this possible? Or
TK> do I need to implement platform specific code to do this?

There is no support for this in wx, you have to either create a window
without any decorations and then draw all of them yourself or use
platform-specific code to integrate an extra button into the native title
bar (which may not be possible for some platforms anyhow, requiring to use
the first solution for them).

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
https://www.tt-solutions.com/

Tony Kennedy

unread,
Jul 7, 2025, 5:21:20 AMJul 7
to wx-users
Thanks, I've got this working, the appearance is not quite right though (see attached, I've coloured the new title bar yellow). I can set the background of the dialog so it matches the title bar colour, this gets rid of the grey area at the top. It would be nicer if I could remove the rounded corners of the window, but I guess that's an operating system thing, so probably best not to change it.

Thanks again,

Tony.
TitleBar.jpg

Vadim Zeitlin

unread,
Jul 7, 2025, 8:40:49 AMJul 7
to wx-u...@googlegroups.com
On Mon, 7 Jul 2025 02:21:20 -0700 (PDT) Tony Kennedy wrote:

TK> Thanks, I've got this working, the appearance is not quite right though
TK> (see attached, I've coloured the new title bar yellow). I can set the
TK> background of the dialog so it matches the title bar colour, this gets rid
TK> of the grey area at the top. It would be nicer if I could remove the
TK> rounded corners of the window, but I guess that's an operating system
TK> thing, so probably best not to change it.

You can (and probably should) change it, but you'll need to use native
APIs (DWM ones under Windows) to do it.

Tony Kennedy

unread,
Jul 7, 2025, 11:14:55 AMJul 7
to wx-users
Hmm. Tried the Windows 11 trick (DwmSetWindowAttribute), it gives me a square window, but I've still got a small grey area at the top of the window (similar to the rounded corner window).

I know this is no longer wx related. I'll see how things look on the Mac and make a decision at that point.

Thanks for the advice,

Tony.
titlebar_square.jpg

Tony Kennedy

unread,
Jul 15, 2025, 1:59:09 PMJul 15
to wx-users
Related to this, I cannot find a way to add a menu to this window. Is there any way to do this?

I can always add some flat buttons to a toolbar instead and create a popup when they are clicked.

Tony.




Vadim Zeitlin

unread,
Jul 16, 2025, 1:37:35 PMJul 16
to wx-u...@googlegroups.com
On Tue, 15 Jul 2025 10:59:09 -0700 (PDT) Tony Kennedy wrote:

TK> Related to this, I cannot find a way to add a menu to this window. Is there
TK> any way to do this?

Do you mean the system menu or a custom one? Both are possible, for the
former one you can get its HMENU from Windows using ::GetSystemMenu() and
there is wxTopLevelWindow::MSWGetSystemMenu() which returns it to you as a
wxMenu. You may also want to handle WM_NCHITTEST to return HTSYSMENU for
the area for which you show the system menu.

Tony Kennedy

unread,
Jul 17, 2025, 5:32:25 AMJul 17
to wx-users
Not quite, I want a menu bar within my popup window. I tried adding a menubar, but it appears in the titlebar area (which is not what I want).

I can do this with a toolbar and buttons/static text and detecting the onclick events. That way it appears below the virtual title bar.

Thanks again for the advice.

Tony.

PS. I know the Mac menu is supposed to appear at the top of the screen, but I've got users that don't notice the menu changing for popup windows (so had to put a prominent menu button so they could see that something could be done).
Reply all
Reply to author
Forward
0 new messages