Common Controls
How to set a bitmap for a CExtButton button?
You can use the CExtBitmap class to load a bitmap from a file or a resource, generate an icon from this bitmap and finally set the icon for the button using the CExtButton::SetIcon() method. Here are the exact steps to achieve this: - Load a bitmap using
CExtBitmap::LoadBMP_File() or CExtBitmap::LoadBMP_Resource() ; - Make it 32-bit compatible using
CExtBitmap::Make32() ; - Use
CExtBitmap::AlphaColor() method to make all pixels of a particular color transparent; - Generate an
HICON handle from this bitmap using CExtBitmap::CreateHICON() ; - To assign the icon to a button (the
CExtButton class), use the CExtButton::SetIcon() method.
How to subclass controls on a CExtResizableDialog dialog dynamically?
If you have a great number of controls on a dialog, it may take quite a time to subclass all these items manually. Starting from version 2.80, there is a new method SubclassChildControls() in the CExtWS template that subclasses automatically all the child controls of CExtResizableDialog and CExtResizablePropertyPage dialogs. The method also eliminates the problem with an incorrect tab order of group boxes on a dialog. There is also a SubclassChildControls() global function, which you can use for any window.
You should invoke SubclassChildControls() after the window has been created. It subclasses the following standard controls: - Static labels including icons
- Edit controls
- Combo boxes
- Push buttons
- Check buttons
- Radio buttons
- Group boxes
- Progress controls
- Scroll bar controls
- Up-down (spin) controls
Another way of subclassing controls with CExtWS is to invoke SetAutoSubclassChildControls(true) before the window is created, i.e. in the class constructor. In this case, each control will be automatically subclassed when needed.
How to enable and use the multicolumn pop-up list box in the CExtComboBox control?
The multicolumn pop-up list box (See a screenshot) is implemented in the CExtComboBoxBase base class. The CExtComboBox class is derived from CExtComboBoxBase and simply makes the combo box drawn in the flat XP style. To turn on the multicolumn feature, just open the resource editor and make it owner-drawn (select Fixed or Variable in the Ownerdraw combo box) and apply the Has Strings style. The following methods allow you to manipulate the content of the multicolumn list box: CExtComboBoxBase classLbItemGet() returns a pointer to a CExtComboBoxBase::LB_ITEM object which keeps information about the cells in the specified row. LbColumnWidthGet /LbColumnWidthSet() gets/sets a width for the specified column.
CExtComboBoxBase::LB_ITEM classLbItemCellInsert() inserts a new cell at the specified position. LbItemCellRemove() removes a cell at the specified position. LbItemCellGet() returns a pointer to a CExtComboBoxBase::LB_ITEM::CELL object, which keeps information about the cell at the specified position. LbItemCellGetCount() returns a number of the cells.
CExtComboBoxBase::LB_ITEM::CELL classm_nLParam specifies the user-defined data.
m_clrText specifies the text color.
m_clrBack specifies the background color.
m_sItemText specifies the text.
You can download a simple TextComboGrid project that shows how to create a combo box filled with the local URL history. It features Last Access Date, Title and Url columns and also demonstrates how to use custom text/background colors.
How to change the font used in CExtButton?
The CExtButton class has a OnQueryFont virtual method used to retrieve a font for drawing button text. By default, it is the font of the parent window:
virtual HFONT OnQueryFont()
{
ASSERT_VALID( this );
HFONT hFont = NULL;
CWnd *pParent = GetParent();
if( pParent != NULL )
{
CFont * pFont = pParent->GetFont();
if( pFont != NULL )
hFont = (HFONT)pFont->GetSafeHandle();
}
return hFont;
}
You can always override this method and change the default font. The following code returns the font stored in the button itself:
virtual HFONT OnQueryFont()
{
ASSERT_VALID( this );
HFONT hFont = NULL;
CFont * pFont = GetFont();
if( pFont != NULL )
hFont = (HFONT)pFont->GetSafeHandle();
return hFont;
}
I use CExtGroupBox and a set of controls. Some controls are not painted correctly, what may be wrong?
If you put controls on a dialog template, make sure they are assigned the proper tab order. Since the Prof-UIS group box has a non-transparent background, the tab order is essential. Windows paints controls on the dialog step by step starting from the control with the highest tab order number to the control with the lowest number. So, ensure your group box is assigned the highest tab order number.
Static text controls used on the resizable dialog are flickering when it is resized. Besides, their background is inconsistent with that of the resizable dialog. How to resolve these problems?
To avoid flickering, just turn on the Clip Children option for your dialog.
Please note that the WS_CLIPCHILDREN style is not compatible with some controls like the static text because they use the background of their parent window "AS IS". Instead, please use the corresponding Prof-UIS classes: CExtCheckBox for check boxes, CExtRadioButton for radio buttons, CExtGroupBox for group boxes, and CExtLabel for static text controls. Unlike those available in MFC, these classes are fully consistent with the Office 2003/VS 2005 theme and include some additional features.
How to use Prof-UIS simple controls in your application?
Just replace the standard MFC classes in your code with the corresponding classes of Prof-UIS. Do not forget to include the appropriate header files. For instance, to use the combo box of Prof-UIS, replace the name CComboBox with CExtComboBox .
If you have any questions, please visit our forum or contact our technical support team at support@prof-uis.com.
|