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
17
votes
7 answers

How Can I Monitor Which Window Currently Has Keyboard Focus

Is there a way to track which window currently has keyboard focus. I could handle WM_SETFOCUS for every window but I'm wondering if there's an alternative, simpler method (i.e. a single message handler somewhere). I could use OnIdle() in MFC and…
jmatthias
  • 7,375
  • 7
  • 27
  • 36
17
votes
4 answers

Dynamic menu using mfc

I would like to add a menu item to my main menu and then populate it with items at run time. How would I do this? And besides adding items how would I have a message map entry for them since I do not know the id?
Ira
  • 173
  • 1
  • 1
  • 4
17
votes
4 answers

What if I don't call ReleaseBuffer after GetBuffer?

From CString to char*, ReleaseBuffer() must be used after GetBuffer(). But why? What will happen if I don't use ReleaseBuffer() after GetBuffer()? Can somebody show me an example? Thanks.
Landy
  • 379
  • 1
  • 4
  • 10
17
votes
3 answers

UTF-8, CString and CFile? (C++, MFC)

I'm currently working on a MFC program that specifically has to work with UTF-8. At some point, I have to write UTF-8 data into a file; to do that, I'm using CFiles and CStrings. When I get to write utf-8 (russian characters, to be more precise)…
SeargX
  • 117
  • 1
  • 2
  • 10
17
votes
4 answers

How to convert std:string to CString in unicode project

I have a std::string. I need to convert this std:string to a Cstring. I try to use the .c_str() but it's only for non-unicode project and i use unicode project ( because non unicode project are depreceated wiht VS2013). Anyone could show my how to…
Walter Fabio Simoni
  • 5,671
  • 15
  • 55
  • 80
17
votes
2 answers

How do I control the text input panel programmatically (TabTip.exe) in Windows Vista/7

I'm adapting an application for touch screen interface and we want to use the tablet text input panel included in Windows Vista/7, specifically its keyboard. I want to show and hide it as appropriate for my app. Basically I want ShowKeyboard() and…
Yngve Hammersland
  • 1,634
  • 2
  • 14
  • 28
17
votes
3 answers

How to send a string via PostMessage?

Inside my app, I want to send a message to a dialog from a different thread. I want to pass an std::exception derived class reference to the dialog. Something like this: try { //do stuff } catch (MyException& the_exception) { …
LLucasAlday
  • 2,349
  • 11
  • 34
  • 41
16
votes
2 answers

What does the acronym IDC mean?

Does anybody know the meaning of the acronym IDC as it is used when programming windows? e.g. in the context of a CDialog application: void CMyDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX,…
yussuf
  • 635
  • 1
  • 4
  • 18
16
votes
3 answers

cannot open source file "afxwin.h"/"afxext.h"/"afxdisp.h"/"afxdtctl.h"/"afxcmn.h"/afxdisp.h etc

I try to ran a previous written MFC c++ code on my visual studio 2015 MFC with multitype MFC library installed. However, I still have 12 errors here regarding missing function: IntelliSense: cannot open source file "afxwin.h" C1083 Cannot open…
Curly
  • 539
  • 2
  • 7
  • 14
16
votes
5 answers

How To Get System Folder Path(C:\Windows C:\Program Files) in Windows using C++?

I am programming in c++ MFC, I want to get "C:\windows" "c:\program files" folder path. Sometimes user may setup windows in other folder such as c:\windows0. Is there any API to get absolute path of the windows and program files path? Many…
sxingfeng
  • 971
  • 4
  • 15
  • 32
16
votes
5 answers

What are the possible classes for the OpenThemeData function?

I'm trying to call the OpenThemeData (see msdn OpenThemeData) function but I couldn't determine what are the acceptable Class names to be passed in by the pszClassList parameter. HTHEME OpenThemeData( HWND hwnd, LPCWSTR…
Kiril
  • 39,672
  • 31
  • 167
  • 226
16
votes
6 answers

how to find a window's SW_SHOW/SW_HIDE status

I am trying to determine a window control's visibility that has been hidden or enabled with CWnd::ShowWindow(). (or ::ShowWindow(hWnd,nCmdShow)) I cannot simply use ::IsWindowVisible(hWnd) as the control is on a tab sheet, which may itself be…
geocoin
  • 1,281
  • 1
  • 14
  • 30
15
votes
6 answers

How to set default font for all the windows in a Win32 Application?

I want all the controls (edit,list control, etc) in my application to be having the same font which is not the system default. How do i do this? Is there any Win32 API that sets the application default font?
Canopus
  • 7,351
  • 11
  • 46
  • 57
15
votes
5 answers

Preventing multiple instances of my application

ADDITIONAL INFORMATION Again i am writing on the above issue (Preventing multiple instances of my application) the code works for if i start two instances from programe menu/desktop shortcut. but in my envrironment, one instance is running from…
Sweta Priya
  • 183
  • 2
  • 2
  • 7
15
votes
4 answers

What are Windows "USER objects"

I'm trying to track down an issue in our MFC code that looks like a resource limitation issue. Memory and CPU look fine. According to the processes tab on the Task manager our GDI objects look in line with other applications, but our USER objects…
JonDrnek
  • 1,414
  • 3
  • 19
  • 37