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

How to write a scrollable MFC custom control?

I want to write my own chart control which requires scrolling. I found that there is a CScrollView but nothing like this for a control. Other toolkits like Cocoa, QT or GTK offer me a base class where i can set a content view which is displayed in a…
Lothar
  • 12,537
  • 6
  • 72
  • 121
3
votes
1 answer

How to make a dictionary of synchronization objects?

What I need is something like std::map but CCriticalSection is non-copyable. Instead of CCriticalSection I thought I could use CRICITAL_SECTION but it's also not possible to copy or move objects of this type. Because…
Christian Ammer
  • 7,464
  • 6
  • 51
  • 108
3
votes
4 answers

Drawing a jpg in MFC

I've been trying to show a jpg image in MFC, but I can't get it drawn. I'm a complete MFC newbie an everything I got up until now is mostly adapted from things I found on the net. Currently I have this: Picture.h: #pragma once #include…
Tekar
  • 105
  • 2
  • 8
3
votes
1 answer

How to send CString through sockets?

I'm trying to program a chatting program. I ask you guys for help since I have little problem. when I try to send a CString formatted strings, it only receives first letter of the string. I'm using CAsyncSocket for sockets. I tried it with char*…
백경훈
  • 101
  • 4
3
votes
1 answer

changing GLUT calls to work with MFC/C++

I have a program that uses GLUT for its OpenGL rendering. Now I need it to be inside of a MFC project so that it can work with another program component. I've followed this tutorial:…
laurenelizabeth
  • 786
  • 1
  • 7
  • 19
3
votes
1 answer

How to scroll CTreeCtrl item to center

I have a CTreeCtrl object (C++, MFC). This CTreeCtrl remembers the last selection and if the user opens the window again the last selection will be expand and select automatically. But when I call EnsureVisible to show the last selection, it appears…
Simon Hilner
  • 85
  • 2
  • 11
3
votes
1 answer

Windows API SetWindowSize() seems to have no effect

I have what should be an extremely simple goal yet it seems intractable. I have to get some precisely-sized screen pix for documentation so I thought it would make sense to add a control to size my app's window to the exact dimensions I want. I'm…
vacuumhead
  • 479
  • 1
  • 6
  • 16
3
votes
4 answers

Maximum length of double value?

I am getting buffer overflow: Format String warning from hp fortify. Can you please let me know the maximum length a double value can have? In the following example dCode is a double value which is stored in pszPref. Code: TCHAR…
Tansheet
  • 79
  • 2
  • 5
3
votes
1 answer

IMFSinkWriter can't export a large size video of mp4

My Windows MFC application has a function to export a video file. And it can select encoding format (via WMV or MP4) and frame size. But, Unfortunately when i tried to export MP4 file which is set large frame size, everytime MF_E_INVALIDMEDIATYPE…
dosuken123
  • 438
  • 3
  • 7
  • 19
3
votes
2 answers

Mouse Move Capture (Mouse leave & Mouse Enter)

Hi i have three controls (CButtton) in my application,whenever mouse move over a control,i want to capture when mouse enters on which control in a window and when it leaves and i have to change the caption of a button control. Thanks in Advance
shiv
  • 31
  • 1
  • 2
3
votes
1 answer

bass lib not linking, all other work perfect

I'm having a wierd problem. i'm developping a nice game with openGL on MFC. i need to use threads for multi sound. so i am trying to use the BASS lib for that. For a reason that is beyond my comprihention, i can not get the bass.lib to link. all…
Erez
  • 1,933
  • 5
  • 29
  • 56
3
votes
1 answer

SendMessage/PostMessage to a derived CView class not working for MFC application

I am building a test application(testApp) for a legacy MFC based application (MFC-app). I am trying to simulate mouse clicks on the MFC-app using message-passing between them. I was able to do this successfully for bring up dialog boxes from the…
veekay
  • 65
  • 2
  • 7
3
votes
1 answer

PostThreadMessage C++ (CWinThread)

i'm using MFC C++ and I'm trying to send message to CWinThread using PostThreadMessage from Dlg Class and the message isn't handled on the thread class .H file of the thread: #define Message_Test_Id WM_USER + 1 class CTestMsg : public…
user5255862
3
votes
3 answers

Error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'const std::ofstream' (or there is no acceptable conversion)

I am working on an MFC Application and have declared an ofstream object in a class header, the object is then initialized in the constructor and used in the other methods of the same class. I got the following error: Error C2678: binary '<<' : no…
Itban Saeed
  • 1,660
  • 5
  • 25
  • 38
3
votes
2 answers

using MFC CMap for CString int pairs

I'm currently working on a DLL that needs to convert back and forth between the friendly name for a value and the value itself. As this code is used in many places throughout the codebase, I want to try and keep it simple and in a single function or…
James Kent
  • 5,763
  • 26
  • 50