Template class that implements "Property Browser" - like property page for ATL ActiveX Controls

Developing ActiveX Controls I always was unhappy to spend a fair amount of time to monotonous GUI work designing and implementing a property pages. After all I wrote this class that works in most cases as universal property page for any ATL-based ActiveX Control. The prototype for this class is property browser window known for any of Visual Basic's developers.

How it works:

Generally, this class uses IPropertyPage::SetObjects and query the control's IDispatch::GetTypeInfo to enumerate properties. Currently, this template class can handle following kinds of properties:
  • Simple types such as long, short, text(BSTR), ect.
  • Font (IFontDisp)
  • OLE_COLOR
  • Picture (IPictureDisp)
  • enums
  • boolean (VARIANT_BOOL)

    Current implementation don't display properties that has [hidden] or [nonbrowsable] attributes as well as indexed properties and properties of custom types (IFoo* or similar). The control's default interface should be dual and derived from IDispatch. If you use enumerated properties, the control must support IPerPropertyBrowsing::GetPredefinedStrings and IPerPropertyBrowsing::GetPredefinedValue (look the demo project for a sample) The main template class CPropertyBrowserPage is derived from both IPropertyPageImpl and CDialogImpl and uses some other helper classes that is briefly described below:

  • CPropBrowseWnd class is a owner-drawn listbox that displays properties grid and handles property selections, start/stop editing, ect. It is a main GUI window and CPropertyBrowserPage creates it in OnInitDialog.
  • CPBProperty is a simple class for storage properties attributes like name, type, current value and "dirty" status.
  • CPBPropertyHolder helper class is just a very simple container (array) of CPBProperty objects.
  • CPBColorPicker class is popup color picker window that allow user to choose color either from palette or from system's colors set.
  • CPBDropListBox class works together with in-place edit window to resemble combo-box like interface
  • PBDib class generally wasn't developed by me, this class encapsulates DIB manipulations API

    How to use:

    1. Copy following files to your project directory:

  • PropertyBrowserPage.h
  • PropertyBrowserPage.cpp
  • PBDib.h
  • PBDib.cpp

    and add *.cpp files to the project.

    2. Select "New ATL Object" from the Insert menu. Select "Property Page" and fill all fields Wizard requires. (For example, assume you choose "CDemoCtrlPage" as the name of your page's class)

    3. Go to CDemoCtrlPage class declaration and modify base classes list as following

    
    class ATL_NO_VTABLE CDemoCtrlPage :
    	public CComObjectRootEx<CComSingleThreadModel>,
    	public CComCoClass<CDemoCtrlPage, &CLSID_DemoCtrlPage>,
    //	public IPropertyPageImpl, <--- this lines should be removed
    //	public CDialogImpl
    /* next line should be added*/
    	public CPropertyBrowserPage<CDemoCtrlPage>
    
    next, change message map chain macro as following:
    
    BEGIN_MSG_MAP(CDemoCtrlPage)
    /*	CHAIN_MSG_MAP(IPropertyPageImpl<CDemoCtrlPage>) <--- this line should be removed*/
    	CHAIN_MSG_MAP(CPropertyBrowserPage<CDemoCtrlPage>) /*<--- this line should be added*/
    END_MSG_MAP()
    
    and remove Wizard-generated CDemoCtrlPage::Apply() method and finaly don'f forget to include PropertyBrowserPage.h

    4. Add following macro in your control's class property map

    
    	PROP_PAGE(CLSID_DemoCtrlPage)
    

    5. Go to Wizard-generated page's dialog template and remove all child controls.

    6. Please note that this class uses some C RTL code that makes _ATL_MIN_CRT directive impossible so you have to remove it.

    Note: This project was build using Visual C++ 5.0 SP3. I haven't tested it under Visual C++ 6.0

    If you find this class useful and would like to use it in your projects I'll very pleased. But I provide no warranty of any kind so you use it at your own risk. Please let me know if you find a bug(s) in this code or have any suggestion about it and I'll try to respond you if I'll able.

    Download demo project - 41 KB

    Download source - 19 KB

    History



  • Comments

    • There are no comments yet. Be the first to comment!

    Leave a Comment
    • Your email address will not be published. All fields are required.

    Top White Papers and Webcasts

    • Organizations today are under tremendous pressure to deliver a higher quality of products and services at lower costs, and to do so using existing resources. Any expenditure companies do make to help them achieve this goal is expected to deliver a measurable, hard-dollar ROI — and to deliver it quickly. The Internet of Things (IoT) is creating new opportunities for companies to enhance their products, gain business insights and differentiate their offerings. This whitepaper defines an ROI model for …

    • Live Event Date: May 16, 2017 @ 1:00 p.m. ET / 10:00 a.m. PT Developers who use popular JavaScript frameworks like React to build user interfaces often have to create components to build the interface. Building components is time consuming, has integration and maintenance risks, and worst of all, distracts them from the task at hand -- actually building the app. Attend this webinar to see how to quickly and easily add more than 115 professionally supported and tested components from Sencha to your React …

    Most Popular Programming Stories

    More for Developers

    RSS Feeds

    Thanks for your registration, follow us on our social networks to keep up-to-date