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
20
votes
14 answers

Is There Still A Case For MFC

What are the compelling features of MFC? Why would you select it for a new project?
Aaron Fischer
  • 20,853
  • 18
  • 75
  • 116
19
votes
3 answers

How to Use Timer in MFC Dialog based Application?

I am developing MFC Dialog based application in Visual Studio 2008. I want to use timer that start on start of the application and continue to run and calls a function that performs my task? How can I do this? Thanks
Ali Ahmed
  • 1,749
  • 6
  • 20
  • 29
19
votes
3 answers

Run MFC program on Linux

I have a rather large MFC based program. I have been tasked to get it running on Linux. I have explained that this will require a re-write of the program either into straight C++ with STL (more work), or into Qt/C++ (less work). I am now told…
E.Freitas
  • 542
  • 1
  • 4
  • 18
19
votes
3 answers

How to apply Test Driven development for GUI application(VC MFC)?

Can I use TDD for gui application? How to do it.
yesraaj
  • 46,370
  • 69
  • 194
  • 251
19
votes
3 answers

Redirect stdout and stderr to the output debug console of microsoft visual studio

I am using microsoft visual studio to do C++. I don't see std::err and std::out in the output console of the IDE. Is there a way to redirect them ?
0x26res
  • 11,925
  • 11
  • 54
  • 108
19
votes
4 answers

Linker: cannot open file 'nafxcwd.lib'

I have problem with compiling my project via visual studio 2013. I got this linker error: LINK : fatal error LNK1104: cannot open file 'nafxcwd.lib' According to this page, I must use MFC in shared library. But I don't use MFC at all. All my…
user922871
  • 435
  • 2
  • 6
  • 17
19
votes
1 answer

SendMessage and PostMessage which one is better to use?

searching the web for the difference between these two function calls, I've found that: The difference between these two API calls is the way that they return control to the calling application. With SendMessage control is not returned to the…
19
votes
6 answers

MFC - change text color of a cstatic text control

How do you change the text color of a CStatic text control? Is there a simple way other that using the CDC::SetTextColor?
Owen
  • 4,063
  • 17
  • 58
  • 78
18
votes
1 answer

How do I host WPF content in MFC Applications?

I'm going to answer my own question here because I spent a few hours piecing this together and wanted to share what I found in the hope that I will save someone else the digging. There is an MSDN Walkthrough that gets you most of the way there, but…
17 of 26
  • 27,121
  • 13
  • 66
  • 85
18
votes
12 answers

How to read the SD Card ID number?

How can I programatically read the SD Card's CID register, which contains a Serial Number and other information? Can I do it through Android Java, or Native code? Thanks in advance, Eric
Eric Hamilton
  • 181
  • 1
  • 1
  • 3
18
votes
7 answers

How can you bring a control to front in mfc

How do you change controls' Z-order in MFC at design time - i.e. I can't use SetWindowPos or do this at runtime - I want to see the changed z-order in the designer (even if I have to resort to direct-editing the .rc code). I have an MFC dialog to…
Tim Erickson
  • 2,323
  • 2
  • 22
  • 27
17
votes
2 answers

What does AFX_MANAGE_STATE(AfxGetStaticModuleState()) do exactly

I have used a lot of modal dialogs and they worked fine without the use of AFX_MANAGE_STATE, but recently I was working on a different project in which the resource dlls are different from the launching dll. I surfed the web and found out the above…
dev ray
  • 465
  • 3
  • 6
  • 18
17
votes
4 answers

CString to char*

We are using the CString class throughout most of our code. However sometimes we need to convert to a char *. at the moment we have been doing this using variable.GetBuffer(0) and this seems to work ( this mainly happens when passing the Csting into…
Mark Lakewood
  • 1,980
  • 4
  • 22
  • 44
17
votes
5 answers

how do I write to stdout from an MFC program?

MFC programs can't normally write to stdout. MFC does something weird with the stdout/stdin pipes during startup and anything you write (for example doing a printf("hello");) just goes to /dev/null. Does anyone know how to successfully write to…
Stephen Kellett
  • 3,078
  • 1
  • 22
  • 25
17
votes
10 answers

64 bit tools like BoundsChecker & Purify

For many years I have used two great tools BoundsChecker & Purify, but the developers of these applications have let me down, they no longer put effort into maintaining them or developing them. We have corporate accounts with both companies, and…
titanae
  • 2,259
  • 2
  • 21
  • 31