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

MFC C++ CListBox get selected item

First let me say that I've been searching for a solution for couple of days now... I'm trying to get selected item for ListBox. This is my code: CListBox * pList1 = (CListBox *)GetDlgItem(IDC_LIST1); CString ItemSelected; // Get the name of the…
3
votes
0 answers

Detecting WinXP SP3 using MFC/C++ code returns true even in WinXP SP2

Under windows 7 64bit I run my C++ app using compatibility mode "Windows XP service pack 2" and the following code which detects WinXP SP3 returns "TRUE" while it shouldn't. What seems to be wrong here ? BOOL CUtils::Is_WinXP_SP3_or_Later() { …
Maverick
  • 1,105
  • 12
  • 41
3
votes
4 answers

Remove "Untitled - " from main frame window caption

I have an MFC document application where I want to remove the "Untitled - " from the caption. It way my understanding that I need to remove the 'AddToTitle' property from the window style, and then I can set the title, and the'untitled' string would…
netcat
  • 1,281
  • 1
  • 11
  • 21
3
votes
1 answer

How to change the advanced setting from registry

Hi i am trying to change the elements in advanced setting from registry. I am able to change the values, but there is not change in User Interface i.e,(Font Smoothing). what i need to do after changing the values in registry??
Nitin R G
  • 75
  • 7
3
votes
1 answer

Changing CFrameWnd to CFrameWndEx in MFC causes unhandled exception - any ideas?

Still getting used to this MFC lark and I've hit a brick wall on this particular problem. I'm updating some legacy code to use some of the more refined controls available in the MFC Feature Pack. Following the examples given online for updating an…
Monobounce
  • 108
  • 1
  • 8
3
votes
3 answers

SSL Socket in Windows. Library? Synchronous/Asynchronous? Threads?

I have a 2 threads application. One GUI thread and one worker thread (CWinThread) in which I make time consuming operations - calculations and HTTP comunication. I have to switch from HTTP to SSL socket connection. I also need to make a…
Julian Popov
  • 17,401
  • 12
  • 55
  • 81
3
votes
1 answer

[MFC/C++]Sending CBitmap's bits over socket, and re-construct it on receiver side

I am new with MFC and try to learn it with a project of MFC dialog base on VS2008. Here are the archivements I have done: First, I have managed to display a list of pictures from a folder to a Listbox Control. After that, I also handled the click…
Trung Nguyen
  • 177
  • 1
  • 12
3
votes
1 answer

How to add a gripper to a PropertySheet?

I have a class derived from CPropertySheet, and i want to insert a "gripper" on the bottom right of the dialog. my dialog already is resizable, i just can't insert the gripper.
Penachia
  • 389
  • 4
  • 18
3
votes
3 answers

why does thread procedure should be static or member function

why does thread procedure should be static or member function? any valid reason?
Naruto
  • 9,476
  • 37
  • 118
  • 201
3
votes
1 answer

C++ How can i trigger that a PostMessage was proceed in another thread

I have a MFC-C++ application where at least two threads are running "MainFrame" (=GUI thread) and a "Solver" thread. At one point the second thread (Solver) initiate a change in the model which the GUI thread should execute by a PostMessage(...). To…
3
votes
1 answer

Save a portion of my program’s own window to a bitmap file using mfc/win32

Within my mfc program, I need to programmatically capture a portion of that program’s own window, then save it out as a file (bmp or jpg etc). How to do this without using 3rd party library?
jmc
  • 51
  • 1
  • 4
3
votes
4 answers

Making a c# winforms application useable as a dll from an unmanaged mfc application

I'm wondering how I would go about converting an existing c# winforms application to a class library and then call it from an mfc application. Are there any references on how to do this? I've tried googling, but, besides the fact that it will need…
Tim
  • 31
  • 2
3
votes
2 answers

Maximized Window Restores to Full Screen

Using CWnd::ShowWindow(SW_SHOWMAXIMIZED) maximizes my app window as expected. However, when clicking the restore button on the app (or double clicking the title-bar), the restored size is the same size as the maximized window, which is confusing for…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
3
votes
1 answer

In MFC, how can WinMain function find user application object's address value?

Greeting, I'm novice in MFC area. I have a question about process of starting MFC application. I learned that unlike SDK program, I don't have to write WinMain. Because It is supplied by the class library and is called when the application starts…
구마왕
  • 488
  • 6
  • 20
3
votes
0 answers

How to use filtered views with ATL OLE DB

I am developing an MFC application that accesses a mysql database. For connectivity I created a consumer class based on CCommand by using the ATL templates (nothing special). Now I want to filter my data based on certain criteria. I am aware of the…
Bart
  • 547
  • 3
  • 16