Export (0) Print
Expand All

BirthdayPicker Sample: Demonstrates .NET Framework Resources with Windows Forms

The BirthdayPicker sample shows how the .NET Framework resource mechanism can be used in C++ applications. It also demonstrates some common Window Forms components.

Security noteSecurity 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.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

To take advantage of .NET Framework resources, C++ applications can use the .NET Framework tool WinRes.exe. This tool is specialized in creating ".resx" files (the equivalent of ".rc" files in Win32 C++ applications). Birthdaypicker.resx contains the imageList1 resource along with the collection of bitmaps it handles. The resultant .resx file is then compiled by resgen.exe into the file birthdaypicker.resources, which is then linked into the resulting assembly of the application.

To build and run BirthdayPicker using Visual Studio

  1. In the Visual Studio IDE, load the solution file BirthdayPicker.sln.

  2. In Solution Explorer, right-click the BirthdayPicker solution.

  3. On the Debug menu, click Start.

    Observe the Custom build step, running resgen.exe on birthdaypicker.resx and generating the resource file for the application. In addition, note the linker option /assemblyresource, used to link the resulting birthdaypicker.resources to the application.

  4. On the Debug menu, click Start.

Once the sample is running, two DateTimePicker controls are displayed. Select your birthday using the first control and an arbitrary date (such as today) with the second control. Once the date range has been selected, the linked tree control is propagated with multiple nodes interpreting the timespan in different ways. For example, the number of years or days elapsed, the equivalent in dog years or in fruit fly generations, and how many full moons have passed in this time interval.

This sample demonstrates the following classes:

DateTimePicker; ImageList; ResourceManager; TreeView

This sample demonstrates the following keywords:

ResourceManager::GetObject; DateTimePicker::Format; TimeSpan; KeyPressEventHandler; ToolTip::SetToolTip; ContextMenu; TreeView::Nodes; TreeView::SelectedNode; TreeNode::GetNodeCount; TreeNode::Remove; TreeNodeCollection::Insert; TreeNodeCollection::Clear; String::Format; Panel; dynamic_cast

Community Additions

Show:
© 2014 Microsoft