Click here to Skip to main content
Click here to Skip to main content

Visual Studio 2005 and the SmartPhone

, 17 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Tips on SmartPhone coding the MFC way - Part 1

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.

// In your header, you will have the following
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();

//..... startup code such as menus and defaults from the registry

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

DRLaverdure
Software Developer (Senior) Pocketfleet
Canada Canada
I am a mechanic with a passion for software development. I am retired from the Canadian Military. I have been programming since as far back as the first IBM Clone although I have never had any formal education in the area of computer sciences.

Comments and Discussions

 
QuestionHow can i attach CUpDownCtrl with CListBox in WTL? PinmemberHlaingMin1-May-08 23:50 
AnswerRe: How can i attach CUpDownCtrl with CListBox in WTL? PinmemberDRLaverdure2-May-08 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141220.1 | Last Updated 18 Dec 2007
Article Copyright 2007 by DRLaverdure
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid