Child Window Controls
Child Window Controls
? Allow user to display/select info in standard ways Six “Classic” Control Types
? Windows Environment does most of work in: ? Go back to first versions of Windows
– painting/updating a Control's screen area ? Implemented in User.exe
– determining what user is doing
? Can do the "dirty work" for the main window
Type Window Class MFC Class
? Often used as input devices for parent window ----------------------------------------------------
? Are the "working components" of Dialog Boxes Static Text “STATIC” CStatic
? Windows OS contains each control's WinProc Button “BUTTON” CButton
– so messages to controls are processed in predefined way Edit Control “EDIT” CEdit
? Parent window communicates with controls by List Box “LISTBOX” CListBox
sending/receiving messages Combo Box “COMBOBOX” CComboBox
Scroll Bar “SCROLLBAR” CScrollBar
? All are windows
1
TYPE WINDOW CLASS MFC CLASS Classic Window Controls
--------------------------------------------------- ? Static
Rich Edit “RichEdit20A” CRichEditCtrl – Primarily to display text
Slider “msctls_trackbar32” CSliderCtrl
Spin Button “msctls_updown32” CSpinButtonCtr – Can also display icon images and rectangles
Status Bar “msctls_statusbar32” CStatusBarCtrl – Automatically redrawn if exposed
Tab “SysTabControl32” CTabCtrl – Often used as labels for other controls
Toolbar “ToolbarWindow32” CToolBarCtrl
ToolTip “tooltips_class32” CToolTipCtrl ? Button
Tree View “SysTreeView32” CTreeCtrl
– “Clicked” by user to indicate desired actions or choices
made
– Lots of different styles (e.g., pushbutton, check, radio,
group)
– Typically notify parent window when user chooses the
button
– User selects item from list & item is copied to edit box ? Edit
– One type allows user to type into edit box – To enter/view/edit/delete text
• If text matches item in list, it is highlighted & scrolled into view – Single or multiline control
– Another type doesn’t allow user to type in edit box – Lots of word processing capability
– Also Clear/Copy/Cut/Paste/Undo capability
2
? 9. Handle to “menu” Example (Win32 API)
– Controls don’t have menus
– So hMenu parameter used to hold control’s integer ID ? In response to WM_CREATE in Main Window’s
– ID value passed with WM_COMMAND message WndProc( ):
generated when user interacts with the control
– Allows program to identify which control was activated HWND hMyButton;
? 10. Handle to instance of program creating control HINSTANCE hInstance;
– GetWindowLong () usually used to get this value hInstance = (HINSTANCE) GetWindowLong (hWnd,
GWL_HINSTANCE);
? 11. Pointer to window creation data hMyButton = CreateWindow (“BUTTON”, “Push Me”,
– Normally NULL WS_CHILD | BS_PUSHBUTTON, 10, 10, 130, 60, hWnd,
(HMENU)ID_MYBUTTON, hInstance, NULL);
ShowWindow (hMyButton, SW_SHOWNORMAL);
3
MFC Control Message Sending Messages to
Handlers Controls, Win32 API
? Set up message macro for each notification ? SendMessage( )--sends message to a window’s
code of interest WinProc( )
– e.g., for button’s BN_CLICKED notification ? Doesn't return until message has been processed
• ON_BN_CLICKED (ID, OnClickHandler) ? Parameters:
? Declare the handler functions in the .h file – Handle of destination window
? Write the handler functions in .cpp file, e.g. – ID of message to send
void CMyProgView::OnClickHandler() – wParam and lParam values containing message data, if
{ // code goes here }; any
4
Button Controls Graphical Push Buttons
? Some Styles: BS_PUSHBUTTON, ? One way: use CBitmapButton class
BS_RADIOBUTTON, BS_CHECKBOX, ? Assume we have a CBitmapButton object called
BS_OWNERDRAW, BS_GROUPBOX, etc. m_bitmapbut and two bitmaps in the resources:
? Button notification codes: – IDB_BMUP: “up state” bitmap
– BN_CLICK, BN_DOUBLECLICK – IDB_BMDOWN: “down state” bitmap