Introduction
The SpinControl
I decided to write for the first time, a program for the SmartPhone and found that there are many differences that need to be overcome compared to the Pocket PC. However there is not a lot of help so I decided to share a few of the tricks I found with you. Hopefully it will make SmartPhone development a little easier. Because of the time I have available, I will share one tip at a time.
Background
This article deals mainly with MFC and dialog based applications. There is not a lot of help when coding using the MFC classes and dialog based applications for the SmartPhone. I also found that in VS 2005 help files, they removed a lot of the sample code.
The Combobox
The SmartPhone does not have a touch screen and therefore it does not natively support the Combobox. The help files tell you to use a Spin-Box. You will not find this control in the tools drop down. It has to be created using a Spin Control and a Listbox.
A Spin control must be attached to the Listbox in the code.
Here is how it is done...
First you add a listbox to your dialog. Use the following attributes:
- Border=TRUE
- No Integral Height=TRUE
- Notify=TRUE
- Vertical Scrollbar=TRUE
- Selection=Single
and give it an ID - we will use IDC_CONTROL1
Then you add a Spin Control. The control attributes are:
- Alignment=Right
- Arrow Keys=True
- Orientation=Horizontal
- Wrap=True
- Set Buddy Integer=TRUE
Then you need to add control variables to the listbox and spin controls, we will add m_ctrlControl1
for the listbox and m_ctrlSpin1
for the Spin Control.
Next you need to add a string variable for the listbox, for this demo we will assign a CString
called m_strControl1
.
protected:
CString m_strControl1;
CListBox m_ctrlControl1;
CSpinButtonCtrl m_ctrlSpin1;
Next, you will need to tie the Spin control to the list box. In the InitDialog
of your application, add the following code:
BOOL CSampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_ctrlSpin1.SetBuddy(&m_ctrlControl1);
Now we are ready to populate the control:
m_ctrlControl1.AddString(_T("Item1"));
m_ctrlControl1.AddString(_T("Item2"));
m_ctrlControl1.AddString(_T("Item3"));
Now you can set the text to default to the first entry like this:
m_ctrlControl1.GetText(0,m_strControl1);
UpdateData(FALSE);
There you have it... A SpinBox
control for the SmartPhone.
In my next article, we will discuss how to set the back arrow key on a Smartphone to act as a Backspace key while in a textbox.