.NET
  Home arrow .NET arrow Page 4 - List Control and Property Grid with the MF...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

List Control and Property Grid with the MFC Feature Pack
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-10-26

    Table of Contents:
  • List Control and Property Grid with the MFC Feature Pack
  • Customize the list control
  • Property Grid
  • Properties

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    List Control and Property Grid with the MFC Feature Pack - Properties


    (Page 4 of 4 )

    A property grid contains multiple groups (or just one), and within that, multiple properties (or just one). Before we add any property, we need to create a group. For this, use the CMFCPropertyGridProperty class. Within this you can add items with the AddSubItem function. You can add a property group to the grid control with the AddProperty function.

    //create a new item

    CMFCPropertyGridColorProperty* pColorProp =

    new CMFCPropertyGridColorProperty(

    _T("Window Color"),RGB(210, 192, 254), NULL, _T("Specifies the default dialog color"));

     

    // A little customization

    pColorProp->EnableOtherButton(_T("Other..."));

    pColorProp->EnableAutomaticButton(_T("Default"), ::GetSysColor(COLOR_3DFACE));

     

    // Add a new group

    CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("Misc"));

    // Add the new item into this

    pGroup3->AddSubItem(pColorProp);

     

    // And finally add the end result to the grid control

    m_wndPropList.AddProperty(pGroup3);

     

    Creating a custom item is not that hard. You need to know which functions to overwrite and derive from one of the properties. We will create one that will have one accept and one cancel button near an edit box:

    //Definition of a class

    class CTwoButtonsProp : public CMFCPropertyGridProperty

    {

    public:

    CTwoButtonsProp(const CString& strName,

    const COleVariant& varValue);

     

    protected:

    virtual BOOL HasButton() const { return TRUE; }

    virtual void AdjustButtonRect();

    virtual void OnClickButton(CPoint point);

    virtual void OnDrawButton(CDC* pDC, CRect rectButton);

     

    CImageList m_images;

    };

     

    //Constructor

    CTwoButtonsProp::CTwoButtonsProp(const CString& strName,

    const COleVariant& varValue) : CMFCPropertyGridProperty(strName, varValue)

    {

    // Load image and create a list from it

    CBitmap bmp;

    bmp.LoadBitmap(IDB_BUTTONS);

     

    m_images.Create(14, 14, ILC_MASK | ILC_COLOR8, 0, 0);

    m_images.Add(&bmp, RGB(255, 0, 255));

    }

     

    // Change the size of the button

    void CTwoButtonsProp::AdjustButtonRect()

    {

    CMFCPropertyGridProperty::AdjustButtonRect();

    m_rectButton.left -= m_rectButton.Width();

    }

     

    //Action to take upon button click

    void CTwoButtonsProp::OnClickButton(CPoint point)

    {

    BOOL bIsLeft = point.x < m_rectButton.CenterPoint().x;

    AfxMessageBox(bIsLeft ? _T("Left button clicked") :

    _T("Right button clicked"));

    }

     

    // How to draw the buttons

    void CTwoButtonsProp::OnDrawButton(CDC* pDC, CRect rectButton)

    {

    for (int i = 0; i < 2; i++)

    {

    CMFCToolBarButton button;

     

    CRect rect = rectButton;

     

    if (i == 0)

    {

    rect.right = rect.left + rect.Width() / 2;

    }

    else

    {

    rect.left = rect.right - rect.Width() / 2;

    }

     

    // Acquire some visual studio style

    CMFCVisualManager::AFX_BUTTON_STATE state = CMFCVisualManager::ButtonsIsHighlighted;

     

    CMFCVisualManager::GetInstance()-> OnFillButtonInterior(pDC, &button, rect, state);

     

    m_images.Draw(pDC, i, CPoint(rect.left, rect.top), ILD_NORMAL);

     

    CMFCVisualManager::GetInstance()-> OnDrawButtonBorder(pDC, &button, rect, state);

    }

    }

     

    //Finally in the initialization create an instance of this

    pGroup5->AddSubItem(new CTwoButtonsProp(_T("2 Buttons"), _T("text")));

     

    The result speaks for itself:

    And I will show you some of the other properties and styles you can create. For now this will be only in pictures:

     

     

     

     

     

    This will be all for this piece on the MFC Feature Pack. I would like to thank you for reading my article. I hope you have learned a lot and you will rate my article as you think it's worth. If you have any questions feel free to put them up here on the blog or over our friendly community at DevHardware. Live With Passion!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    .NET ARTICLES

    - Introducing .NET
    - Building Business Objects for an Application
    - Methods for an Application`s Business Logic ...
    - Properties of an Application`s Business Logi...
    - Classes and Properties in an Application`s B...
    - Organizing Code for the Business Logic Layer...
    - Building the Business Logic Layer
    - Completing a Business Layer with Windows Wor...
    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek