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
15
votes
4 answers

Is there any way to check if pointer is dangling?

I have a code where I use a pointer to access some datablock. In some rare cases, a few members of the datablock are empty, and as a result the pointer becomes dangling. In fact, I get the correct pointer but the program crashes when trying to do…
Nikhil
  • 299
  • 3
  • 6
  • 17
15
votes
3 answers

How to write a size() function that works on any type of collection objects?

I require a simple way to obtain the count / length / size of an object of class T where T is some sort of collection type, such as a std::map, std::list, std::vector, CStringArray, CString, std::string, … For most of the standard types, T::size()…
Mordachai
  • 9,412
  • 6
  • 60
  • 112
15
votes
1 answer

Using WM_USER, WM_APP or RegisterWindowMessage

Currently, I have a Windows EXE application, with several loaded DLLs. DLLs need to communicate with my windows application through PostMessage and SendMessage. The Windows EXE application + DLLs are all within a single process. The message should…
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875
15
votes
6 answers

How to Run Only One Instance of Application

I have a application which uses socket connection to send and receive data from another application. While creating socket it uses the port 4998 . That is where my problem lie. Once I start my application the socket starts using port 4998. So if I…
Simsons
  • 12,295
  • 42
  • 153
  • 269
15
votes
5 answers

How to enable the TRACE macro in Release mode?

The TRACE macro can be used to output diagnostic messages to the debugger when the code is compiled in Debug mode. I need the same messages while in Release mode. Is there a way to achieve this? (Please do not waste your time discussing why I should…
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
15
votes
6 answers

How to display a non-modal CDialog?

Can someone tell me how I could create a Non Modal Dialog in MFC's Visual c++ 6.0 and show it? I wrote this code: CDialog dialog; if (dialog.init(initialization values...)) dialog.DoModal(); But it blocks my application from showing the dialog.…
14
votes
4 answers

Code Metrics Analysis for Unmanaged C++ Code

Does anyone know of a free tool, similar to what is built into Visual Studio 2010 for managed code, that can do analysis of unmanaged, MFC C++ code and give metrics (lines of code, dependency or coupling, etc)? I've been searching on Google for…
JToland
  • 3,630
  • 12
  • 49
  • 70
14
votes
2 answers

MFC: Why does my spin control work backwards

Using MS Visual Studio, I have attached a spin control to an edit control using the "auto buddy" property. The spin control alters the edit box, but the up button decrements the value and the down button increments the value. How do you fix…
Adam Tegen
  • 25,378
  • 33
  • 125
  • 153
14
votes
3 answers

visual studio building error: unresolved external symbol _IID_IWICImagingFactory (MFC static lib)

I wrote a porgram with a few standard dialogs in an SDI (Doc/View enabled) project. Now that I want to send it to some friends i did set the Use of MFC Use MFC in a static library. But when i try to build the solution i get the following…
Juarrow
  • 2,232
  • 5
  • 42
  • 61
14
votes
3 answers

Does Microsoft Office 2010 make use of WPF or is it plain old MFC?

I have been using WPF for some time now and I am trying to reproduce some of the nifty UI features of their office suite. Although very easy in WPF, I am wondering how it could be done using MFC feature packs (I might have to use it instead, since…
ak3nat0n
  • 6,060
  • 6
  • 36
  • 59
14
votes
8 answers

Is there an auto-update framework for C++/Win32/MFC (like Sparkle)?

I've decided to add auto-update functionality to one of my applications and was looking for any existing solutions that compare the current running version with the latest version that is then downloaded from the web. I know Sparkle on Mac OSX which…
fhe
  • 6,099
  • 1
  • 41
  • 44
14
votes
4 answers

Visual Studio unable to recognise my MFC library for my webcam laser rangefinder code

I tried copying the source code from the internet directly and I couldn't build/debug the whole file because of the error found below. Please Help Error occurred while restoring NuGet packages: System.ArgumentException: The path is not …
user3236892
  • 163
  • 1
  • 1
  • 4
14
votes
5 answers

How to convert _bstr_t to CString

I have a _bstr_t variable bstrErr and I am having a CString variable csError. How do I set the value which come in bstrErr to csError?
subbu
  • 3,229
  • 13
  • 49
  • 70
14
votes
3 answers

What is the point of `static char THIS_FILE[] = __FILE__;`?

What is the point of static char THIS_FILE[] = __FILE__;? Intro: What does it do? Where does it come from? MFC, Microsofts native class library for Windows, has a DEBUG_NEW macro that tracks memory allocations and the place they happened (in the…
14
votes
8 answers

Resizing Controls in MFC

I am writing a program which has two panes (via CSplitter), however I am having problems figuring out out to resize the controls in each frame. For simplicity, can someone tell me how I would do it for a basic frame with a single CEdit control? I'm…
Konrad
  • 39,751
  • 32
  • 78
  • 114