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

Where do I put the code to initialize my controls?

I have now tried several times to find a place where I can insert a code part which basically only adds a column to a control I have in my dialog: void MusicPlayerDialog::InitList() { m_trackList.InsertColumn(0, "Tracks"); …
Sossenbinder
  • 4,852
  • 5
  • 35
  • 78
3
votes
2 answers

C++ - How can I find out where the current thread was created?

I'm working on a huge C++ MFC GUI app using Visual Studio 2010 that's got tons of code the I'm unfamiliar with. There's a thread that's being spawned way too many times, and I'm not sure where it's being spawned as there's lots of code that spawns…
taha
  • 172
  • 8
3
votes
2 answers

How can I print other language characters in Microsoft C++?

We can print any English character with log by putting "%c". Take an another case. Keyboard layout has been changed. Now my input is some Korean/chinese language. We can not simply put "%c" in log to print those characters. How can we achieve this…
3
votes
6 answers

Searching for Holy Grail of search and replace in C++

Recently I was looking for a way to replace tokens in string which is essentially find and replace (but there is at least one additional approach to the problem) and looks like quite banal task. I've came with couple of possible implementations but…
kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
3
votes
2 answers

How to read a character not included in ascii in c++?

I'm going through a folder of files editing the titles. I am trying to remove a certain piece of the title but the bracket used to separate in the title is not a standard ascii so I can't figure a way of removing it. This is a sample of the title: …
3
votes
1 answer

MSHTML vs EdgeHTML

I have a Windows Desktop application that is written in C++/MFC/COM technologies. This application relies heavily on CHTMLEditView (MSHTML Editing platform) and extensively uses IHTMLxxx COM interfaces. It seems to be working fine on Windows 10…
user4617883
  • 1,277
  • 1
  • 11
  • 21
3
votes
1 answer

How to convert CString to integer and float?

I am trying to convert CString to int and float but unable to find any C++ library function to get this done. please help.
AnasShoaib90
  • 629
  • 2
  • 7
  • 14
3
votes
2 answers

Lock file but allow usage by current process?

I want to be able to lock a file in Win32 so that it can only be used by my current process. The most obvious way to accomplish that seemed to be via CreateFile: HANDLE file = ::CreateFile("c:\\foo.txt", GENERIC_READ |…
Peter
  • 7,216
  • 2
  • 34
  • 46
3
votes
1 answer

Is it possible to hide (or undefine) a typedef?

To avoid confusion and possible errors, is it possible to hide or undefine a typedef. I do a lot of c++ and java at the same time. In java, the boolean type is boolean, and in c++ it's bool. The problem is that somewhere in the windows c++…
Goldorak84
  • 3,714
  • 3
  • 38
  • 62
3
votes
2 answers

convert CString to CTime

In smart device MFC application: I have successfully converted CTime to CString. Now I want to convert it back, CString to CTime. How can I do that?
user001
  • 444
  • 5
  • 10
3
votes
1 answer

Menu item keeps disabled even after ON_COMMAND handler is added

I've made a simple split-window application using Visual Studio 2013. There are two views, one view is made of default-view-class and the other view is made of custom-view-class derived from CScrollView. ///////////////////////// //…
Walter.JJ
  • 31
  • 1
  • 5
3
votes
2 answers

C++ File Write includes the memory address of the string instead of the contents

All, I'm still learning C++ but I have an issue in a project I'm tinkering with that I'm curious about. I've noticed that when I try to print the contents of a string that is a member of a class, I get the memory address instead of the contents. I…
sallou
  • 99
  • 9
3
votes
2 answers

Do not allow right click selection on the list control items mfc?

I want not to allow selection on the list control items when I try to select the item using right click and should show the selection if left click on the item. I tried handling it in NM_RCLICK event to prevent right click selection as follows: …
Siva
  • 1,281
  • 2
  • 19
  • 41
3
votes
1 answer

How to fix error with sample code for MFC tooltips?

I get this error when compiling the following source from here: Error 1 error C2440: 'static_cast' : cannot convert from 'UINT (__thiscall CStaticLink::* )(CPoint)' to 'LRESULT (__thiscall CWnd::* )(CPoint)' …
Tim
  • 20,184
  • 24
  • 117
  • 214
3
votes
2 answers

How to move a control while resizing dialog size in MFC?

I've made a view on dialog in MFC. You can see well from the following image.(like slider control and edit box, etc) These controls are not moved when I resize a dialog size. enter image description here I'd like to move the controls to fit dialog.…
cabot
  • 73
  • 1
  • 7