Child Window Controls
Child Window Controls
Allow user to display/select/input info in standard ways ? Windows Environment does most of work in:
?
Often used as input devices for parent window ? Are the "working components" of Dialog Boxes ? Windows OS contains each control's WinProc
?
Type Window Class MFC Class ---------------------------------------------------Static Text Button Edit Control List Box Combo Box Scroll Bar
?
CreateWindow ()
For any kind of window, including a control Typically called in response to WM_CREATE or WM_SIZE
Parameters:
1. Predefined control window class names:
"STATIC", "BUTTON", EDIT, LISTBOX, COMBOBOX, SCROLLBAR, others
3. Window style
WS_, SS_, BS_, ES_, LBS_, CBS_, SBS_ (see CreateWindow help) Several styles can be combined with the bitwise or operator ( | ) All controls should include WS_CHILD style
Parameters 4-7:
X,Y position (Relative to the upper left corner of parent window client area) Width & Height
9. Handle to menu
Controls dont have menus So hMenu parameter used to hold controls integer ID ID value passed with WM_COMMAND message generated when user interacts with the control Allows program to identify which control was activated
Control message handlers in same switch/case statement with menu handlers (WM_COMMAND) ? Done just as for menu handlers
Handle of destination window ID of message to send wParam and lParam values containing message data, if any
Need to be type cast
There are many messages that can be sent to a control ? Depend on type of control
?
Static Controls
Lots of styles, see online help on Static Control Styles. Some examples: SS_BITMAP, SS_CENTER, SS_GRAYFRAME, SS_ICON, SS_SIMPLE, SS_WHITEFRAME, etc. ? Change text with WM_SETTEXT message May need to format values with wsprintf( ) ? Retrieve text with WM_GETTEXT message or GetWindowText()
?
Button Controls
Some Styles: BS_PUSHBUTTON, BS_RADIOBUTTON, BS_CHECKBOX, BS_OWNERDRAW, BS_GROUPBOX, etc. ? Button notification codes:
?
Program communicates with list box by sending it messages; some common List Box messages:
LB_RESETCONTENTS, LB_ADDSTRING, LB_GETCURSEL, LB_GETTEXT, LB_DELETESTRING
? ? ?
Combo boxes much like list boxes (CBS_, CB_, CBN_) Program examples: listbox, combo
EDIT CONTROLS
? For
viewing and editing text ? Current location kept track of with a "carat
A small vertical line
? Backspace,
Delete, arrow keys, highlighting work as expected ? Scrolling possible (use WS_HSCROLL, WS_VSCROLL styles) ? No ability to format text with different fonts, sizes, character styles, etc.
Use Rich Edit Control for this
common styles
in an edit control stored as one long character string ? Carriage return <CR> is stored as ASCII code (0x0D,0x0A) ? <CR> inserted automatically if a line doesnt fit and wraps ? NULL character inserted only at end of last line of text