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

Difference between CTypedPtrArray and CArray

MFC has two similar templated container classes: CTypedPtrArray and CArray. CTypedPtrArray is supposed to be an array of typed-pointers, while CArray can be an array of any type (including pointers), and I see nothing in the documentation that…
abelenky
  • 63,815
  • 23
  • 109
  • 159
3
votes
1 answer

Unicode characters become question marks (C++ and MFC Dialog Based App)

These codes sets the values to editbox. But I'm having trouble when I retrieve Unicode characters from MySQL table. For example, string nüşabə sets as nüşabÉ™. Here is my codes. void CmysqlDlg::OnBnClickedButton3() { USES_CONVERSION; try …
Mirjalal
  • 1,292
  • 1
  • 17
  • 40
3
votes
3 answers

Parent notification in MFC Dialog

I have a first dialog with a simple button on it and while clicking the button, a second dialog is created using CDialog::Create(IDD,this). I would like the parent to be notified when the second dialog is destroyed but without adding any code to the…
Ryan
  • 477
  • 5
  • 12
3
votes
3 answers

Fast move CString to std::string

I'm working in a codebase with a mixture of CString, const char* and std::string (non-unicode), where all new code uses std::string exclusively. I've now had to do the following: { CString tempstring; load_cstring_legacy_method(tempstring); …
Adversus
  • 2,166
  • 20
  • 23
3
votes
1 answer

Create CFrameWnd gives first-chance exceptions--why?

I'm attempting to write a simple MFC app that draws in a scrollable window, using code based on CFrameWnd. The code below is adapted from Prosise "Programming Windows with MFC", 2nd ed, pp 89ff. When I run this in the debugger, I get two…
Woody20
  • 791
  • 11
  • 30
3
votes
2 answers

error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject' afxwin.h

I'm trying to make class responsible for putting some text on grey bg: Score.h #pragma once class Score { public: Score(); ~Score(); void UpdateScore(int points); void UpdateLives(int lives); int GetScore(){ return m_iScore; } …
mielu
  • 63
  • 2
  • 8
3
votes
1 answer

Registered Window Message TaskbarButtonCreated not received

I am wanting to start looking at the Windows 7 TaskBar API. I have created a basic MFC Dialog Project but after registering the TaskbarButtonCreated message, it never gets sent to my WindowProc. Here is what I have: LRESULT…
Shane Haw
  • 723
  • 9
  • 22
3
votes
1 answer

Conversion from SYSTEMTIME to time_t gives out Time in UTC/GMT

I am trying to convert SYSTEMTIME to time_t through the implementation I found in various forums. time_t TimeFromSystemTime(const SYSTEMTIME * pTime) { struct tm tm; memset(&tm, 0, sizeof(tm)); tm.tm_year = pTime->wYear - 1900; // EDIT…
Sathish Guru V
  • 1,417
  • 2
  • 15
  • 39
3
votes
2 answers

Find which MFC child window would receive a mouse click

So, I have a plugin to an MFC program. I'm using a mouse event hook (from SetWindowsHookEx) to capture clicks. The host application can have any number of (possibly overlapping) child windows open, but I only want to intercept clicks in a…
tfinniga
  • 6,693
  • 3
  • 32
  • 37
3
votes
1 answer

How to activate "disable display scaling on high dpi settings" by default

Our application does not work correctly on some Windows 8.1 devices with high DPI settings (150% or higher). Specifically, we are hosting embedded web browsers using CEF. All these embedded CEF browsers are rendering the elements offset. The…
James Bateson
  • 1,069
  • 13
  • 20
3
votes
0 answers

MFC modal dialog disables main window

How can I make a modal dialog modal only to its immediate parent? In other words, if I have 3 windows: main, a modeless one created from main, and a modal created from the modeless one, the modal dialog prevents user interaction with its parent -…
Rado
  • 8,634
  • 7
  • 31
  • 44
3
votes
1 answer

How to stop a MFC/win32 control re-painting

I have a CRichEditCtrl, and an algorithm works on its contents in-place, iterating through the contents and making changes. This seems to cause it to re-paaint every time, which causes flickering and a noticeable time to complete the operation,…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
1 answer

How to prevent or turn off direct2d "autoscaling" of a bitmap?

I have a problem with Direct2D bitmap scaling. I loaded a bitmap from a file using that example, then I wanted to scale bitmap by myself (fit to view saving proportions, add a shadow effect…) but Direct2D automatically scales bitmap (e.g. while…
Craftsmann
  • 95
  • 1
  • 10
3
votes
1 answer

How do I draw a rounded rectangle without filling it (in MFC)?

Another drawing question for you MFC/GDI gurus out there... :-) I'm using MFC, and I'm doing some drawing with a CDC object. That works fine. But now I want to draw a rectangle with rounded corners, the line being a couple of pixels wide. But I dont…
UglySwede
  • 429
  • 1
  • 7
  • 16
3
votes
2 answers

Mixing MFC and WPF: Modal Dialogs

I'm adding C# WPF dialogs to an existing C++ MFC app, using a C++/CLI interface layer. I've got things working, except I'm having a problem with modality. For example: MFC app shows a WPF dialog using ShowDialog. Works as expected. That WPF dialog…
Joe
  • 3,827
  • 1
  • 25
  • 37
1 2 3
99
100