Home Index  | Back

New Page 1
Lesson 1 -Building Your First Windows Application

1.1 : Creating a Windows Application

1.2 : Creating a Dialog-Based Application

1.3 : Creating DLLs, Console Applications, and More

1.4 : Changing Your AppWizard Decisions
 1.5 : Understanding AppWizard’s Code
 1.6 : Understanding a MDI Application
 1.7 : Understanding the Components of a Dialog-Based Application

Lesson 2 - Dialogs and Controls

2.1 : Understanding Dialog Boxes

2.2 : Creating a Dialog Box Resource

 2.3 : Writing a Dialog Box Class
 2.4 : Using the Dialog Box Class
Lesson 3 - Messages and Commands

3.1 : Understanding Message Routing

3.2 : Understanding Message Loops

 3.3 : Reading Message Maps
 3.4 : Learning How ClassWizard Helps You Catch Messages
 3.5 : Recognizing Messages
 3.6 : Understanding Commands
 3.7 : Understanding Command Updates
 3.8 : Learning How ClassWizard Helps You Catch Commands and Command Updates

Lesson 4 - Documents and Views

4.1 : Understanding the Document Class

4.2 : Understanding the View Class

4.3 : Creating the Rectangles Application

 4.4 : Other View Classes

4.5 : Document Templates, Views, and Frame Windows

Lesson 5 - Drawing on the Screen

5.1 :Understanding Device Contexts

 5.2 : Introducing the Paint1 Application
 5.3 : Building the Paint1 Application
 5.4 : Scrolling Windows
 5.5 : Building the Scroll Application
Lesson 6 - Building a Complete Application: ShowString

6.1 : Building an Application That Displays a String

 6.2 : Building the ShowString Menus
 6.3 : Building the ShowString Dialog Boxes
 6.4 : Making the Menu Work
 6.5 : Making the Dialog Box Work
 6.6 : Adding Appearance Options to the Options Dialog Box
Lesson 7 -  Status Bars and Toolbars

7.1 : Working with Toolbars

 7.2 : Working with Status Bars
Lesson 8 - Common Controls

8.1 : The Progress Bar Control

 8.2 : The Up-Down Control
 8.3 : The Image List Control
 8.4 : The List View Control
 8.5 : The Tree View Control
 8.6 : The Rich Edit Control
 8.7 : The Date Picker Control
 8.8 : Month Calendar Control
 8.9 : Scrolling the View
Lesson 9 - Property Pages and Sheets

9.1 : Introducing Property Sheets

 9.2 : Creating the Property Sheet Demo Application
 9.3 : Running the Property Sheet Demo Application
Lesson 10 - ActiveX Concepts

10.1 : The Purpose of ActiveX

10.2 : Object Linking

10.3 : Object Embedding

 10.4 : Containers and Servers
 10.5 : Toward a More Intuitive User Interface
 10.6 : The Component Object Model  

10.7 : Automation

 10.8 : ActiveX Controls

Lesson 11 -  Building an ActiveX Control

11.1 : Creating a Rolling-Die Control

11.2 : Displaying the Current Value

11.3 : Reacting to a Mouse Click and Rolling the Die 

 11.4 : Creating a Better User Interface
 11.5 : Generating Property Sheets
Lesson 12 - Database Access

12.1 : Understanding Database Concepts

12.2 : Creating an ODBC Database Program

 12.3 : Choosing Between ODBC and DAO
 12.4 : OLE DB

Lesson -8:Common Controls

8.2- The Up-Down Control

An up-down control, which is little more than a couple of arrows that the user clicks to increase or decrease the control’s setting. Typically, an edit control next to the up-down control, called a buddy edit control or just a buddy control, displays the value to the user.

In the Common application, you can change the setting of the up-down control by clicking either of its arrows. When you do, the value in the attached edit box changes, indicating the up-down control’s current setting. After the control has the focus, you can also change its value by pressing your keyboard’s Up and Down arrow keys.

Creating the Up-Down Control

Add another call to CCommonView::OnCreate(), this time calling it CreateUpDownCtrl(). Add the member function and the code in Listing 8.3. Also add resource symbols for IDC_BUDDYEDIT and IDC_UPDOWN.

Listing 8.3 CommonView.cpp—CCommonView::CreateUpDownCtrl()

void CCommonView::CreateUpDownCtrl()

{

m_buddyEdit.Create(WS_CHILD | WS_VISIBLE | WS_BORDER,

CRect(50, 120, 110, 160), this, IDC_BUDDYEDIT);

m_upDown.Create(WS_CHILD | WS_VISIBLE | WS_BORDER |

UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS,

CRect(0, 0, 0, 0), this, IDC_UPDOWN);

m_upDown.SetBuddy(&m_buddyEdit);

m_upDown.SetRange(1, 100);

m_upDown.SetPos(50);

}

The program creates the up-down control by first creating the associated buddy control to which the up-down control communicates its current value. In most cases, including this one, the buddy control is an edit box, created by calling the CEdit class’s Create() member function. This function’s four arguments are the control’s style flags, the control’s size, a pointer to the control’s parent window, and the control’s ID. If you recall the control declarations, m_buddyEdit is an object of the CEdit class.

Now that the program has created the buddy control, it can create the up-down control in much the same way, by calling the object’s Create() member function. As you can probably guess by now, this function’s four arguments are the control’s style flags, the control’s size, a pointer to the control’s parent window, and the control’s ID. As with most controls, the style constants include the same constants that you use for creating any type of window. The CSpinButtonCtrl class, of which m_upDown is an object, however, defines special styles to be used with up-down controls. Table 8.1 lists these special styles.

Table 8.1 Up-Down Control Styles

Styles Description
UDS_ALIGNLEFT

 Places the up-down control on the left edge of the buddy control

UDS_ALIGNRIGHT

Places the up-down control on the right edge of the buddy control

UDS_ARROWKEYS

Enables the user to change the control’s values by using the keyboard’s Up and Down arrow keys

UDS_AUTOBUDDY

Makes the previous window the buddy control

UDS_HORZ Creates a horizontal up-down control
UDS_NOTHOUSANDS

Eliminates separators between each set of three digits

UDS_SETBUDDYINT

Displays the control’s value in the buddy control

UDS_WRAP Causes the control’s value to wrap around to its minimum when the maximum is reached, and vice versa

This Unit’s sample application establishes the up-down control with calls to SetBuddy(), SetRange(), and SetPos(). Thanks to the UDS_SETBUDDYINT flag passed to Create() and the call to the control’s SetBuddy() member function, Common doesn’t need to do anything else for the control’s value to appear on the screen. The control automatically handles its buddy. Try building and testing now.

 

Next>>
 
© Dewsoft Overseas