Tag Archives: VC++

Split Button Control

What is a split button?

In the previous post we presented the command link button control that is one of the controls introduced with Windows Vista. Another such control is the split button. This is a button that:

  • act like a regular button when pressed, but
  • display a drop-down menu when its drop-down arrow is presses

This is actually a regular button that has one of the windows styles BS_SPLITBUTTON or BS_DEFSPLITBUTTON set.

Split button control

How do add a split button

If you work with Microsoft Visual Studio 2008 or newer then you can find “Split Button Control” in the resource editor toolbox. First step is to drag it from toolbox in the resource dialog template.

Split Button Control

You can set the caption and the handler for BN_CLICKED just like with any regular push button.

However, for the drop down menu you have to define it explicitly.

Split button drop down menu

To specify what is the menu to be displayed use SetDropDownMenu.

Then, add handlers for the menu items and handle the commands.



Debugging Tips: Memory Leaks Isolation

In a recent post we showed how to detect memory leaks in MFC. In this post we present some tips for breaking on a particular allocation that leaks. However, you must note that this technique only works if you are able to find a reproducible allocation, with the same number.

Here is a memory leak report:

The allocation number is showed in curly brackets {}, and in this case was 183.

The steps to be able to break when an allocation that leaks is created are:

  • Make sure you have the adequate reporting mode for memory leaks (see Finding Memory Leaks Using the CRT Library).
  • Run the program several times until you find reproducible allocation numbers ({183} in the example above) in the memory leaks report at the end of running the program.
  • Put a breakpoint somewhere at the start of the program so you can break as early as possible.
  • Start the application with the debugger.
  • When the initial breakpoint is hit, in the watch window write in the Name column: {,,msvcr90d.dll}_crtBreakAlloc, and in Value column put the allocation number that you want to investigate (in my example it would be 183).
  • Continue debugging (F5).
  • The execution stops at the specified allocation. You can use the Call Stack to navigate back to your code where the allocation was triggered.

Visual Studio 2012 available for download

Visual Studio 2012 and .NET framework 4.5 became available on 15 August for MSDN subscribers, that can download it from here. Because the new features are discussed in detail in many places I will not attempt to enumerate everything. However, I just want to point some of the new things available for native development.

  • more C++ standard support: includes strongly-typed enums, range-based for loops, stateless lambdas, override and final, as well as new STL headers (<atomic>, <chrono>, <condition_variable>, <filesystem>, <future>, <mutex>, <ratio>, <thread>)
  • C++ compiler enhancements: auto-vectorizor and auto-parallelizer
  • IDE: C++ code-snippets, semantic colorization and (the long awaited) C++/CLI IntelliSense
  • parallel libraries: C++ AMP that allows us to write parallel programs that run on heterogeneous hardware, and new additions to the Parallel Patterns Library (especially in async programming)
  • Windows 8 development: a native XAML framework allows writing apps for WinRT; that is also possible with DirectX (and the two can actually be mixed together)
  • Unit test framework: allows you to write light-weight unit tests for your C++ applications

On the other hand there is not much done for MFC, that only benefits from a series of bug fixes. the only thing worth noting is reducing the size of statically-linked MFC applications that use “MFC controls”. You can read details about the problem and the solution here.

More about these can be found in the following articles:

What you have to note is that at this point VS2012 has some limitations:

  • You cannot target WinXP with this release
  • There is no Express version that allows you to write native C++ apps (for the desktop)

However, Microsoft has promised to solve these with an upgrade later this autumn (but no dates have been disclosed). You can read about that here: