This project has been moved to GitHub. New location: https://github.com/mariusbancila/mfccollectionutilities C++11 has provided support for range-based for loops. They allow iterating over the elements of a range without using an index. std::vector<int> v = {1, 2, 3, 4, 5}; for(auto& e : v) e *= 2; However, if you try the following MFC code you…
Category: MFC
Visual Studio 2012 Debugger Visualizer for CPtrArray
CPtrArray is a nasty MFC container that should not be used. However, if you deal with legacy code you may not have a choice and have to work with it. Unfortunately, the Visual Studio debugger is not able to display its elements, since these are pointers to void and that can be anything. In this…
Bindings for DataGridView hosted in an MFC application
A WinForms DataGridView control has the ability to automatically generate its columns and populate from a specified data source (which can be a DataSet, a simple list or something else). All you have to do is something like this: var list = new List<Record>() {new Record() {Id = 1, Name = “item 1”, Date =…
Second CDatabase bug in MFC in Visual Studio 2012
I was writing recently about an MFC bug in CDatabase class in Visual Studio 2012. In the meanwhile I have stumbled upon an even greater bug (check this report on Connect for the details): when the OpenEx function fails (wrong credentials, service not reachable, machine is shot down etc.) it corrupts memory. What happen next…
CDatabase bug in MFC in VS2012
After migrating an MFC application from Visual Studio 2008 to Visual Studio 2012 I run into an unexpected error: the application was having problem fetching data from the SQL Server database. After debugging it turned out that function CDatabase::GetConnect that I was using to retrieve the connection string after opening the database (for different purposes)…
Keyboard input and TAB navigation between WPF controls in a Win32 application
It is possible to host WPF controls in a Win32 application, and the other way around, but because of the differences betweeb these technologies there are various issues that can appear. One of these is handling of keyboard input. Without diving too much into differences between WPF and Win32, I will show how to provide…
A tale of two flags: DS_CONTROL and WS_EX_CONTROLPARENT
I recently ran into problems with an MFC application that was hosting some Windows Form user control in a modal dialog; the application hanged after it lost focus. The problem was the window received WM_GETDLGCODE message in an infinite loop making it impossible to handle anything else. After a lot of digging, I found that…
Sorting a CTreeCtrl
The CTreeCtrl supports several ways to sort its content: InsertItem allows to insert the child item alphabetically, when specifying TVI_SORT for hInsertAfter SortChildren performs an alphabetical sorting of the child items of the given parent item in a tree SortChildrenCB performs a sort with a user-defined callback (hence the CB suffix) of the children of…
Add/Remove Commands to/from the Window Menu
A window’s system menu (now called simply window menu) features by default commands like Move, Size or Close. (When the user selects one of these commands a WM_SYSCOMMAND message is sent to the window.) What if you want to remove and add these commands on the fly? Here is how you can do it. This…
Visual Studio 2010 changes for VC++ (summary)
In the past months I have written about what’s new in Visual Studio 2010 with regard to Visual C++. In this post I will summarize these articles. MSBuild and multi-targeting Visual Studio 2010 changes for VC++ (part 1) IntelliSense and Browsing (#include auto completion, call hierarchy, red squiggles, find all references, class wizard) Visual Studio…