Creating a GUI with MFC

2019-06-19 02:19发布

I recently started learning MFC (Prosise book), and I feel like it's difficult. But the most difficult part seems to be about creating user interfaces. It seems like you have to know the positions your controls should be positioned at (not the case with dialog based apps).

How do you get around that? Do you first draw the application in Photoshop, then measure the distances there?

And also, are there any GUI designers for it? (to ease the pain). I like it a lot, especially because of the speed and the fact it doesn't require a big framework.

Anyone who does MFC programming regularly is welcome to give me advice on how to get good at programming MFC.

11条回答
相关推荐>>
2楼-- · 2019-06-19 03:02

I'd have to agree that for MFC work, the resource editor which is part of Visual studio is probably the easiest way to get going with MFC. You can just lay your controls out on a dialog and stretch them to appropriate proportions. For the record, MFC is a framework it's just that it comes bundled as part of Windows.

If you want your controls to resize, you'll need to add some code to handle the resize (ON_SIZE I think it is) messages delivered as the dialog is resized. This isn't too bad as long as you don't want to resize / reposition too many things at once.

Personally, I'd recommend avoiding MFC in favour of WxWidgets. There's some great GUI layout programs like wxDesigner which can make creating resizeable dialogs and property pages fairly effortless.

查看更多
疯言疯语
3楼-- · 2019-06-19 03:02

MFC is a pain, IMO. Unless you need to program with c++, I recommend using C# with WPF or WinForms. It's much easier. And if you need to use c++ there are better GUI solutions, like Qt.

查看更多
Evening l夕情丶
4楼-- · 2019-06-19 03:08

If you want the layout features of a dialog in an MFC application derive your CView class from CFormView. This should seem a lot like the "forms" based GUI of .NET WinForms, VB6, etc...

This can be done via the new application wizard, under the Generated Classes' Base Class dropdown section (I checked this on VS 2008).

You can also just create a dialog-based application - which you seem to already be familiar with.

There are several other CView-derived classes that provide other ways to design the "views" of your application. Using the default CView as your base class (as the wizards create by default) assumes you'll handle manually creating "controls" and/or painting the screen. Painting (actually drawing the display with the GDI) being something old-school Win32 developers are familiar but is often never done in more modern frameworks.

查看更多
小情绪 Triste *
5楼-- · 2019-06-19 03:11

Go for QT in GUI purposes. I am sure you will like it..........

查看更多
Melony?
6楼-- · 2019-06-19 03:11

A typical MFC app has a top level frame window and some number of child view window and control bars. None of those things typically need to be manually positioned, although you sometimes need to specify an initial size during construction. You can use Visual Studio's dialog box editor to layout dialog boxes. It should be very rare to have to manually write positioning code.

查看更多
登录 后发表回答