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…

Visual Studio 2010 changes for VC++ (part 4)

VC++ Feature Pack that came with Visual Studio 2008 SP1 introduced support for the Office Fluent Ribbon. However, developers had to create ribbons entirely from code, because there was no support in the resource editor for that. Visual Studio 2010 comes with a visual designer for the ribbon. You can choose whether to use a…

File Dialog with Custom Controls

Sometimes you want to customize a file dialog, maybe to provide a preview for images or files in general. Fortunately, the common file dialog can be easily extended to achieve this. I will explain in this post how to do that. There are several things one needs to do to extend the file dialog. First…

.NET out string[] to Automation SAFEARRAY**

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

Task Dialog in MFC

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…