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

Can a custom MFC window/dialog be a class template instantiation?

There's a bunch of special macros that MFC uses when creating dialogs, and in my quick tests I'm getting weird errors trying to compile a template dialog class. Is this likely to be a big pain to achieve? Here's what I tried: MyDlg.h template
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
2 answers

Sort files according to creation date?

First Problem is solved. Files is perfectly arrange. for (int i = 0; i < allFiles.GetSize(); i++) { box1.AddString(allFiles[i]); } vector files; vector vec; vec.insert(vec.begin(), &allFiles[0], &allFiles[allFiles.GetSize() - 1]…
andy
  • 35
  • 1
  • 6
3
votes
1 answer

getting rid of _WIN32_WINNT not defined.

I'm trying to get rid of the _WIN32_WINNT not defined: _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h) I'm running VS 2010 on Win 7 and am trying to recompile a MFC project orginally complied in Win CE. I've had a look…
user4292309
3
votes
2 answers

How to upgrade a VC++6.0 project to VS2010?

I have MFC Dialogue based applications written in VC++6.0. Due to my work environment requirements I need to upgrade to Visual Studio 2010. I don't need to add any new feature, just compile with the upgraded visual studio. Can any guide me on…
user3883423
  • 247
  • 5
  • 19
3
votes
0 answers

How to place a toolbar inside an edit control?

My original goal was to place an X button inside an edit control (it later turned out that this edit control by itself must be a part of the combo box.) I've been suggested to use this article as a guidance. To make it look a little bit "prettier" I…
c00000fd
  • 20,994
  • 29
  • 177
  • 400
3
votes
1 answer

How to get a list of recent files in MFC

I am trying to build a welcome page (which is CDHTmlDialog based) and in that welcome page i want to present a list of my recent files. it should look like Adobe Reader welcome page. I tried to get the recent file list by getting the MRU list and…
3
votes
3 answers

Migrating a big project in MFC from Visual C++ 6.0 to Visual Studio 2005

I am maintaining a big project (~250k loc, not counting code generated from idl) in Visual C++ 6.0, that uses Visibroker (VB for short) 5.2.1 (which is a CORBA implementation from Borland). Recently, the other module that communicates with my…
Thanh DK
  • 4,257
  • 3
  • 23
  • 18
3
votes
1 answer

MFC: Deleting dynamically created CWnd objects

Lets say in a dialog, we dynamically create a variable number of CWnds... like creating a and registering a CButton every time the user does something/ Some pseudo-code... class CMyDlg : public CDialog { vector windows; void onClick() { …
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
4 answers

Visual C++: Invalid allocation size. How to force the debugger to stop on this message?

The MFC program I am debugging is printing this message in the "Output" window in Visual Studio 9.0: HEAP[AppName.exe]: Invalid allocation size - 99999998 (exceeded 7ffdefff) I'm pretty sure this is due to a bad "new", uninitialized variable or…
James
  • 6,978
  • 2
  • 17
  • 18
3
votes
3 answers

Display element in CStringArray on Debugger one bye one?

This code every time display Cat in debugger. First time and second time. But I want to display Cat at 1st time in debugger and then Dog in 2nd time debugger. int main(){ CStringArray arr; arr.Add("Cat"); arr.Add("Dog"); for…
Alex Cerry
  • 107
  • 13
3
votes
3 answers

What is the use of CListCtrl::GetItemData()?

Can anybody please help me to know, what is the use of CListCtrl::GetItemData() in MFC, VC++ ? I went through MSDN description but it was not clear enough. If anybody can provide a brief explanation and some example it will be really great and would…
user3587879
  • 127
  • 3
  • 12
3
votes
4 answers

By knowing VC++ MFC, how easy or difficult is to learn C#.Net?

Right now, I'm more into design & maintenance of MFC based application. I'm seeing good progress and requirement for C#.Net application. With this background knowledge, how easy or difficult is to learn C#.Net? Is there any tutorials available…
Akaanthan Ccoder
  • 2,159
  • 5
  • 21
  • 37
3
votes
1 answer

Can I draw Qt objects directly to Win32 DC (Device Context)?

I can draw Qt objects to an QImage and then draw the image to HDC or CDC. This may hurt our application's performance. It would be great if I can draw Qt objects directly to Win32 HDC or MFC CDC. I expect that there is a class, say QWin32Image for…
Kevin C.
  • 271
  • 3
  • 8
3
votes
0 answers

How to get combined size of multiple monitors C++

We have just provided support in our latest game for multiple dialogs across multiple monitors. We store the position of each dialog so that it can reopened as the user last left it. But if the user turns off one monitor and launches our game then…
3
votes
2 answers

File read write using MFC CFile

I'm wondering why the below code not writing correct data to file. If I change the buffer size to some greater amout this code works fine. For the below code, if I try to read a file less than 500 bytes it works good, but for a bigger file simply I…
hypheni
  • 756
  • 3
  • 17
  • 37
1 2 3
99
100