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
2 answers

CMFCOutlookBarTabCtrl::SetActiveTab not working

I have added a CMFCOutlookBar control to a dialog. This outlookbar contains some 12 trees. As per following link https://msdn.microsoft.com/en-us/library/bb983453.aspx we can set active tab (in my case tree control) of our wish. but it doesn't seems…
Yogesh
  • 1,565
  • 1
  • 19
  • 46
3
votes
2 answers

C++ MFC how to use GetDlgItem()

This is in the main "example dlg.cpp" file: void CHelixV3Dlg::OnBnClickedCancel() { CEdit* editbox = (CEdit*)GetDlgItem(IDC_EDIT1); //works fine, defined as: *CWnd GetDlgItem(int nID); in this file } This is test.cpp source file void…
Nullptr
  • 221
  • 2
  • 5
  • 11
3
votes
3 answers

How to move window by right mouse button using C++?

I need to move window by right mouse button. The window has no caption, titlebar. By left button it works void CMyHud::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default …
Nika_Rika
  • 613
  • 2
  • 6
  • 29
3
votes
2 answers

Okay to compare pointers returned by RUNTIME_CLASS() macro?

I've got a function that takes a list of CRuntimeClass pointers in order to setup a view. I'd like to return without doing anything if the function is called with a list of the same classes that are already setup. Saving the pointer values and…
Kurt Hutchinson
  • 2,959
  • 23
  • 30
3
votes
0 answers

CDatabase ExecuteSQL works, but doesn't for insert

I have an MFC application using OBDC to access the MS Access Database. I am trying to insert a new record into the table, but I get a First-chance exception at 0x7705C44D in WinPASS.exe: Microsoft C++ exception: int at memory location…
Skynight
  • 507
  • 2
  • 7
  • 24
3
votes
2 answers

Is it possible to change Pictue Control background color istead of Changing image?

I am trying to change color of a Picture Control box Which I added to a Dialog box in Microsoft Visual C++ environment. I did these Procedure: In Resource file-> Dialog editor I added a Picture Control box(Type=Rectangle) I had a look at this…
J2015
  • 320
  • 4
  • 24
3
votes
1 answer

the disappearance of the child window when when the parent window redrawn

I created child window (dialog) end set it's parent the window of another process (Notepad for example) by its handle. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); if (NULL != hProcess ) { …
Nika_Rika
  • 613
  • 2
  • 6
  • 29
3
votes
2 answers

how to load image from file using MFC

My browse button code is void CFileOpenDlg::OnBnClickedButton1() { // TODO: Add your control notification handler code here CFileDialog dlg(TRUE); int result=dlg.DoModal(); if(result==IDOK) { path=dlg.GetPathName(); UpdateData(FALSE); …
Sweety Khan
  • 41
  • 1
  • 1
  • 2
3
votes
1 answer

MFC Message flow for controls?

In MFC, suppose I have a dialog box, and in this box, it has a child CListCtrl, then I use mouse to click this CListCtrl, we know that eventually an WM_LBUTTONDOWN message is sent to CListCtrl. My question is: How does this WM_LBUTTONDOWN message…
wangshuaijie
  • 1,821
  • 3
  • 21
  • 37
3
votes
1 answer

Wrong CListCtrl items drawing

I have my CListCtrlEx derived from CListCtrl. This list have style LVS_REPORT, LVS_OWNERDRAWFIXED and LVS_EX_GRIDLINES. I have added possibility to change font for this list. This works fine, but there is one bad thing - if I change font and before…
brightside90
  • 243
  • 3
  • 13
3
votes
2 answers

Obtaining MFC Feature Pack GUI elements in .NET WinForms

The MFC Feature Pack (and VS 2010) adds out-of-the-box support for several "modern" GUI elements (such as MDI with tabbed documents, the ribbon, and a Visual Studio-style interface with docking panels). These are a boon to those of us that have to…
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
3
votes
1 answer

Focus not changing upon tab key in a nested CWnd-Derived Class

Environment: VS2013, MFC, C++ I have a CDialog derived dialog with 2 static buttons (OK, Cancel), created with the dialog editor. Additionally the dialog should contain a dynamically created instance of a CWnd-Derived class, which contains 2 edit…
suriel
  • 191
  • 1
  • 10
3
votes
1 answer

What are the consequences of not calling GdiplusShutdown before exiting an application?

I'm currently working on a legacy MFC application and I noticed that there was a missing call to GdiplusShutdown() before exiting the application. The documentation clearly states that each GdiplusStartup call must be paired by a call to…
rold2007
  • 1,297
  • 1
  • 12
  • 25
3
votes
0 answers

Intel Inspector cannot find debug symbols Visual C++ MFC

I have just started to try out the Intel Inspector software for memory analysis in my Visual C++ MFC projects. The analysis run fine and some errors are found by the tool. However, I cannot naviage to the problem source files and code lines because…
10100111001
  • 735
  • 15
  • 31
3
votes
1 answer

Why are images not appearing on subitems in mfc CListView/CListCtrl?

I've created a very simple view derived from CListView, and I want to be able to show images on each column of my CListView. To do that I know that I have to use LVS_EX_SUBITEMIMAGES and use SetItem to set the Image in the sub item, simple as that,…
Robson
  • 916
  • 5
  • 22