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
1 answer

MFC : accessing CMainFrame's CImageList from ChildView

I'm trying to add images to imagelist of toolbar, which is a member of CMainFrame startStopPicture.LoadBitmapW(IDB_STOP_PIC); m_ToolBar.GetToolBarCtrl().GetImageList()->Add(&startStopPicture, reinterpret_cast(NULL));…
goodking
  • 145
  • 1
  • 12
3
votes
5 answers

ExitInstance not called in MFC app

Until now, I never really needed the Winapp ExitInstance() of a large MFC (Single Document Interface if it matters) app I'm working on. But now I do, mainly to cleanup memory alocations, unload some DLLs, etc. Well I soon learned by the obvious…
Randy
  • 751
  • 1
  • 6
  • 5
3
votes
3 answers

How to use F10 as a shortcut in an MFC application using a Ribbon

I developed an MFC application using VS2008 and the MFC featurepack. This application UI is using a ribbon. I now need to have F10 as a proper shortcut for one of the critical feature of my application but I seem to be unable to set the accelerator…
Fabien Hure
  • 644
  • 3
  • 7
  • 17
3
votes
2 answers

Calling the event handler programmatically in an MFC application

I am working on an MFC application (C++) My checkbox has an event hander mapped to the ON_BN_CLICKED. It works fine when the user check/uncheck the box, i.e. the event handler is called. However, when I check the box programmatically: ((CButton…
towi_parallelism
  • 1,421
  • 1
  • 16
  • 38
3
votes
3 answers

How do we write some statement to the console screen from an MFC application?

I has a mfc application which I am launching through command prompt. Where I will enter some specified syntax. If I had given wrong syntax, as of now I am showing a message box. But instead of showing message can I write the same message to the same…
Siva
  • 1,281
  • 2
  • 19
  • 41
3
votes
2 answers

Listview flickers on Win32 dialog when removing and re-adding all items and all columns

Consider a plain Win32 dialog with listview control (in report mode) written in C++. Upon a certain event all items and all columns are deleted and new columns and items are created. Basically, as content changes, columns are automatically generated…
wpfwannabe
  • 14,587
  • 16
  • 78
  • 129
3
votes
1 answer

Breaking on a button click event in Visual Studio debugger

This question is regarding the debugger in Visual Studio 2008. I am working on a C++/MFC application with a huge codebase (thousands of .cpp files). I'm looking for a way to tell the debugger, "The next time I click a button in my app, stop at the…
psteiner
  • 187
  • 3
  • 17
3
votes
3 answers

Where can I see printf output in an mfc applcation?

Where can I see printf output in an mfc application during debugging? Is there a "console" window I can view in the debugger? (Visual Studio C++ 6.0) Thanks.
T.T.T.
  • 33,367
  • 47
  • 130
  • 168
3
votes
1 answer

In MFC When EndDialog() is called, when does class destructor fire?

In MFC, for the typical dialog window, when OnOK() is called by MFC, this function calls the EndDialog() function, and somehow the class destructor is called at some point. Suppose I have a public variable, a string named "test", in the CDialog's…
Blitz
  • 33
  • 4
3
votes
1 answer

Console prompt window appear on system("start dir") but not on system("start ipconfig")

I try to create a simple UI which runs a command prompt in the background (but the windows console must not disappear) while clicking on each button, resp. But before, I try something like system("start dir"); to see if the button works. Here is the…
aGer
  • 466
  • 1
  • 4
  • 17
3
votes
1 answer

Having trouble using settimer() for MFC application

I set up this this code so I can have a timer for a minesweeper game but I can't get it to compile. void CALLBACK CMineSweeperBoard::clock(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime) { if (t_seconds < 59){ t_seconds++; } else{ …
3
votes
1 answer

Create a control dynamically in an MFC application

According to this link from Microsoft, it should be possible to define a CButton and specify its parent window (CDialog) without having the CButton as a member of the Dialog, but I couldn't do it. So if myButton is a member of a CDialog-derived…
towi_parallelism
  • 1,421
  • 1
  • 16
  • 38
3
votes
1 answer

Can a dialog intercept drag'n'drop messages passed to its controls?

If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
0 answers

Is MFC supported in the Community Version of Visual Studio?

I am migrating some programs from an ancient version of Visual Studio to Visual Studio Community Version 2013. A few of my projects use MFC. I am unable to convert these; the immediate problem being the lack of include files such as... #include…
Mike D
  • 2,753
  • 8
  • 44
  • 77
3
votes
1 answer

Zoom Bitmap Image from center in mfc

I am new to MFC. How to zoom Bitmap image from center. In my code image is zooming from top left corner. But image should zoom from center in scrollbar.. void CRightUp::ImageDraw(int sHeight,int sWidth){ CDC *screenDC = GetDC(); CDC mDC; …
abhi312
  • 364
  • 1
  • 6
  • 25