COXFontPickerButton Overview
Copyright © The Code Project 1997-1999, All Rights Reserved

COXFontPickerButton is COXBitmapButton derived class that is designed to allow a user to choose font and text color. This control uses standard CFontDialog to choose font and text color and uses COXStatic control in order to display the chosen font and text color. And of course it allows you to use all power of COXBitmapButton class such as displaying an image, specifying text font and color, tooltip and many more features available in this class. Also we provide DDX routines that allows you to associate COLORREF and CFont variables with the control and set/retrieve data in standard manner (the details will be provided below).

Usage

I.    COXFontPickerButton in dialog or form view

1) In resource editor put a button control in a dialog template. Make sure that you specify owner drawn style for this button (COXBitmapButton
requirement)

2) Put a static control next to the button. This static control will be later explicitly associated with the button and subclassed with COXStatic object. This control will be used in order to display chosen font and text color

3) In OnInitDialog() for CDialog-derived implementation and in OnInitialUpdate() for CFormView-derived implementation you must call the following function that will associate the static control with font picker button:
BOOL SetBuddy(UINT nBuddyWndID);

4) You might want to associate COLORREF and/or CFont variable with the font picker button using the following DDX routines:
void DDX_FontPickerFont(CDataExchange *pDX, int nIDC, CFont* pFont);
void DDX_FontPickerColor(CDataExchange *pDX, int nIDC, COLORREF& clr);
In order to do that you have to add corresponding variables to your CDialog or CFormView derived class:
CFont m_font;
COLORREF m_clrText;
and update your DoDataExchange() routine by adding the following lines of code:
DDX_FontPickerFont(pDX, IDC_BUTTON_FONT, &m_font);
DDX_FontPickerColor(pDX, IDC_BUTTON_FONT, m_clrText);
where IDC_BUTTON_FONT is presumed to be an ID of the font picker button. Using these DDX routines you can set/retrieve font and text color by simply calling UpdateData() function.

II.    COXFontPickerButton as a child control of any arbitrary window (explicit creation)

1) Create the COXFontPickerButton control explicitly using CButton::Create() function. Make sure that you specify BS_OWNERDRAW style for this button (COXBitmapButton requirement) 

2) Create the COXStatic control explicitely using COXStatic::Create() function. Before calling this function you need to calculate the rectangle for this control so it will be positioned nicely relatively to the COXFontPickerButton control

3) After both controls were successfully created you have to associate the COXStatic control with the COXFontPickerButton control using:
BOOL SetBuddy(COXStatic* pBuddy);

4) After accomplishing three previous steps you've got fully functional font picker button control. User can click on the button and standard CFontDialog will appear where a user can chose the font and text color. The chosen font and text color can be retrieved using following functions:
CFont* GetBuddyFont() const;
BOOL GetBuddyLogFont(LOGFONT* pLF) const;
COLORREF GetBuddyTextColor() const;