In Visual Studio 2015 MFC comes with a new features (something that has rarely happen in recent years): support for dynamic dialog layout. That means library support for moving and resizing controls on a dialog. In this article I will show how this feature works. Suppose we have the following dialog: What we want is…
Tag: MFC
GUIDGEN with plain text GUIDs and case options
guidgen.exe is a small utility that comes with Visual Studio and generates GUIDs in a variety of formats. The problem with the tool is that it does not format GUIDs in plain text, which I happen to need many times (in source code, database tables, etc.) and I suppose is a feature needed by many…
Microsoft made C++ a second-class citizen in Visual Studio 2015
Visual Studio 2015 is out and comes with lots of new features and improvements (see details here) but it also surprised me with what I call a demoting of C++ again to a second-class citizen, after some years when it looked like it regained importance at Microsoft. I’m saying Microsoft has demoted C++ because they…
MFC Collection Utilities library
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…
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…