Export (0) Print
Expand All
Expand Minimize

CMNCTRL1 Sample: Demonstrates Common Control MFC Classes, Part 1 

Download sample

The CMNCTRL1 sample illustrates how to use the following common control MFC classes: CTreeCtrl, CToolBarCtrl, CAnimateCtrl, CDateTimeCtrl, and CMonthCalCtrl. It shows how the controls are created and how to change the controls using many of the different available styles. Some controls cover topics that often yield questions from the user; for example, the drag and drop implementation for CTreeCtrl.

CMNCTRL1 is the result of replacing the original CMNCTRLS sample with two smaller projects: CMNCTRL1 (tree, toolbar, date and time picker, month calendar, and animate controls) and CMNCTRL2 (progress, up/down, and slider controls). This was done to reduce the footprint of the sample code, making it easier to trace specific portions of the application.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

To build and run the CMNCTRL1 sample

  1. Open the solution cmnctrl1.sln.

  2. On the Build menu, click Build.

  3. On the Debug menu, click Start Without Debugging.

When you run CMNCTRL1, select the tab for the control you want to activate. Select the styles and views from the check boxes, radio buttons, and combo boxes available in the different property pages. Note how each option changes the behavior or appearance of the control being displayed. For CTreeCtrl, you will be able to see the different notification messages sent by the control as you experiment with it.

NoteNote

Because of a display bug in the Win32 API, the tree view control will not update the node labels when the TVS_HASLINES and TVS_LINESATROOT styles are dynamically applied. To restore the labels, open and close one of the child nodes.

Keywords

This sample demonstrates the following keywords:

CBitmap::LoadBitmap; CEdit::Clear; CEdit::GetLineCount; CEdit::LineIndex; CEdit::LineLength; CEdit::ReplaceSel; CEdit::SetSel; CFileDialog::GetPathName; CGdiObject::DeleteObject; CImageList::DragShowNolock; CString::GetBufferSetLength; CString::GetLength; CString::Left; CString::LoadString; CString::ReleaseBuffer; CTreeCtrl::SelectDropTarget; CWnd::GetInvalidateRect; CWnd::GetClientRect; CWnd::GetWindowRect; CWnd::SetWindowPos; CWnd::SetWindowText; DeleteItem; GetCursorPos; GetDlgItem; GetParent; GetWindowLong; InvalidateRect; CWinApp::LoadIcon; MAKELONG; MessageBeep; ReleaseCapture; ScreenToClient; SetCapture; SetWindowLong; SetWindowPos; UpdateWindow; CWnd::WindowProc; mbstowcs; rand; srand; time; wsprintf

NoteNote

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples

Community Additions

ADD
Show:
© 2014 Microsoft