Visual C++ Samples
The Visual C++ samples illustrate a wide variety of functionality across multiple technologies.
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To access samples from Visual Studio
On the Help menu, click Samples.
In the Samples on Disk section of the readme file, click local Samples folder. By default, the samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\1033 or drive:\Program Files (x86)\Microsoft Visual Studio 10.0\Samples\1033.
Right-click the .zip file that contains the samples you want to open and then click Extract All to extract the samples to a folder of your choice.
Some samples have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler. However, they still demonstrate how to complete the task.
To build and run a sample
Open the solution in Visual Studio.
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
For the most recent versions of the Visual C++ samples, see one of the following pages on the MSDN Web site:
ATL Samples - Advanced
Demonstrates how to implement an Active Document Server.
Downloads data asynchronously from a URL.
Creates a button that displays itself with three different bitmaps depending on its state.
Demonstrates using connection points with ATL controls.
Shows how to use the ATL security classes to examine security settings.
Displays the output generated by the ATLTRACE2 macro.
Illustrates the implementation and use of connection points (the IConnectionPointContainer and IConnectionPoint interfaces) in a multithreaded environment.
Shows how to use a thread pool in an application and how implementing a thread pool can improve the application's performance.
Demonstrates how to call a COM object implemented in a Windows service from multiple clients running on different machines.
Illustrates how ATL COM objects can be used in an MFC server EXE.
ATL Samples - Controls
Demonstrates how to build a windowed control using ATL.
Plays CD audio tracks and displays information about the tracks in tooltips and a piechart display.
Creates a control that demonstrates property pages and draws a circle.
Builds a control that implements custom properties, events, property pages, and object safety.
Creates a superclassed Windows control.
ATL Samples - General
Demonstrates the use of ICollectionOnSTLImpl and CComEnumOnSTL, and the implementation of custom copy policy classes.
Demonstrates a simple control container.
Shows how to create and maintain SAFEARRAYs using CComSafeArray; also how to pass SAFEARRAYs from a component to script.
Demonstrates using CComAutoThreadModule Class.
Implements a tearoff interface — a collection/enumeration of BSTRs.
Implements a collection/enumeration of objects using ATL and the Standard C++ Library.
Demonstrates COM interface map entry macros with compiler COM support.
Shows how to use a custom memory allocator for CStringT to improve performance in a multithreaded application.
Demonstrates using a connection point on dispatch interfaces.
ATL Samples - OLEDB - Consumer
Displays the schema information, such as tables and columns, of OLE DB providers.
Demonstrates a mid-level application that relies on the CManualAccessor class to take full control of data bindings for your applications.
Demonstrates using dynamic accessor and schema rowset classes to read metadata from a database.
Reads through a table in a database using multiple threads.
ATL Samples - OLEDB - Provider
Implements an updateable OLE DB Provider. Demonstrates some advanced techniques.
Implements an updateable (read/write) OLE DB provider.
CLR Samples - Windows Forms
An MFC implementation of the Scribble sample, updated and extended to include new .NET functionality.
Scribble (Windows Forms)
A Windows Forms implementation of the Scribble sample, updated and extended to include new .NET functionality.
Demonstrates some of the capabilities available when using the STL/CLR Library.
Adds dual interfaces to an Automation application.
Implements a three-tier client/server application.
Implements a server using ATL, exposing STL collections, and controlled by compiler COM support in an MFC application.
Demonstrates COM interface map entry macros with compiler COM support.
Illustrates the use and implementation of connection points (the IConnectionPointContainer and IConnectionPoint interfaces) in a multithreaded environment.
Demonstrates how to call a COM object implemented in a Windows service from multiple clients running on different computers.
Demonstrates a multithreaded client and free-threaded server with compiler COM support.
Demonstrates an in-process Automation server application with compiler COM support.
Implements an EXE server that does not have any user interface.
Demonstrates an Automation server application with compiler COM support.
Compiler Samples - General
Demonstrates how to map C/C++ compiler flags from other compilers to the Visual C++ compiler (cl.exe).
Compiler Samples - MASM
A pure C project that demonstrates Euclid's algorithm for finding the greatest common divisor.
An extension of EuclidStep1 that is a mixed C and ASM project. The core of Euclid's algorithm is moved from the .c file to an .asm file, with the .c file calling into the .asm file.
A pure C project that demonstrates the sieve of Eratosthenes to find prime numbers.
An extension of PrimesStep1 that is a mixed C and ASM project that moves the core algorithm to the .asm file.
An extension of PrimesStep2 that adds a separate C header file and an .asm include file to declare the extern function and global data structure.
Determines the capabilities of the CPU being run.
Illustrates the basic debugging features of the C run-time libraries.
Demonstrates the C run-time debugging hook functions.
Shows how to use the _CrtDoForAllClientObjects C run-time function to iterate through a linked list of client objects.
Illustrates the C run-time debugging report functions.
Demonstrates the run-time error checks feature.
This sample demonstrates how to upgrade code that used deprecated CRT functions to increase code security.
Uses the Expression Evaluator Add-In API to extend the native debugger expression evaluator.
Demonstrates event handling using COM.
Programmatically modifies a Visual C++ project using C++.
Programmatically modifies a Visual C++ project using C#.
Programmatically modifies a Visual C++ project using Visual Basic.
Provides information about application-dependent assemblies and the state of the assemblies in the native fusion cache in human readable form.
Demonstrates how to control the Input Method Editor mode and how to implement IME level 3.
Demonstrates a recommended way to implement multilingual resources in a Win32 application.
Demonstrates the use of Unicode resource files.
Shows how the .NET Framework resource mechanism can be used in C++ applications. It also demonstrates some common Window Forms components.
C++ Language Samples
Demonstrates key concepts of features in C++ that support .NET and expose capabilities of the CLR.
Implements a simple pocket calculator using C++ and the .NET Framework Windows Forms classes.
Demonstrates simple access to a SQL Database.
Illustrates the use of COM events (fired from an unmanaged COM server) through a .NET Framework wrapper, automatically generated from the COM server's type library.
Demonstrates ASP.NET Web Forms and ASP.Net Web Services.
Shows how to create a DLL that wraps access to a COM object and exposes its functionality to .NET Framework clients.
Demonstrates how to develop a Windows Forms MDI application using C++/CLI and the .NET Framework classes.
Demonstrates interoperability between managed components (written with C++ and C#) and native components (written with C++ using COM attributes).
MFC Samples - Advanced
Demonstrates MFC C++ template-based collection classes and standard prebuilt collection classes.
OpenGL application using MFC device contexts along with OpenGL's resource contexts.
Sharing the DLL version of the Foundation class library with an application and custom DLL.
A regular DLL that can be statically or dynamically linked to the Microsoft Foundation Class Library.
Demonstration of sharing GDI resources among multiple threads using the framework's single document interface (SDI) support for documents and views.
Multithread illustration, where user-interface events are processed in a separate user-interface thread.
Multithread illustration, where recalculations are performed in a worker thread.
Dialog-based application that creates two CWinThread objects and uses them to perform a simple task under the user's control.
Demonstrates Multimedia Sound Using User-Defined Resources.
MFC Samples - Controls
Demonstrates use of an in-place active menu, a stock property page, and the About box control option.
Demonstrates ActiveX control basics, including control painting, stock and custom properties, stock and custom events, use of colors and fonts, the stock Font property page, the default property page, and versioning.
Demonstrates some of the new controls available with MFC on wiprlhext, including the command link button (CButton), the pager control (CPagerCtrl), the split button (CSplitButton), and the network address control (CNetAddressCtrl).
Demonstrates a Visual Editing Container Application.
Demonstrates how to use MFC to build an ActiveX control that is capable of downloading data asynchronously.
A control that enforces use of a design-time and run-time license.
A control with a localized user interface that demonstrates use of separate type libraries and resource dynamic-link libraries (DLLs) for localization.
Demonstrates use of the Windows Vista "Net Address Verifier" control.
Control that displays the colors of a palette. It demonstrates read-only properties, persistent Get/Set properties, persistent parameterized properties, and picture properties.
Control subclassed from a Windows owner-drawn button control. It demonstrates stock properties, custom events, and picture holders.
Demonstrates the invocation of Self-Registration Code.
A control with the visual appearance of a spin-dial that demonstrates property page data validation.
An ActiveX control that has its own help file and tooltips.
A control that is invisible at run time and fires a timer event at set intervals. Demonstrates notification functions and ambient properties.
A control, subclassed from a Windows list box, that displays text or bitmap items.
MFC Samples - General
The CLIPART directory contains sample resources that you can use to customize the appearance of your application.
Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 1).
Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 2).
Demonstrates various features of the CTaskDialog class.
Custom toolbar and status bar, dialog bar, and floating palette.
Owner-draw list box and menu, custom control, bitmap button, spin control.
Uses the CListView and CDaoRecordset classes to implement the virtual list view functionality that is available for the list view common control.
Demonstrates the Use of DIBs and Color Palettes.
Adding a toolbar and a status bar to a dialog-based application.
Demonstrates the dynamic creation of dialog templates.
Dragging and floating toolbars that are "dockable".
Dynamically modifying list of items in menus; handling commands not known at compile time; and updating the status bar command prompt for such commands.
Creates a custom dialog box that illustrates what events are generated when you create a CFileDialog.
Illustrates a single application window with a menu and About box.
Minimal MFC sample that illustrates that few lines of code are required to get a window to appear on the screen.
Demonstrates how to use the common control MFC classes CListCtrl and CHeaderCtrl.
MDI application that does not use documents and views.
Updated version of the MDI sample that uses the document/view architecture.
Demonstrates how to use CImage, the __m64 data type, and device-independent bitmaps (DIBs).
Demonstrates the use of an MFC CDialog object as a modeless dialog box.
Simple text editor that lets the user open and edit multiple text files at one time.
Demonstrates how to implement an interface (SDI) application similar to Notepad that allows you to edit text messages and send them to other users or other systems through the Windows messaging API, or MAPI.
Property sheets (dialogs).
Illustrates full row selection in a list-view common control.
Provides simple illustrations of a wide breadth of MFC features.
Demonstrates loading, resizing, conversion, and saving images.
Shows how to use property pages in a MDI child frame window.
A game that shows to use CImageList and how to use memory display contexts in applications requiring animation effects.
Demonstrates various CRectTracker styles and options.
Demonstrates the use of the variant data type.
Multiple views, scroll view, splitter windows.
MFC Samples - Internet
Demonstrates handling DHTML events and using DHTML DDX.
Wraps the Internet Explorer MSHTML editing control.
Demonstrates the MFC CHtmlView and CReBar Classes.
Demonstrates how to create an HTML-based dialog box using the Visual C++ libraries classes.
MFC Samples - OLE
Demonstrates how to add dual interface support to an MFC-based Automation server.
Illustrates Automation features. Includes AUTODRIV, a simple Automation client application that drives the AUTOCLIK sample application.
Full-featured object-oriented drawing application that is also an ActiveX Visual Editing container.
Demonstrates a Server Application with OLE Drag and Drop.
An in-process Automation server that can be loaded as a DLL in the client's address space.
A simple Automation client application that drives the INPROC sample application.
Shows how to create an Active document (formerly known as a DocObject) container.
An Automation server that implements a simple calculator.
ActiveX Visual Editing container application, with drag and drop.
Implementing an OLE object browser through custom OLE interfaces.
Demonstrates a Visual Editing Server That Edits Text Using CEditView.
Implements an ActiveX control container using MFC's support for OLE embedding. You can use TSTCON to test ActiveX controls, change their properties, and invoke their methods.
Uses MFC's support for rich edit controls to create a basic word processor.
MFC Samples - Utility
A simple dialog-based MFC application that generates globally-unique identifiers.
A console application that produces a mapping between resource identifications and Help contexts.
MFC Samples - Visual C++ 2008 Feature Pack
Demonstrates how to add a custom page to the Toolbar Customization dialog box.
Demonstrates how to implement a desktop alert dialog box (similar to the dialog box that an instant messaging application displays).
Demonstrates how to implement advanced tooltips for controls on a dialog box.
Demonstrates how to integrate support for a ribbon into an object-oriented drawing application with visual editing container support.
Demonstrates how to dynamically update a menu on the menu bar and a popup menu at run-time.
Demonstrates how to implement a file system explorer that resembles the Windows Explorer, with similar user interface elements and capabilities.
Demonstrates how to implement an application similar to Internet Explorer, with similar user interface elements and capabilities.
Demonstrates how to create an application that uses the new tabbed MDI documents interface instead of the traditional MDI child windows.
Demonstrates how to dynamically remove specific menu items and submenus at application startup.
Demonstrates how to use MFC to create a user interface similar to Microsoft Money.
Demonstrates how to implement an editor application similar to an Office 2007 application, with similar user interface elements and limited similar capabilities. The MSOffice2007Demo sample implements a very full ribbon user interface much like an Office 2007 application, and some (but not all) of the ribbon elements are connected to capabilities in the application.
Demonstrates the capabilities of many of the controls implemented in MFC, including customizable buttons, color picker controls and palettes, a font chooser, an image editor, a property grid, a masked edit control, and shell list and tree controls.
Demonstrates how to create an application similar to Microsoft Outlook 2003/2007.
Demonstrates how to switch between multiple views on a single document in an SDI application. The sample uses the Outlook bar control to list the available views and switch between them.
Illustrates how to draw popup menu items dynamically.
Illustrates how to create a multi-column toolbar with an owner-draw information area. Click 2, 3 or 4 buttons on the Standard toolbar in order to change at the runtime the number of columns of the custom toolbar.
Illustrates the following types of Property Sheet control: simple, with tabs at the left side, with tree control at the left side, OneNote-style tabs, list of items at the left side.
Demonstrates a customizable Rebar control which hosts a toolbar.
Illustrates various controls that can be hosted in the Ribbon Control. At the bottom of the main frame you can find the Source Code window with source code text, which outlines how to create a particular gadget.
Demonstrates usage of Ribbon Control with Multi Document Interface.
Demonstrates a floating "information" pane, which automatically rolls up. You can press the pin button on the caption of floating pane to turn rolling on and off.
Demonstrates how to set docking pane size programmatically.
Demonstrates how to implement a toolbar button that hosts an external control.
Demonstrates how to implement an application that saves and loads different states for the menu bar, toolbars, and docking windows.
Demonstrates how to add various advanced controls to a status bar.
Demonstrates how to create a view that contains multiple tabbed views, such as the tabs in an Excel workbook.
Demonstrates the MFC Tab Control and the different appearances it has using different properties and visual managers.
Demonstrates the MFC Task Pane classes and their different appearances using various properties and visual managers.
Demonstrates how to integrate a date/time picker control with the toolbar
Demonstrates how to use advanced MFC tooltip features.
Illustrates the ability to use MFC Control Bar menus with the system tray icon (such as the notification icons in the lower-right corner of the display).
Demonstrates how to implement an application with many of the same user interface features and some of the capabilities of Visual Studio. Many of the Visual Studio user interface elements, including customizable docking menubar and toolbars, and docking windows, are demonstrated.
Demonstrates how to implement an application that imitates the functionality of WordPad, including the user interface elements and some of the capabilities.
Demonstrates how to add a toolbar to a docking pane. This resembles the toolbar in Solution Explorer in Visual Studio.
MFC Samples - Windows Touch
Demonstrates the Windows Touch support in MFC (requires touch hardware).
Demonstrates the Windows Touch support in MFC (requires touch hardware).
Demonstrates the Windows Image Acquisition (WIA) application programming interfaces (APIs).
Unix - ccWrapper
Demonstrates a wrapper that maps flags from the Sun Forte and gcc compilers to the Microsoft Visual C++ compiler (cl.exe).