+ All Categories
Home > Documents > Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Date post: 05-Jan-2016
Category:
Upload: loreen-ryan
View: 239 times
Download: 2 times
Share this document with a friend
17
Chapter 7 Controls
Transcript
Page 1: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Chapter 7Controls

Page 2: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Scroll bar control

Page 3: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

3

Scroll bar control (1/3)

• Scroll bar codes (interfaces)

Page 4: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

4

CScrollBar Class(2/3)

• Member functions

Member functions meaning

SetScrollRange() Set the min and max range of the scroll bar

SetScrollPos() Set the thumb position

GetScrollPos() Get the thumb position

Page 5: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Scroll bar notification(3/3)

• Messages:

• Add message MACRO in MessageMap– Scroll Bars have no ID.

• Event Message Handler

ON_WM_HSCROLL() or ON_WM_VSCROLL()ON_WM_HSCROLL() or ON_WM_VSCROLL()

void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

WM_HSCROLL/ WM_VSCROLLWM_HSCROLL/ WM_VSCROLL

Page 6: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

6

Scroll bar message handler (4/3)

• WM_HSCROLL/WM_VSCROLL 메시지 핸들러

– nSBCode• Scroll bar code (types of event)

– nPos• Position of the thumb• Only use when nSBCode is SB_THUMBPOSITION or

SB_THUMBTRACK

– pScrollBar• Pointer to the scroll bar

void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);

Page 7: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Coding Practice

• Add a edit control and scroll bar control • Set the range of the scroll bar to (0, 100)• Show the position value of the thumb in the

edit control

Page 8: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

• Use Create Member function

Create CScrollBar by hand

m_VScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦ SBS_VERT, rectVert, this, IDC_VSCROLLBAR);

m_HScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

SBS_HORZ, rectHorz, this, IDC_HSCROLLBAR);

m_VScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦ SBS_VERT, rectVert, this, IDC_VSCROLLBAR);

m_HScrollBar.Create (WS_CHILD ¦ WS_VISIBLE ¦ WS_BORDER ¦

SBS_HORZ, rectHorz, this, IDC_HSCROLLBAR);

Page 9: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Coding Practice

• Attach horizontal and vertical scroll bars as shown below and draw a circle.

• Adjust the position of the circle using the scroll bar.

Page 10: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

List box control

Page 11: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

11

List Box Control(1/8)

• Listbox control:– Display lists of text strings called items– Optionally sort the items and have scroll bar

• 속성 대화상자

Single SelectionList box

Multiple Selection List box

Page 12: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

CListBox Class

• CListBox class encapsulates list box controls

• Creating a List Box– Use CListBox::Create member function

m_ListBox.Create (WS_CHILD ¦ WS_VISIBLE ¦ LBS_STANDARD,

rect, this, ID);

m_ListBox.Create (WS_CHILD ¦ WS_VISIBLE ¦ LBS_STANDARD,

rect, this, ID);

Page 13: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

List Box StylesStyle DescriptionLBS_STANDARD Creates a "standard" list box that has a border and a vertical scroll bar, notifies its parent

window when the selection changes or an item is double-clicked, and sorts items alphabetically.

LBS_SORT Sorts items that are added to the list box.LBS_NOSEL Creates a list box whose items can be viewed but not selected.LBS_NOTIFY Creates a list box that notifies its parent when the selection changes or an item is double-

clicked.LBS_DISABLENOSCROLL

Disables the list box's scroll bar when it isn't needed. Without this style, an unneeded scroll bar is hidden rather than disabled.

LBS_MULTIPLESEL Creates a multiple-selection list box.LBS_EXTENDEDSEL Adds extended selection support to a multiple-selection list box.LBS_MULTICOLUMN Creates a multicolumn list box.LBS_OWNERDRAWVARIABLE

Creates an owner-draw list box whose items can vary in height.

LBS_OWNERDRAWFIXED

Creates an owner-draw list box whose items are the same height.

LBS_USETABSTOPS Configures the list box to expand tab characters in item text.LBS_NOREDRAW Creates a list box that doesn't automatically redraw itself when an item is added or

removed.LBS_HASSTRINGS Creates a list box that "remembers" the strings added to it. Conventional list boxes have

this style by default; owner-draw list boxes don't.

LBS_WANTKEYBOARDINPUT

Creates a list box that sends its parent a WM_VKEYTOITEM or WM_CHARTOITEM message when a key is pressed. This style is used to customize the list box's response to keyboard input.

LBS_NOINTEGRALHEIGHT

Allows a list box to assume any height. By default, Windows sets a list box's height to a multiple of the item height to prevent items from being partially clipped.

Page 14: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

14

List Box Notifications

– LBN_DBLCLK, LBN_SELCHANGE and LBN_SELCANCEL messages require LBS_NOTIFY style setting

Notification Sent When Message-Map Macro LBS_NOTIFY Required?

LBN_SETFOCUS The list box gains the input focus.

ON_LBN_SETFOCUS No

LBN_KILLFOCUS The list box loses the input focus.

ON_LBN_KILLFOCUS No

LBN_ERRSPACE An operation failed because of insufficient memory.

ON_LBN_ERRSPACE No

LBN_DBLCLK An item is double-clicked. ON_LBN_DBLCLK Yes

LBN_SELCHANGE

The selection changes. ON_LBN_SELCHANGE Yes

LBN_SELCANCEL The selection is canceled. ON_LBN_SELCANCEL Yes

Page 15: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

15

Editing items

• Add and Delete Items

• Select items

m_list.AddString(_T(“apple”));m_list.DeleteString(3);

// For a single selection list boxm_list.SetCurSel(2);

// For a multiple selection list boxm_list.SetSel(2);m_list.SetSel(3, FALSE);

Page 16: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

16

Get selected items

// For a single selection list boxint nIndex = m_list.GetCurSel();if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str);}

// For a multiple selection list boxint nIndex = m_list.GetCaretIndex();if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str);}

Page 17: Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

Coding Practice

• Add buttons, edit box and List box to a dialog application

• Add and delete an item in the list box using button controls


Recommended