Dynamic Dialog Layout for MFC in Visual C++ 2015

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…

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…

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)…

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…