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
28
votes
3 answers

What is `CString`?

Why do I see some code using CStrings declared differently. Some use this format char a_c_string []; While others use CString another_c_string; Is there a difference? All the references I have found on CStrings declare it as I did in the first…
user1768079
  • 683
  • 3
  • 10
  • 18
27
votes
3 answers

Creating a professional-looking (and behaving!) form designer

When I began programming (some 10+ years ago), three things amazed me: Compilers/interpreters (back then I knew them as "programs that make my programs work", often followed by the qualifier "whatever they are") Code editors Form designers Back…
isekaijin
  • 19,076
  • 18
  • 85
  • 153
27
votes
1 answer

Menubar + Commandbar on WM 5.0 and WM 6.5.3

I'm developing a Windows Mobile application, and I faced a problem with CCommandBar, which combines toolbar and menubar. Well, I mean the following: m_wndCommandBar.InsertMenuBar(IDR_MAINFRAME); m_wndCommandBar.LoadToolBar(IDR_MAINFRAME); I have…
Roman Dobrovenskii
  • 935
  • 10
  • 23
27
votes
6 answers

How to prevent MFC dialog closing on Enter and Escape keys?

I know one method of preventing an MFC dialog from closing when the Enter or Esc keys are pressed, but I'd like to know more details of the process and all the common alternative methods for doing so. Thanks in advance for any help.
Laxman Sahni
  • 572
  • 1
  • 6
  • 8
26
votes
9 answers

Where is a good place to start programming GUIs for windows?

I have experience writing console and network client/server applications in C and C++, but I know next to nothing about using the win32 visual API, MFC, Qt, wxWidgets, etc. Where is a good place to start, and what method should I specialize in, so…
Ed.
  • 1,404
  • 4
  • 17
  • 26
26
votes
5 answers

"binary was not built with debug information " warning meaning in mfc application?

I am getting the following Warning when i run my Windows Application(MFC) in Windows 7. 'XXX.exe': Loaded 'C:\2010\Debug\bin\plugins\control\libhotkeys_plugin.dll', Binary was not built with debug information. Please Help Me out.Thank You
vasanth kumar
  • 522
  • 1
  • 5
  • 18
26
votes
5 answers

#error WINDOWS.H already included. MFC apps must not #include

I am getting #error WINDOWS.H already included. MFC apps must not #include windows.h But i dont know how do i find out because of which file this is happening Thanks
Uday
  • 819
  • 3
  • 12
  • 25
25
votes
4 answers

MFC: std::string vs CString?

Using C++ with MFC. Coming from a C# background I typically just use string for all, well, strings. I use them for class members, method parameters, and method return values. Now in C++ I've got std::string, CString, char *, LPCTSTR, and more. …
User
  • 62,498
  • 72
  • 186
  • 247
25
votes
4 answers

How to get the command line arguments in MFC applications?

I wish to have a small dialog based application which is passed command line parameters, so, using VC++6 I ran the application wizard and chose an MFC dialog application. This is not automatically equipped with command-line parameters. So I went to…
karthik
  • 17,453
  • 70
  • 78
  • 122
24
votes
4 answers

how to terminate a process created by CreateProcess()?

I have created a process using CreateProcess(). This is the code: STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; result = CreateProcess("C:\\AP\\DatabaseBase\\dbntsrv.exe", NULL, NULL, NULL, FALSE, 0, NULL, "C:\\ADP\\SQLBase", &si, &pi) How…
digvijay
  • 361
  • 2
  • 4
  • 12
24
votes
10 answers

Windows 7: how to bring a window to the front no matter what other window has focus?

I'm implementing a task-bar replacement, dock-like application-switcher style program. It's doing some unique stuff with OpenGL, and with keyboard shortcuts, so the way it's set up, the window doesn't always have focus. I'd like to implement it such…
jmite
  • 8,171
  • 6
  • 40
  • 81
24
votes
6 answers

Difference between a C++ exception and Structured Exception

Can someone explain the difference between a C++ exception and a structured exception in MFC?
RK-
  • 12,099
  • 23
  • 89
  • 155
24
votes
5 answers

Why #pragma optimize("", off)

I'm reviewing a C++ MFC project. At the beginning of some of the files there is this line: #pragma optimize("", off) I get that this turns optimization off for all following functions. But what would the motivation typically be for doing so?
Stokke
  • 1,871
  • 2
  • 13
  • 18
24
votes
6 answers

error MSB3073: How do I fix this?

3>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(113,5): error MSB3073: The command "copy "C:\Users\jlee\Desktop\10_IPG2.7_4\InitialPowerGadget\Release\EnergyLib.dll"…
CodeDoctorJL
  • 1,216
  • 4
  • 16
  • 29
23
votes
2 answers

How to get size and location of a control placed on a dialog in MFC?

I've got the pointer to the control with function CWnd* CWnd::GetDlgItem(int ITEM_ID) so i've got CWnd* pointer which points to the control, but simply can't find any method within CWnd class that will retrieve the size and location of a given…
dragan.stepanovic
  • 2,955
  • 8
  • 37
  • 66