MFC in Orcas comes with several important changes, such as support for Vista specific command button and split button. I have put together a small demo application displaying a command button with the tex Say “Hello Vista” and the note “Click on this button to show a “Hello Vista” message!”.

The command button is still a CButton, but with the style BS_COMMANDLINK (or BS_DEFCOMMANDLINK for a default command button) set. To set the note you should use the SetNote() method. Additional GetNote() and GetNoteLength() methods are available for it. Here is a screenshot:

Demo of command button for Vista

However, there are several problems with the Orcas March CTP that I want to mention (and I hope these will fixed for the next beta version).

When you create a project, add a command button and try to compile, the resource compiler will say that BS_COMMANDLINK is not recognized. The style is defined in commctrl.h like this:

 

Trying to define _WIN32_WINNT as 0×0600 either in the project properties or in stdafx.h (if you use precompiled headers) does not help. You have to redeclare the styles whether in resource.h or in the .rc file, but as soon as the IDE modifies them, the code you put there is gone. This is a real bummer, and I’m still looking for the best solution. If I find it, I’ll post it here.

The methods that are available for the command button are defined only for UNICODE builds for Vista, as can be seen in afxwin.h:

 

However, if you look in MSDN, method SetShield is not found (though you can find the BCM_SETSHIELD window message). Instead SetElevationRequired() is listed as a member of CButton. This method does not actually exists. Moreover, the people that wrote the documentation don’t seem to know the difference between BOOL and bool (explained here). This method takes a BOOL and returns a BOOL, but MSDN says it returns

true if the method is successful; otherwise false

Using SetShield() with TRUE, displays a shield icon on the button, as shown here:

Demo command button for Vista with shield icon

I hope the issues I mentioned above will be address very soon.

Hits for this post: 10722 .
Trackback

2 comments untill now

  1. Gravatar

    Regarding the issue with the IDE overwriting your custom styles in the .rc, I remember (VS6, no idea in 2005) that you can stop that by writing the constant value directly instead of defining a constant.

  2. Gravatar

    Well, that is indeed an option. But the right approach is to have the IDE add all the necessary files, includes, etc. when you place one of the new controls in a dialog.

Add your comment now