Questions tagged [mfc]

This tag should be used for questions concerning Microsoft Foundation Class Library (MFC), a C++ framework for Windows desktop GUI application programming. You should specify a tag for the version of C++ or Visual Studio being used. Due to the size of MFC, additional tags such as [com], [wininet], [winapi] or other subject matter tags are helpful.

The Microsoft Foundation Class (MFC) framework provides an object-oriented abstraction layer on top of a large subset of the Win32 API. MFC offers a range of classes and templates covering almost all features used in developing a Windows desktop application. It provides models of architecture for the application in which it will be built, namely document - model - view available in three options:

  • SDI applications (single paper interface: one window),
  • MDI (multiple document interface: multiple windows)
  • Dialog-Based applications (a modal dialog box interface).

There are several Visual Studio supplied application templates which provide a starting place for the look and feel of a new application. New templates with new functionality and behavior seen in Microsoft applications (docking windows) such as Visual Studio have been introduced over the years.

MFC uses a single inheritance model of the C++ language (i.e. no multiple inheritance); all the classes form a hierarchy. The newer MFC classes are identified by the prefix CMFC, as in CMFCPropertyPage, or by adding an Ex suffix, as in the CPropertyPageEx class.

Almost all MFC classes inherit from CObject and all window classes or control classes inherit from the CWnd class, which is the base class for all windows and includes all the basic treatments performed on a window such resizing or moving the window.

This MSDN chart give us an idea of class hierarchy:
http://msdn.microsoft.com/en-us/library/ws8s10w4.aspx

For Windows UI development, MFC is a very thin layer over Win32 API, and hence is equivalently as fast as native Win32 GUI application. Some classes, for example, sockets and networking, may be considered slightly thicker. For COM and related stuff, it is considered quite heavy (and hence ATL is preferred).

The MFC model can feel restrictive in that when the application architecture does not quite fit the MFC paradigm of desktop GUI application, the framework can be difficult to extend without bypassing the Visual Studio class wizards and opting for hand coding.

For new development, STL containers should be preferred over the original MFC containers (CList, CArray, etc.). Why STL containers are preferred over MFC containers?

MFC multi-threading support is some what heavy and C++17/C++20 multi-threading and coroutines may be a better approach for background worker threads. However MFC has good support for user interface threads which require a message pump as well as support for the WinAPI thread synchronization library.

While earlier versions of Visual Studio provided an easy selection to install the MFC components as one of several standard packages, later versions appear to have MFC as more of an option that must be turned on.

More details at http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library

13003 questions
33
votes
8 answers

How do I force windows NOT to redraw anything in my dialog when the user is resizing my dialog?

When the user grabs a corner of a resizable window, and then moves it, windows first moves the contents of the window around, then issues a WM_SIZE to the window being resized. Thus, in a dialog where I want to control the movement of various child…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
32
votes
4 answers

How can I convert an Int to a CString?

I can convert a Double to a CString using _ecvt result_str=_ecvt(int,15,&decimal,&sign); So, is there a method like the one above that converts an int to CString?
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
31
votes
5 answers

What are some techniques for migrating a large MFC application to WPF/.NET?

I am currently working on a very large legacy MFC MDI application. It has a large number of UI elements - dockable toolbars, custom tree controls, context menus, etc. It is an image processing application so the main views render themselves using…
17 of 26
  • 27,121
  • 13
  • 66
  • 85
31
votes
3 answers

Is there a Designer for MFC in Visual Studio like for windows forms in .NET?

I'm a .NET programmer. I've never developed anything in MFC. Currently I had to write a C++ application (console) for some image processing task. I finished writing it. But the point is I need to design GUI also for this. Well, there won't be…
claws
  • 52,236
  • 58
  • 146
  • 195
31
votes
8 answers

Is MFC still used for new development (with any material volume)?

I've never been a big fan of MFC, but that's not really the point. I read that Microsoft is due to release a new version of MFC in 2010 and it really struck me as odd - I thought MFC was dead (no ill intention, I really did). Is is MFC used for new…
NTDLS
  • 4,757
  • 4
  • 44
  • 70
31
votes
13 answers

Why STL containers are preferred over MFC containers?

Previously, I used to use MFC collection classes such CArray and CMap. After a while I switched to STL containers and have been using them for a while. Although I find STL much better, I am unable to pin point the exact reasons for it. Some of the…
Naveen
  • 74,600
  • 47
  • 176
  • 233
31
votes
6 answers

How to format date and time string in C++

Let's say I have time_t and tm structure. I can't use Boost but MFC. How can I make it a string like following? Mon Apr 23 17:48:14 2012 Is using sprintf the only way?
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
30
votes
15 answers

Ever done a total rewrite of a large C++ application in C#?

I know Joel says to never do it, and I agree with this in most cases. I do think there are cases where it is justified. We have a large C++ application (around 250,000 total lines of code) that uses a MFC front end and a Windows service as the core…
TWA
  • 12,756
  • 13
  • 56
  • 92
30
votes
4 answers

MFC development in vs2017

When I installed vs2017, I did select Windows development with C++ option. After installation, however, I don't see the MFC has been added. Sure enough, I get errors when I compile my application, fatal error C1083: Cannot open include file:…
Louis
  • 660
  • 1
  • 7
  • 14
30
votes
15 answers

VS2008: "Resource file opened in another editor"

But it's a lie! Good day to all! I have the following problem: when I try to open the resource file PriceCalculationUI.rc Visual Studio 2008 tells me that the file is opened in another editor (in vs2008 I have only 1 opened tab with .cpp file). I…
GrinderZ
  • 674
  • 2
  • 6
  • 16
29
votes
8 answers

Disallowing creation of the temporary objects

While debugging crash in a multithreaded application I finally located the problem in this statement: CSingleLock(&m_criticalSection, TRUE); Notice that it is creating an unnamed object of CSingleLock class and hence the critical section object…
Naveen
  • 74,600
  • 47
  • 176
  • 233
29
votes
2 answers

Using a Qt-based DLL in a non-Qt application

Am I doing it right? A client of mine has a group where I'm developing Qt-based client-server stuff with a lot of fun widget stuff and sockets. Another group within the company wants to use a wrapped version of the QTcpSocket-based client data…
darron
  • 4,284
  • 3
  • 36
  • 44
29
votes
7 answers

How to create a resizable CDialog in MFC?

I have to create a dialog based application, instead of old CFormView type of design. But CDialog produces fixed-size dialogs. How can I create dialog based applications with resizable dialogs?
Serkan
28
votes
2 answers

Redefining or changing macro value

I am currently working on an already developed project written in MFC C++ and am facing a problem with an already present macro having the definition: #define HEIGHT_TESTS 13 I am trying to change the value from within the code but I think since…
Neophile
  • 5,660
  • 14
  • 61
  • 107
28
votes
4 answers

Split functionality for MFC Cstring Class

How to Split a CString object by delimeter in vc++? For example I have a string value "one+two+three+four" into a CString varable.
Dharma
  • 837
  • 1
  • 9
  • 14