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
0 answers

MFC app will CrashRpt slow down the app performance?

I'm thinking of using CrashRpt open-source library but I'm worried about performance. The app performance requirement is critical so it's very importing not to slow it down. The author affirms that there's no performance degradation but I would like…
manujcm
  • 163
  • 11
3
votes
3 answers

Proper usage of the windows user profile directory

I need to create a directory inside a windows users 'home' directory (c:\Documents and Settings\someusername\ or c:\users\someusername\). This directory will exist permanently but will only contain temporary files. What is is the best location for…
theycallmemorty
  • 12,515
  • 14
  • 51
  • 71
3
votes
3 answers

How to get C++ MFC Control HANDLE by it's id?

I have for example IDC_EDIT1 C++ MFC Controls , How Can I get its handle ? By which Windows API , Can I done it ?
Majed Maniat
  • 37
  • 1
  • 1
  • 5
3
votes
2 answers

Can Right-mouse click events be detected on a MFC Button control?

I am trying to create a dialog with multiple buttons, which change color on left and right clicks respectively. So, how can I handle the right click event for specific buttons ?? ON_RBUTTONDOWN doesn't work for specific buttons.
Tarang Gupta
  • 139
  • 1
  • 3
  • 13
3
votes
2 answers

Is it possible to widen a message box in MFC?

I display a message box using the AfxMessageBox keyword. Basic stuff. But, due to the length of the path, it displays like this: Is there any way that I can stop it from word wrapping that way? Sorry if this is a dumb question. But if I have a…
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
3
votes
1 answer

Listening to keyboard events in MFC within PreTranslateMessage()

I was trying to use the following code to listen to simple keyboard events in a dialog based application, but nothing is happening on pressing these keys. Can somebody tell me what went wrong ? BOOL PreTranslateMessage(MSG *pMsg) { CListeningApp*…
Tarang Gupta
  • 139
  • 1
  • 3
  • 13
3
votes
2 answers

Unable to retrieve regex match results - MFC / C++

I am reading an HTML page and trying to retrieve a specific string within it. I have the following code: std::string str = test.GetString(); // someString ( the string i have checked it, it's basically an html page ) std::smatch match; …
Rana
  • 1,675
  • 3
  • 25
  • 51
3
votes
3 answers

MFC CWnd height and width

How do you get the height and width of a CWnd*? The CWnd is the window correct? Why isn't the command: CWnd* parent = this->GetParent(); // C++ command parent->GetSize(); // what I think the method should be OR ... parent->GetWindowRect(); // what i…
Fractal
  • 1,748
  • 5
  • 26
  • 46
3
votes
1 answer

Concatenate string and constant in resource file in C++ (MFC)

I have a C++ project with MFC and a resource file. In my About-Dialog I want to add a constant which contains the version of the programm. IDD_ABOUTBOX DIALOG DISCARDABLE 34, 22, 237, 65 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION |…
Premox
  • 323
  • 10
  • 25
3
votes
1 answer

Determine windows DPI settings programmatically?

we've got a problem with one of our non dpi aware MFC applications. If you change the system setting to high dpi (e.g. 120 or 144 dpi), the application icon on the taskbar looks screwed up. Unfortunately, we have to register our own WNDCLASS for the…
humbagumba
  • 2,054
  • 15
  • 16
3
votes
1 answer

How do I use WTL::CHyperLink?

I am trying to use WTL::CHyperLink in order to display a clickable link on my application. According to this article, I need to attach it to a Static Text control. So, in my GUI, I have now created a static text control with an ID of IDC_LINK In my…
Sossenbinder
  • 4,852
  • 5
  • 35
  • 78
3
votes
1 answer

"Always show selection" doesn't work on CListCtrl in list mode

I want a user to be able to select item(s) in my CListCtrl and then click on a button to act on those items. But when the focus is lost from the list, the selection is no longer shown, even if I set 'Always show selection' to true: This happens…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
3
votes
1 answer

Dialog border different after porting code from Visual Studio 6 to Visual Studio 2013

I have just ported a dialog based MFC program from Visual Studio 6 to to Visual Studio 2013. There were no major issues and the program runs perfectly once compiled under VS 2013. The only visible difference is the thickness of the dialog's borders…
Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
3
votes
2 answers

Do Applications written with MFC classes require external Frameworks to be installed

If I write an application using MFC libraries in C++, in deployment stage do I require to install some sort of frameworks or stuff like that? My intent is to have a standalone exe without complicated installation scripts.
Claudio Ferraro
  • 4,551
  • 6
  • 43
  • 78
3
votes
2 answers

Does LVS_EX_FULLROWSELECT have any compatibility issues with other styles?

I am trying to set the LVS_EX_FULLROWSELECT style on my grid list control as I want full row selection. However apparently it doesn't have any effect. Since I am using a number of other styles as well, I am wondering if LVS_EX_FULLROWSELECT has any…
Jahanzeb Farooq
  • 1,948
  • 4
  • 27
  • 27