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

How to compile VC++ 2010 projects using Visual Studio 2012 and Windows SDK 7.1

I have a lot of projects done with VS2010 in C++. Now we have switched to VS2012 but we want to continue building the projects with the VS2010 runtime (we need to support Windows XP). To our understanding this could be possible using Windows SDK…
Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
13
votes
10 answers

C++ string memory management

Last week I wrote a few lines of code in C# to fire up a large text file (300,000 lines) into a Dictionary. It took ten minutes to write and it executed in less than a second. Now I'm converting that piece of code into C++ (because I need it in an…
Dan Byström
  • 9,067
  • 5
  • 38
  • 68
13
votes
3 answers

Difference between GetDC() and BeginPaint()

I am working on Win32 UI. I want to know the difference Between GetDC and BeginPaint. When to Use which API and when not to use which API.
Umesha MS
  • 2,861
  • 8
  • 41
  • 60
13
votes
3 answers

odd handle leak

My application (base application is MFC interop with C++/CLI but it also contains a lot of C#, Windows Forms, WPF) has has a handle leak. Shortly after application start I can see the handle count in the task manager grow continuously (at a rate of…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
13
votes
5 answers

How can I handle the Return key in a CEdit control?

How can I handle the Return key (VK_RETURN) in a CEdit control? The CEdit control is parented to a CDialog.
knaser
  • 1,421
  • 7
  • 19
  • 16
13
votes
11 answers

Avoiding "(Not Responding)" label in windows while processing lots of data in one lump

I occasionally need to process a large amount of data from one package off the network, which takes sufficiently long that when the user tries to interact with the application windows adds the "(Not Responding)" string to the window title. I am…
Foo42
  • 3,024
  • 4
  • 22
  • 17
13
votes
6 answers

How to draw 32-bit alpha channel bitmaps?

I need to create a custom control to display bmp images with alpha channel. The background can be painted in different colors and the images have shadows so I need to truly "paint" the alpha channel. Does anybody know how to do it? I also want if…
Javier De Pedro
  • 2,219
  • 4
  • 32
  • 49
13
votes
5 answers

How to turn off ASSERTs in debug mode in Visual Studio 2013

Is there any way to turn off asserts instead of switching to Release mode. I need to debug a code which make assertions really often and it slows down my work. These asserts are not related to the issue i am trying to solve, so for now they only…
Alexander Demerdzhiev
  • 1,034
  • 2
  • 14
  • 29
13
votes
7 answers

MFC resources / links

I am about to reenter the MFC world after years away for a new job. What resources to people recommend for refreshing the memory? I have been doing mainly C# recently. Also any MFC centric websites or blogs that people recommend?
JamesSugrue
  • 14,891
  • 10
  • 61
  • 93
13
votes
3 answers

Auto resizing column widths in a CListCtrl

How can I make a CListCtrl to resize the width of its columns automatically? Usually, when an item in the list gets too long, the back end disappears from view and the user manually has to resize the width of the corresponding column. Is there any…
Isuru
  • 182
  • 1
  • 2
  • 11
13
votes
5 answers

Will VC++ MFC become obsolete in near future?

Normally people say MFC is little clumsy. It makes UI development slightly difficult to maintain since it has lot of auto generated code. It has good architecture (doc/view) but is not transparent like Win32 programming to understand how window…
Akaanthan Ccoder
  • 2,159
  • 5
  • 21
  • 37
13
votes
5 answers

MFC Combo-Box Control is not showing the full list of items when I click the drop-down menu

I'm coding an app in MSVS 2008, which has a ComboBox control which I initialize thru the code as below: static char* OptionString[4] = {"Opt1", "Opt2", …
TCSGrad
  • 11,898
  • 14
  • 49
  • 70
13
votes
6 answers

Testing approach for multi-threaded software

I have a piece of mature geospatial software that has recently had areas rewritten to take better advantage of the multiple processors available in modern PCs. Specifically, display, GUI, spatial searching, and main processing have all been hived…
SmacL
  • 22,555
  • 12
  • 95
  • 149
13
votes
12 answers

Class names that start with C

The MFC has all class names that start with C. For example, CFile and CGdiObject. Has anyone seen it used elsewhere? Is there an official naming convention guide from Microsoft that recommends this style? Did the idea originate with MFC or was…
User1
  • 39,458
  • 69
  • 187
  • 265
13
votes
1 answer

What is the correct solution to support IAccesible interface for caret movement in text editors?

I want to implement a text editor from scratch which supports IAccessible interface. I am using MFC and Win32 API. When the caret position change in the standard text editors like Notepad, the corresponding letter, word or line to the caret movement…
A.Danesh
  • 844
  • 11
  • 40