Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)"— Presentation transcript:

1 Chapter 7 Controls

2 Scroll bar control

3 3 Scroll bar control (1/3) Scroll bar codes (interfaces)

4 4 CScrollBar Class(2/3) Member functions meaning SetScrollRange()Set the min and max range of the scroll bar SetScrollPos()Set the thumb position GetScrollPos()Get the thumb position

5 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_VSCROLL

6 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);

7 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

8 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);

9 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.

10 List box control

11 11 List Box Control(1/8) Listbox control: –Display lists of text strings called items –Optionally sort the items and have scroll bar 속성 대화상자 Single Selection List box Multiple Selection List box

12 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);

13 List Box Styles StyleDescription LBS_STANDARDCreates a "standard" list box that has a border and a vertical scroll bar, notifies its parent window when th e selection changes or an item is double-clicked, and sorts items alphabetically. LBS_SORTSorts items that are added to the list box. LBS_NOSELCreates a list box whose items can be viewed but not selected. LBS_NOTIFYCreates a list box that notifies its parent when the selection changes or an item is double-clicked. LBS_DISABLENOSCROL L Disables the list box's scroll bar when it isn't needed. Without this style, an unneeded scroll bar is hidden r ather than disabled. LBS_MULTIPLESELCreates a multiple-selection list box. LBS_EXTENDEDSELAdds extended selection support to a multiple-selection list box. LBS_MULTICOLUMNCreates a multicolumn list box. LBS_OWNERDRAWVARI ABLE Creates an owner-draw list box whose items can vary in height. LBS_OWNERDRAWFIXE D Creates an owner-draw list box whose items are the same height. LBS_USETABSTOPSConfigures the list box to expand tab characters in item text. LBS_NOREDRAWCreates a list box that doesn't automatically redraw itself when an item is added or removed. LBS_HASSTRINGSCreates a list box that "remembers" the strings added to it. Conventional list boxes have this style by defa ult; owner-draw list boxes don't. LBS_WANTKEYBOARDI NPUT Creates a list box that sends its parent a WM_VKEYTOITEM or WM_CHARTOITEM message when a ke y is pressed. This style is used to customize the list box's response to keyboard input. LBS_NOINTEGRALHEIG HT Allows a list box to assume any height. By default, Windows sets a list box's height to a multiple of the ite m height to prevent items from being partially clipped.

14 14 List Box Notifications –LBN_DBLCLK, LBN_SELCHANGE and LBN_SELCANCEL messages require LBS_NOTIFY style setting NotificationSent WhenMessage-Map MacroLBS_NOTIFY Required? LBN_SETFOCUSThe list box gains the input foc us. ON_LBN_SETFOCUSNo LBN_KILLFOCUSThe list box loses the input foc us. ON_LBN_KILLFOCUSNo LBN_ERRSPACEAn operation failed because of insufficient memory. ON_LBN_ERRSPACENo LBN_DBLCLKAn item is double-clicked.ON_LBN_DBLCLKYes LBN_SELCHANG E The selection changes.ON_LBN_SELCHANGEYes LBN_SELCANCELThe selection is canceled.ON_LBN_SELCANCELYes

15 15 Editing items Add and Delete Items Select items m_list.AddString(_T(“apple”)); m_list.DeleteString(3); // For a single selection list box m_list.SetCurSel(2); // For a multiple selection list box m_list.SetSel(2); m_list.SetSel(3, FALSE);

16 16 Get selected items // For a single selection list box int nIndex = m_list.GetCurSel(); if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str); } // For a multiple selection list box int nIndex = m_list.GetCaretIndex(); if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str); }

17 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


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

Similar presentations


Ads by Google