MFC

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

Read More CDatabase bug in MFC in VS2012

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…

Read More Keyboard input and TAB navigation between WPF controls in a Win32 application

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…

Read More A tale of two flags: DS_CONTROL and WS_EX_CONTROLPARENT

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…

Read More Sorting a CTreeCtrl

With VC++ Feature Pack Microsoft has added new classes to MFC to provide support for new controls. However, these controls were not available from the designer. One had to manually wrote all the code for enabling an application to use these controls. Visual Studio 2010 Beta 2, released a couple of weeks ago, provides support…

Read More New MFC Toolbar Controls in Visual Studio 2010

.NET allows you to expose components as COM and consume them from unmanaged code. There are many references on how to this (and you can only start with MSDN), and I will not talk about that part. What I want to explain here is something different. Suppose you have this interface:

Method GetUsers() returns…

Read More .NET out string[] to Automation SAFEARRAY**

The new MFC library from Visual Studo 2010 supports another Vista specific feature, the task dialog. This is meant as a replacement for the classic dialog box, and can display command links, customized buttons, customized icons, and a footer. Here is an example of such a dialog (from Windows Server 2008). MFC contains a new…

Read More Task Dialog in MFC

At the beginning of January, Microsoft released a beta version of MFC Feature Pack, an exstension to the MFC shipped with Visual Studio 2008. This feature pack allows developers to create applications with the look and feel of Office, Visual Studio and Internet Explorer. MFC application can now support: Office Ribbon Office 2003, XP and…

Read More MFC Feature Pack