Visual C++ Samples
The Visual C++ samples illustrate a wide variety of functionality across multiple technologies.
Security Note |
---|
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. |
Warning
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 find samples online
In the Visual Studio menu bar, choose Help, Samples.
In the left pane of the Samples dialog box, select Samples, then Visual C++, then Windows Runtime for samples that run in Windows 8, or one of the other categories for desktop samples that run in Windows 8 or earlier versions of Windows.
You can also visit the MSDN Code Gallery from any browser.
To build and run a sample
Open the solution in Visual Studio.
On the Build menu, choose Build.
On the Debug menu, choose Start Without Debugging.
For the most recent versions of the Visual C++ desktop samples, see one of the following pages on the MSDN Web site. If you open a project from an earlier version of Visual Studio in Visual C++ in Microsoft Visual Studio 2012, the project will be upgraded for you. Code Gallery may also contain C++ samples that are not listed here.
ATL Samples (using attributes)
Descriptions of the Samples
ATL Samples - Advanced
Sample Name |
Description |
---|---|
ActiveDoc |
Demonstrates how to implement an Active Document Server. |
Async |
Downloads data asynchronously from a URL. |
ATLButton |
Creates a button that displays itself with three different bitmaps depending on its state. |
ATLDuck |
Demonstrates using connection points with ATL controls. |
ATLSecurity |
Shows how to use the ATL security classes to examine security settings. |
ATLTraceTool |
Displays the output generated by the ATLTRACE2 macro. |
Connect |
Illustrates the implementation and use of connection points (the IConnectionPointContainer and IConnectionPoint interfaces) in a multithreaded environment. |
CThreadPool |
Shows how to use a thread pool in an application and how implementing a thread pool can improve the application's performance. |
DCOM |
Demonstrates how to call a COM object implemented in a Windows service from multiple clients running on different machines. |
MFCATL |
Illustrates how ATL COM objects can be used in an MFC server EXE. |
ATL Samples - Controls
Sample Name |
Description |
---|---|
ATLFire |
Demonstrates how to build a windowed control using ATL. |
CDInfo |
Plays CD audio tracks and displays information about the tracks in tooltips and a piechart display. |
Circ |
Creates a control that demonstrates property pages and draws a circle. |
Polygon |
Builds a control that implements custom properties, events, property pages, and object safety. |
SubEdit |
Creates a superclassed Windows control. |
ATL Samples - General
Sample Name |
Description |
---|---|
ATLCollections |
Demonstrates the use of ICollectionOnSTLImpl and CComEnumOnSTL, and the implementation of custom copy policy classes. |
ATLCon |
Demonstrates a simple control container. |
ATLSafeArray |
Shows how to create and maintain SAFEARRAYs using CComSafeArray; also how to pass SAFEARRAYs from a component to script. |
AutoThread |
Demonstrates using CComAutoThreadModule Class. |
Beeper |
Implements a tearoff interface — a collection/enumeration of BSTRs. |
CircColl |
Implements a collection/enumeration of objects using ATL and the Standard C++ Library. |
COMMap |
Demonstrates COM interface map entry macros with compiler COM support. |
CustomString |
Shows how to use a custom memory allocator for CStringT to improve performance in a multithreaded application. |
DispSink |
Demonstrates using a connection point on dispatch interfaces. |
ATL Samples - OLEDB - Consumer
Sample Name |
Description |
---|---|
CatDB |
Displays the schema information, such as tables and columns, of OLE DB providers. |
DBViewer |
Demonstrates a mid-level application that relies on the CManualAccessor class to take full control of data bindings for your applications. |
DynamicConsumer |
Demonstrates using dynamic accessor and schema rowset classes to read metadata from a database. |
MultiRead |
Reads through a table in a database using multiple threads. |
ATL Samples - OLEDB - Provider
Sample Name |
Description |
---|---|
AdvancedPV |
Implements an updateable OLE DB Provider. Demonstrates some advanced techniques. |
UpdatePV |
Implements an updateable (read/write) OLE DB provider. |
CLR Samples - Windows Forms
Sample Name |
Description |
---|---|
Scribble (MFC) |
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. |
STLCLR |
Demonstrates some of the capabilities available when using the STL/CLR Library. |
ComTypeLibfor7 Samples
Sample Name |
Description |
---|---|
ACDual |
Adds dual interfaces to an Automation application. |
ADOSamp |
Implements a three-tier client/server application. |
AllInOne |
Implements a server using ATL, exposing STL collections, and controlled by compiler COM support in an MFC application. |
COMMap |
Demonstrates COM interface map entry macros with compiler COM support. |
Connect |
Illustrates the use and implementation of connection points (the IConnectionPointContainer and IConnectionPoint interfaces) in a multithreaded environment. |
DCOM |
Demonstrates how to call a COM object implemented in a Windows service from multiple clients running on different computers. |
FreeThrd |
Demonstrates a multithreaded client and free-threaded server with compiler COM support. |
InProc |
Demonstrates an in-process Automation server application with compiler COM support. |
Labrador |
Implements an EXE server that does not have any user interface. |
MFCCalc |
Demonstrates an Automation server application with compiler COM support. |
Compiler Samples - General
Sample Name |
Description |
---|---|
ccWrapper |
Demonstrates how to map C/C++ compiler flags from other compilers to the Visual C++ compiler (cl.exe). |
Compiler Samples - MASM
Sample Name |
Description |
---|---|
EuclidStep1 |
A pure C project that demonstrates Euclid's algorithm for finding the greatest common divisor. |
EuclidStep2 |
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. |
PrimesStep1 |
A pure C project that demonstrates the sieve of Eratosthenes to find prime numbers. |
PrimesStep2 |
An extension of PrimesStep1 that is a mixed C and ASM project that moves the core algorithm to the .asm file. |
PrimesStep3 |
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. |
CRT Samples
Sample Name |
Description |
---|---|
CPUID |
Determines the capabilities of the CPU being run. |
CRT_Dbg1 |
Illustrates the basic debugging features of the C run-time libraries. |
CRT_Dbg2 |
Demonstrates the C run-time debugging hook functions. |
DFACObjs |
Shows how to use the _CrtDoForAllClientObjects C run-time function to iterate through a linked list of client objects. |
Report |
Illustrates the C run-time debugging report functions. |
RTC |
Demonstrates the run-time error checks feature. |
SecureCRT |
This sample demonstrates how to upgrade code that used deprecated CRT functions to increase code security. |
Debugging Samples
Sample Name |
Description |
---|---|
EEAddIn |
Uses the Expression Evaluator Add-In API to extend the native debugger expression evaluator. |
Events Samples
Sample Name |
Description |
---|---|
COMEvents |
Demonstrates event handling using COM. |
Extensibility Samples
Sample Name |
Description |
---|---|
VCProjEngine_CPP |
Programmatically modifies a Visual C++ project using C++. |
VCProjEngine_CS |
Programmatically modifies a Visual C++ project using C#. |
VCProjEngine_VB7 |
Programmatically modifies a Visual C++ project using Visual Basic. |
Fusion Samples
Sample Name |
Description |
---|---|
TraceMan |
Provides information about application-dependent assemblies and the state of the assemblies in the native fusion cache in human readable form. |
International Samples
Sample Name |
Description |
---|---|
IME |
Demonstrates how to control the Input Method Editor mode and how to implement IME level 3. |
SatDLL |
Demonstrates a recommended way to implement multilingual resources in a Win32 application. |
UniRes |
Demonstrates the use of Unicode resource files. |
Language Samples
Sample Name |
Description |
---|---|
BirthdayPicker |
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. |
Calculator |
Implements a simple pocket calculator using C++ and the .NET Framework Windows Forms classes. |
Data |
Demonstrates simple access to a SQL Database. |
MEDriver |
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. |
Nile |
Demonstrates ASP.NET Web Forms and ASP.Net Web Services. |
QStat |
Shows how to create a DLL that wraps access to a COM object and exposes its functionality to .NET Framework clients. |
Scribble |
Demonstrates how to develop a Windows Forms MDI application using C++/CLI and the .NET Framework classes. |
TilePuzzle |
Demonstrates interoperability between managed components (written with C++ and C#) and native components (written with C++ using COM attributes). |
MFC Samples - Advanced
Sample Name |
Description |
---|---|
Collect |
Demonstrates MFC C++ template-based collection classes and standard prebuilt collection classes. |
Cube |
OpenGL application using MFC device contexts along with OpenGL's resource contexts. |
DLLHusk |
Sharing the DLL version of the Foundation class library with an application and custom DLL. |
DLLScreenCap |
A regular DLL that can be statically or dynamically linked to the Microsoft Foundation Class Library. |
MTGDI |
Demonstration of sharing GDI resources among multiple threads using the framework's single document interface (SDI) support for documents and views. |
MTMDI |
Multithread illustration, where user-interface events are processed in a separate user-interface thread. |
MTRecalc |
Multithread illustration, where recalculations are performed in a worker thread. |
Mutexes |
Dialog-based application that creates two CWinThread objects and uses them to perform a simple task under the user's control. |
Speakn |
Demonstrates Multimedia Sound Using User-Defined Resources. |
MFC Samples - Controls
Sample Name |
Description |
---|---|
Button |
Demonstrates use of an in-place active menu, a stock property page, and the About box control option. |
Circ |
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. |
CmnCtrl |
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). |
Contain |
Demonstrates a Visual Editing Container Application. |
Image |
Demonstrates how to use MFC to build an ActiveX control that is capable of downloading data asynchronously. |
Licensed |
A control that enforces use of a design-time and run-time license. |
Localize |
A control with a localized user interface that demonstrates use of separate type libraries and resource dynamic-link libraries (DLLs) for localization. |
NetAddr |
Demonstrates use of the Windows Vista "Net Address Verifier" control. |
Pal |
Control that displays the colors of a palette. It demonstrates read-only properties, persistent Get/Set properties, persistent parameterized properties, and picture properties. |
Push |
Control subclassed from a Windows owner-drawn button control. It demonstrates stock properties, custom events, and picture holders. |
RegSvr |
Demonstrates the invocation of Self-Registration Code. |
SpinDial |
A control with the visual appearance of a spin-dial that demonstrates property page data validation. |
TestHelp |
An ActiveX control that has its own help file and tooltips. |
Time |
A control that is invisible at run time and fires a timer event at set intervals. Demonstrates notification functions and ambient properties. |
XList |
A control, subclassed from a Windows list box, that displays text or bitmap items. |
MFC Samples - General
Sample Name |
Description |
---|---|
ClipArt |
The CLIPART directory contains sample resources that you can use to customize the appearance of your application. |
CmnCtrl1 |
Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 1). |
CmnCtrl2 |
Demonstrates how to create and change the styles of Windows Common Controls using MFC classes (Part 2). |
CTaskDialog |
Demonstrates various features of the CTaskDialog class. |
CtrlBars |
Custom toolbar and status bar, dialog bar, and floating palette. |
CtrlTest |
Owner-draw list box and menu, custom control, bitmap button, spin control. |
DBVList |
Uses the CListView and CDaoRecordset classes to implement the virtual list view functionality that is available for the list view common control. |
DIBLook |
Demonstrates the Use of DIBs and Color Palettes. |
DlgCbr32 |
Adding a toolbar and a status bar to a dialog-based application. |
DlgTempl |
Demonstrates the dynamic creation of dialog templates. |
DockTool |
Dragging and floating toolbars that are "dockable". |
Dynamenu |
Dynamically modifying list of items in menus; handling commands not known at compile time; and updating the status bar command prompt for such commands. |
FileDlgWatcher |
Creates a custom dialog box that illustrates what events are generated when you create a CFileDialog. |
Hello |
Illustrates a single application window with a menu and About box. |
HelloApp |
Minimal MFC sample that illustrates that few lines of code are required to get a window to appear on the screen. |
ListHdr |
Demonstrates how to use the common control MFC classes CListCtrl and CHeaderCtrl. |
MDI |
MDI application that does not use documents and views. |
MDIDocVw |
Updated version of the MDI sample that uses the document/view architecture. |
MMXSwarm |
Demonstrates how to use CImage, the __m64 data type, and device-independent bitmaps (DIBs). |
Modeless |
Demonstrates the use of an MFC CDialog object as a modeless dialog box. |
Multipad |
Simple text editor that lets the user open and edit multiple text files at one time. |
Npp |
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. |
PropDlg |
Property sheets (dialogs). |
RowList |
Illustrates full row selection in a list-view common control. |
Scribble |
Provides simple illustrations of a wide breadth of MFC features. |
SimpleImage |
Demonstrates loading, resizing, conversion, and saving images. |
SnapVw |
Shows how to use property pages in a MDI child frame window. |
Spiro |
A game that shows to use CImageList and how to use memory display contexts in applications requiring animation effects. |
Tracker |
Demonstrates various CRectTracker styles and options. |
VariantUse |
Demonstrates the use of the variant data type. |
ViewEx |
Multiple views, scroll view, splitter windows. |
MFC Samples - Internet
Sample Name |
Description |
---|---|
DHTMLExplore |
Demonstrates handling DHTML events and using DHTML DDX. |
HTMLEdit |
Wraps the Internet Explorer MSHTML editing control. |
MFCIE |
Demonstrates the MFC CHtmlView and CReBar Classes. |
Scheduler |
Demonstrates how to create an HTML-based dialog box using the Visual C++ libraries classes. |
MFC Samples - OLE
Sample Name |
Description |
---|---|
ACDual |
Demonstrates how to add dual interface support to an MFC-based Automation server. |
AutoClik |
Illustrates Automation features. Includes AUTODRIV, a simple Automation client application that drives the AUTOCLIK sample application. |
CalcDriv |
Automation client. |
DrawCli |
Full-featured object-oriented drawing application that is also an ActiveX Visual Editing container. |
HierSvr |
Demonstrates a Server Application with OLE Drag and Drop. |
InProc |
An in-process Automation server that can be loaded as a DLL in the client's address space. |
IPDrive |
A simple Automation client application that drives the INPROC sample application. |
MFCBind |
Shows how to create an Active document (formerly known as a DocObject) container. |
MFCCalc |
An Automation server that implements a simple calculator. |
OClient |
ActiveX Visual Editing container application, with drag and drop. |
OLEView |
Implementing an OLE object browser through custom OLE interfaces. |
SuperPad |
Demonstrates a Visual Editing Server That Edits Text Using CEditView. |
TstCon |
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. |
WordPad |
Uses MFC's support for rich edit controls to create a basic word processor. |
MFC Samples - Utility
Sample Name |
Description |
---|---|
GUIDGen |
A simple dialog-based MFC application that generates globally-unique identifiers. |
Makehm |
A console application that produces a mapping between resource identifications and Help contexts. |
MFC Samples - Visual C++ 2008 Feature Pack
Sample Name |
Description |
---|---|
CustomPages |
Demonstrates how to add a custom page to the Toolbar Customization dialog box. |
DesktopAlertDemo |
Demonstrates how to implement a desktop alert dialog box (similar to the dialog box that an instant messaging application displays). |
DlgToolTips |
Demonstrates how to implement advanced tooltips for controls on a dialog box. |
DrawClient |
Demonstrates how to integrate support for a ribbon into an object-oriented drawing application with visual editing container support. |
DynamicMenu |
Demonstrates how to dynamically update a menu on the menu bar and a popup menu at run-time. |
Explorer |
Demonstrates how to implement a file system explorer that resembles File Explorer, with similar user interface elements and capabilities. |
IEDemo |
Demonstrates how to implement an application similar to Internet Explorer, with similar user interface elements and capabilities. |
MDITabsDemo |
Demonstrates how to create an application that uses the new tabbed MDI documents interface instead of the traditional MDI child windows. |
MenuSubSet |
Demonstrates how to dynamically remove specific menu items and submenus at application startup. |
MSMoneyDemo |
Demonstrates how to use MFC to create a user interface similar to Microsoft Money. |
MSOffice2007Demo |
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. |
NewControls |
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. |
OutlookDemo |
Demonstrates how to create an application similar to Outlook 2003/2007. |
OutlookMultiViews |
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. |
OwnerDrawMenu |
Illustrates how to draw popup menu items dynamically. |
PaletteDemo |
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. |
PropSheetDemo |
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. |
RebarTest |
Demonstrates a customizable Rebar control which hosts a toolbar. |
RibbonGadgets |
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. |
RibbonMDI |
Demonstrates usage of Ribbon Control with Multi Document Interface. |
RollupPane |
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. |
SetPaneSize |
Demonstrates how to set docking pane size programmatically. |
Slider |
Demonstrates how to implement a toolbar button that hosts an external control. |
StateCollection |
Demonstrates how to implement an application that saves and loads different states for the menu bar, toolbars, and docking windows. |
StatusBarDemo |
Demonstrates how to add various advanced controls to a status bar. |
TabbedView |
Demonstrates how to create a view that contains multiple tabbed views, such as the tabs in an Excel workbook. |
TabControl |
Demonstrates the MFC Tab Control and the different appearances it has using different properties and visual managers. |
TasksPane |
Demonstrates the MFC Task Pane classes and their different appearances using various properties and visual managers. |
ToolbarDateTimePicker |
Demonstrates how to integrate a date/time picker control with the toolbar |
ToolTipDemo |
Demonstrates how to use advanced MFC tooltip features. |
TrayMenu |
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). |
VisualStudioDemo |
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. |
WordPad |
Demonstrates how to implement an application that imitates the functionality of WordPad, including the user interface elements and some of the capabilities. |
WorkSpaceToolBar |
Demonstrates how to add a toolbar to a docking pane. This resembles the toolbar in Solution Explorer in Visual Studio. |
MFC Samples - Windows Touch
Sample Name |
Description |
---|---|
GestureDemo |
Demonstrates the Windows Touch support in MFC (requires touch hardware). |
TouchDemo |
Demonstrates the Windows Touch support in MFC (requires touch hardware). |
OS Samples
Sample Name |
Description |
---|---|
GetImage |
Demonstrates the Windows Image Acquisition (WIA) application programming interfaces (APIs). |
Unix Samples
Sample Name |
Description |
---|---|
Unix - ccWrapper |
Demonstrates a wrapper that maps flags from the Sun Forte and gcc compilers to the Microsoft Visual C++ compiler (cl.exe). |