I am using custom base styles in my grid view and would like to read these base styles from and write them to the profile or registry.
Take a look at gridsvw3.cpp in gridapp. This registers some base styles (an error style and a combo style) and gives the user the possibility to change this base styles and write them to the profile (or registry). When the user opens a new view, the styles will be initialized with attributes specified in the profile (or registry).
Please take care that you register the base styles before calling ReadProfile(). ReadProfile will load the setting from the profile and override the standard settings if it can find an entry for the specific base style.
Example:
void CGridSample3View::SetupBaseStyles()
{
ASSERT(GetParam()->GetStylesMap() == NULL);
// ASSERTION-> a stylesmap is already connected to parameter-object ->END
if (GetParam()->GetStylesMap() != NULL)
return;
// create a stylesmap and connect it with the parameter-object
CGXStylesMap* pStyMap;
GetParam()->SetStylesMap(pStyMap = new CGXStylesMap);
// create standard styles
pStyMap->CreateStandardStyles();
// Add some base styles
// "Combo Style" - A style with a combo box and choice list
pStyMap->RegisterStyle(szComboStyle,
CGXStyle()
.SetControl(GX_IDS_CTRL_CBS_DROPDOWNLIST)
.SetChoiceList(_T("one\r\ntwo\r\nthree\r\nfour\r\nfive\r\nsix\r\n")),
TRUE // system-style (non removable)
);
// "Error Style" - Yellow text on red backcolor with a bold font
pStyMap->RegisterStyle(szErrorStyle,
CGXStyle()
.SetTextColor(RGB(255,255,0)) // yellow
.SetInterior(RGB(255,0,0)) // red
.SetFont(
CGXFont()
.SetBold(TRUE)
),
TRUE // system-style (non removable)
);
// I do also want to adapt the base styles:
// StandardStyle() calls pStyMap->LookupStyle(pStyMap->m_wStyleStandard, ...)
// and returns a reference to the Standard-Style.
//
// So, I can simply adapt this style's settings to my needs.
StandardStyle()
.SetFont( CGXFont()
.SetFaceName(_T("Times New Roman"))
.SetSize(9) );
RowHeaderStyle()
.SetTextColor(RGB(0,0,255) );
// Now, read the styles from profile.
// Note that reading style from profile can override the previous settings.
// The previous settings are standard settings.
pStyMap->SetSection(_T("My Base Styles")); // extra profile section
pStyMap->ReadProfile();
}
void CGridSample3View::OnInitialUpdate()
{
BOOL bNew = ConnectParam();
if (bNew)
SetupBaseStyles(); // Setup base styles and read them from profile
CMyGridView::OnInitialUpdate(); // Creates all objects and links them to the grid
...
}