News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How to create a flat combo box?

By Andrey Yatsyk, March 25, 2002.
Print version

Question

How to create a flat combo box (same as in Pocket Word above the file list and used for selecting sorting order)?

Answer

Really, the control that Pocket Word uses is not combo box. I.e. there is no style that you can set to combo box and get the same looking control.

One of possible solutions is to create a custom control with similar look and feel. The CDocListComboBox class was developed for such purpose. It is derived from CWnd class and has a custom redefined paint method. This control can be in two states: the normal state when popup menu is not showed and the popup state when the assigned menu is showed.

I will provide some notes about this control using. You can familiarize with this code in a sample project.

At first you should create the a combo by Create method. In the sample project the following chunk of code responsible for this action:

m_ctrlDocListCombo.Create( TEXT("FlatComboBox"), WS_CHILD | WS_VISIBLE, CRect(rect.left, rect.top, rect.right, rect.top + 22), this, 1 /*ID*/ );

You should create a menu with items that will be showed when the combo box pops up and set the menu id by invoking SetDropDownMenu() method:

m_ctrlDocListCombo.SetDropDownMenu(IDR_MYMENUBAR);

Also you should provide two strings that will be displayed in this control. The first one is displayed when the control is in the popup state and the second one when it is not:

m_ctrlDocListCombo.SetTitleText(TEXT("Show")); m_ctrlDocListCombo.SetSelectedText(TEXT("Digits"));

Finally you can create the usual message handlers for menu commands.

By using this simple control you will get standard look and feel and you the users of your program will be familiar with this type of control because of similar control widespread in Microsoft products.

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House