wxFrame custom Title bar

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Priya
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Apr 07, 2017 8:38 am

wxFrame custom Title bar

Post by Priya »

Hi,

Using wxFrame - wxFRAME_SHAPED we can achieve shaped window.
I want to know whether i can achieve similar to the below image. My title bar should be having a background image(which is having app icon and app name) and with minimise, maximise and close button.
Is it achievable in both windows and Linux??

[img]
sample.png
sample.png (6.22 KiB) Viewed 5446 times
[/img]

Please help

Thanks and Regards,
Priya
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxFrame custom Title bar

Post by eranon »

Maybe this thread may help: viewtopic.php?t=30494
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Priya
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Apr 07, 2017 8:38 am

Re: wxFrame custom Title bar

Post by Priya »

yes. This post i already checked. I can able to apply an image to a title bar. But i am not able to add minimise, maximise, and close button in that title bar since i have to remove wxCAPTION style. Without this style minimise, maximise, and close button style is not support.

So i have to add buttons to achieve that. But am not aware how to handle this.And moreover i want my title image should stretch width wise when i do maximise and minimise.

Is that doable in wxWidgets??

Thanks and Regards,
Priya
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxFrame custom Title bar

Post by eranon »

I'm not used about custom window w/ wxWidgets, but I guess you have to draw everything (icon, title, background image, buttons miming the system ones) during paint event handler (in pure Windows, it would be about WM_NCPAINT, but I don't know if there is a differenciation from wxWidgets) and run appropriate code to minimize, maximize and close when user hits the buttons area.

--
EDIT: About overall concept of skinning, you can look at wxSkin: https://github.com/EEmmanuel7/wxskintoy (not updated since 6 years, so I don't know if it still works w/ last wxWidgets releases) and way to paint your own custom controls: https://wiki.wxwidgets.org/Painting_your_custom_control
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Nunki
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Fri Sep 14, 2012 8:26 am
Location: Kontich, Belgium
Contact:

Re: wxFrame custom Title bar

Post by Nunki »

Hi Priya,

You could go for the custom made window and do the handling yourself. To construct what you want would be like the next image.
structure.jpg
structure.jpg (39.78 KiB) Viewed 5420 times
So basically a vertical sizer with two panels on it, the top panel being set to a fix height op 40px e.g. The latter with a stretch factor=1. Both of them expanded in horizontal direction. The top panel will act as your title bar - if you disable everything on the frame, no title bar, no buttons.
Then on this top panel add a horizontal sizer with an image, text, a spacer and 3 image buttons. This would result in something like this
result.jpg
result.jpg (24.6 KiB) Viewed 5420 times
The spacer has to have a stretching=1 to push the buttons to the right. Now you can play with border widths to minimise space between panels and all, to make it all lokk like a real window. Add some handlers for clicking on the three buttons on the right like this

Code: Select all

BEGIN_EVENT_TABLE( Test, wxMDIChildFrame )

////@begin Test event table entries
 EVT_BUTTON( XRCID("ID_BITMAPBUTTON"), Test::OnBitmapbuttonClick )
 EVT_BUTTON( XRCID("ID_BITMAPBUTTON1"), Test::OnBitmapbutton1Click )
 EVT_BUTTON( XRCID("ID_BITMAPBUTTON2"), Test::OnBitmapbutton2Click )
////@end Test event table entries

END_EVENT_TABLE()
This might bring you where you wanted to be...

regards,
Nunki
User avatar
marcelinux
Knows some wx things
Knows some wx things
Posts: 40
Joined: Thu Nov 07, 2013 9:59 pm
Location: Madrid, Spain

Re: wxFrame custom Title bar

Post by marcelinux »

Priya wrote:Is it achievable in both windows and Linux??
What about Linux Desktops (Plasma, Gnome, Unity, Cinnamon, lxde)?
Buttons for min/max/close have different images and location.
I just need learn a little bit more. Thank you for your help.
Priya
Knows some wx things
Knows some wx things
Posts: 43
Joined: Fri Apr 07, 2017 8:38 am

Re: wxFrame custom Title bar

Post by Priya »

Hi Nunki

Thank you. I will try your approach :)

@eranon I am going thru the wxSkin code. I was not clear how button are created. Will check the code :)


Thanks & Regards
Priya
User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: wxFrame custom Title bar

Post by eranon »

I don't know specifically about wxSkin (I talked about it because it could shortcut the effort if it works and covers enough of controls), but basically you derive from the wxWidgets base class the closest to the behavior you target, then you draw your way during an handler of paint event. Here an example I found typing "wxwidgets skinning button" w/o quotes in Google: https://wxwidgets.info/howto_draw_gradient_buttons/
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]
Post Reply