Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grid, flexgrid, or gridbag layout for MFC

Tags:

c++

mfc

MFC seems to have a severe lack of layout managers/sizers. Hard to believe any self-respecting UI library would lack sizers but there you go. I've found something that will take care of the usual box layout just fine, but what I haven't found is a sizer that will help when you need things to be aligned both vertically and horizontally as they expand.

I got most information from here:

layout manager for MFC dialog apps

I've scoured the web and every search for MFC and grid/anything/ ends up sending me to a bunch of grid widgets, not sizers. Is there such a thing anywhere?

like image 391
Edward Strange Avatar asked Nov 04 '10 18:11

Edward Strange


2 Answers

I ran into this "problem" a couple of years ago using WTL. I got fed up by over complicated WM_SIZE handlers, so I bit the bullet and implemented a few layout containers, and adapted the Win32 controls and some of my own to the layout containers.

I basically made subclasses for each control, and implemented my own protocol for "MinSize, MaxSize, PreferredSize". Some controls are tricky to implement this for, but nothing is impossible. It wasn't all that hard to do, so you might want to give it some thought and do it. MFC isn't quite as flexible as ATL/WTL with respect to subclassing, but it's flexible enough.

Unfortunately I can't share the code with you though. :/ I even added a simple XML markup language on top which was pretty nice.

like image 52
Jörgen Sigvardsson Avatar answered Sep 27 '22 17:09

Jörgen Sigvardsson


I haven't heard of a proper fully-featured sizer library for MFC either. And I don't believe there is anything much better than the options mentioned in that linked question.

In my opinion, I doubt any such thing will ever be made at this point. Other well-established GUI frameworks already have proper sizer features integrated by default and also make up for many of MFC's other deficiencies at the same time. I think many people would say it's just not worthwhile to develop such a thing for MFC now. (I even once started working on a sort of generic sizing library that could have been applied to MFC, but eventually lost ambition and put it aside.)

Furthermore, I feel like Microsoft themselves have written-off MFC as a legacy, and instead moved to favor .NET/C#/WPF for GUI development. After all, look at how far those newer technologies have progressed in the past 10 years or so, while at the same time MFC has hardly changed beyond the occasional addition of a feature pack.

If it is at all feasible, I'd suggest considering moving to a more modern C++ framework (such as Qt) or to .NET/C#/WPF (at least for the GUI portion of applications).

like image 20
TheUndeadFish Avatar answered Sep 27 '22 18:09

TheUndeadFish