Add Color Property page in ActiveX control

  • Create the ActiveX Control project using MFC ActiveX Control Wizard.
  • Open the XXXCtrl.cpp file.
  • Include the following header file.
            #include <\msstkppg.h>
  • Add the property page ID. See the code below
     BEGIN_PROPPAGEIDS(CXXXCtrl, 1)
        PROPPAGEID(CLSID_StockColorPage);
END_PROPPAGEIDS(CXXXCtrl) ;
  • Click the class wizard and add the Forecolor and Backcolor stock property availabe in Automation option.
  • Add the Message map for both Backcolor and Forecolor. This message map will execute when you change the background color in the color palette. Get the RGB value. 
void CXXXCtrl::OnBackColorChanged()
{
COLORREF nBackColor = TranslateColor(GetBackColor()) ;
m_nBackRColor = GetRValue(nBackColor) ;
m_nBackGColor = GetGValue(nBackColor) ;
m_nBackBColor = GetBValue(nBackColor) ;

COleControl::OnBackColorChanged();
}


void CXXXCtrl::OnForeColorChanged()
{
COLORREF nBackColor = TranslateColor(GetForeColor()) ;
m_nForeRColor = GetRValue(nForeColor) ;
m_nForeGColor = GetGValue(nForeColor) ;
m_nForeBColor = GetBValue(nForeColor) ;
COleControl::OnForeColorChanged();
}

  • To set the value that we get from OnBackColorChanged and OnForeColorChanged, Add the below two lines in function called DoPropExchange.
SetForeColor(RGB(m_nForeRColor,
                 m_nForeGColor,m_nForeBColor));
SetBackColor(RGB(m_nBackRColor,
                 m_nBackGColor,m_nBackBColor));
  • Now run the program and you can see the color property page in the property dialog.