Title: Programming Windows with MFC
1Programming Windows with MFC
2Chapter 7
3The Classic Controls
Control Type WNDCLASS MFC Class
Buttons "BUTTON" CButton
List boxes "LISTBOX" CListBox
Edit controls "EDIT" CEdit
Combo boxes "COMBOBOX" CComboBox
Scroll bars "SCROLLBAR" CScrollBar
Static controls "STATIC" CStatic
4The Classic Controls Creating
- Create
- A flat look
- CreateEX
- A chiseled look
A list box with flat edges and chiseled edges
5The four types of button controls
6The buttons window style
Style Description
BS_PUSHBUTTON Creates a standard push button control
BS_DEFPUSHBUTTON Creates a default push button used in dialog boxes to identify the push button that's clicked if Enter is pressed
BS_CHECKBOX Creates a check box control
BS_AUTOCHECKBOX Creates a check box control that checks and unchecks itself when clicked
BS_3STATE Creates a three-state check box control
BS_AUTO3STATE Creates a three-state check box control that cycles through three stateschecked, unchecked, and indeterminatewhen clicked
BS_RADIOBUTTON Creates a radio button control
BS_AUTORADIOBUTTON Creates a radio button control that, when clicked, checks itself and unchecks other radio buttons in the group
BS_GROUPBOX Creates a group box control
7Alignment of the text
Style Description
BS_LEFTTEXT Moves the text accompanying a radio button or check box control from the button's right (the default) to its left
BS_RIGHTBUTTON Same as BS_LEFTTEXT
BS_LEFT Left justifies the button text in the control rectangle
BS_CENTER Centers the button text in the control rectangle
BS_RIGHT Right justifies the button text in the control rectangle
BS_TOP Positions the button text at the top of the control rectangle
BS_VCENTER Positions the button text in the center of the control rectangle vertically
BS_BOTTOM Positions the button text at the bottom of the control rectangle
BS_MULTILINE Allows text too long to fit on one line to be broken into two or more lines
8Push Buttions
- ON_BN_CLICKED(IDC_BUTTON,OnButtonClicked)
- void CMainWindowOnButtonClicked ()
-
- MessageBox (_T ("I've been clicked!"))
-
9Check Boxes
- CButtonSetCheck
- //Check Check Boxes
- m_wndCheckBox.SetCheck(BST_CHECKED)
- //Uncheck Check Boxes
- m_wndCheckBox.SetCheck(BST_UNCHECKED)
10The CListBox Class
- Encapsulates list box controls
- Display lists of text strings called items
- ON_LBN message-map macros
11The CListBox Classes
- Creating
- m_wndListBox.Create (WS_CHILD WS_VISIBLE
LBS_STANDARD, rect, this, IDC_LISTBOX) - Adding and Removing Items
- CListBoxAddString and CListBoxInsertString
- CListBoxDeleteString
- CListBoxGetCount
12List Box Notifications
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
13CStatic Class
- Static controls
- Created from the STATIC WNDCLASS
- Text, rectangles, and images
14The FontView Application
15The CEdit Class
- Encapsulates the functionality of edit controls
- Used for text entry and editing
- Single-line and multi-line
16A dialog box with two single-line edit controls.
17Creating an Edit Control
- CEditCreate
- CEditSetLimitText
18Inserting and Retrieving Text
- CEditSetWindowText
- CEditGetWindowText
- CEditReplaceSel
- CEditGetLine
19The CComboBox Class
- Combines a single-line edit control
- Three varieties
- Simple
- Drop-down
- Drop-down list
20A combo box with a drop-down list
21The CScrollBar Class
- Encapsulates scroll bar controls
- Created from the "SCROLLBAR" WNDCLASS
- Adding WS_VSCROLL and WS_HSCROLL flags to the
window style - CScrollBarCreate