
- •The ministry of education and science of ukraine kharkiv national university of radio electronics
- •1. The Basics of Microsoft Foundation Classes
- •Mfc general information
- •A Framework of mfc-program
- •Creating the Application Class
- •Creating the Frame-Window Class
- •Declaring a Message Map and instantiation of application object global instance
- •Defining a Message Map
- •Messages and their processing in mfc-programs
- •Writing Message Map Functions
- •Message boxes and menus in mfc-programs
- •2. Dialog windows
- •2.1 Modal and modeless dialog windows
- •2.2 The control elements of dialog window
- •CListBox::AddString (lpctstr lpszItem ); // Call this member function to add a string (lpszItem) to a list box;
- •3. Additional control elements in mfc-programs. Working with icons, cursors, raster images
- •3.1 Additional control elements
- •Radio buttons
- •Afx_msg void cWnd::OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar ); afx_msg void cWnd::OnHScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Afx_msg void OnVScroll( uint nSbCode, uint nPos, cScrollBar* pScrollBar );
- •Working with icons, cursors, raster images
- •The icons and cursor registration
- •Icon and cursor loading
- •4. The elements of text processing in mfc
- •The redrawing problem decision
- •5. The Elements of working with graphics
- •5.1 The graphics functions.
- •Working with brushes
- •5.2 The mapping modes and output regions
- •6. Common control elements
- •Windows Common Controls
- •6.2 The toolbar using
- •On resizing, the message wm_size is sent and the standard handler OnSize() is called.
- •The working with Spins
- •The working with slider
- •To set the range (minimum and maximum positions) for the slider in a slider control use the following function:
- •The working with progress bar
- •The tree control using in mfc programs
- •Adding elements to the tree
- •The status bars usage
- •Bool cStatusBarCtrl::SetParts( int nParts, int* pWidths );
- •Tab controls using in mfc-programs
- •Int cTabCtrl::GetCurSel(); To Selects a tab in a tab control use SetCurSel() function:
- •Int cTabCtrl::SetCurSel( int nItem );
- •The property sheets and wizards
- •7. Thread multitasking and it’s implementation in mfc
- •7.1 The basic features of multitasking
- •7.2 The Synchronization
- •7.3 The working with semaphore
- •7. 4 The working with event object
- •8. The concept of Document view
- •8.1 Introduction to document conception
- •The control of documents storing
- •8.2 The dynamic creation of objects
- •The application framework creation
- •The main window and application classes creation
- •Listing 8.1 The example of main window class in Document / View concept
- •Listing 8.2 The example of document class in Document / View concept
- •8.3 The document framework creation
- •8.4 The initiation of application
- •8.5 The standard id’s, used in Document / View concept
- •9. The special types of menu and their implementation in mfc
- •9.1 The description of special menu styles
- •The mechanism to make changes in menus
- •9.2 The dynamic and floating menus implementation
- •CMenu::CreatePopupMenu
- •The example programs to work with dynamic menus
- •10. The system of help
- •10.1 The basic information on help structures
- •The call of help
- •The file of help
- •The Help file creating
- •The example of rtf file
- •10.2 The Help system including to the mfc-program
- •Parameters:
- •Return Values: If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
- •10.3 The handlers of help messages
- •The processing of help calls
- •Wm_commandhelp message processing
- •10.4 Wm_contextmenu message processing
- •11. Manipulating Device-Independent Bitmaps
- •11.1 The types of bitmap
- •11.2 The structures included to bitmap
- •Introducing the cDib Class
- •11.3 Programming the cDib Class
- •Loading a dib into Memory
- •Other cDib Member Functions
- •Creating ShowDib program
- •Modifying ShowDib's Resources
- •Adding Code to ShowDib
- •Examining the OnFileOpen() Function
- •Examining the OnDraw() Function
- •12. The elements of Database Programming
- •12.1 Understanding Database Concepts
- •Accessing a Database
- •12.2 Mfc odbc Classes
- •Registering the Database
- •Creating the Basic Employee Application
- •Creating the Database Display
- •Adding and Deleting Records
- •12.4 Sorting and Filtering
- •12.5 Odbc versus dao
- •13. Remote Automation
- •13.1 The introduction to Remote Automation
- •13.2 The Remote Automation Connection Manager and user components
- •13.3 Automation
- •Automation Clients
- •13.4 ActiveX
- •ActiveX Document Servers
- •ActiveX Document Containers
- •ActiveX Document Views
- •13.5 ActiveX Documents
- •ActiveX Controls
- •Interaction Between Controls with Windows and ActiveX Control Containers
- •13.6 Optimization of ActiveX Controls
- •13.7 Automation Servers
- •13.8 Connection Points
- •14. Microsoft DirectX and the main items of its using
- •14.2 The Component Object Model
- •IUnknown Interface
- •DirectX com Interfaces
- •DirectDraw Architecture
- •Other DirectDraw Features
- •Width and Pitch
- •14.5 Support for 3d Surfaces in DirectX
- •14.6 Direct3d Integration with DirectDraw
- •Direct3d Device Interface
- •Direct3d Texture Interface
- •The Basics of DirectDraw
- •Step 6: Writing to the Surface.The first half of the wm_timer message in ddex1 is devoted to writing to the back buffer, as shown in the following example:
- •Loading Bitmaps on the Back Buffer
- •Step 1: Creating the Palette. The ddex2 sample first loads the palette into a structure by using the following code:
- •Step 4: Flipping the Surfaces. Flipping surfaces in the ddex2 sample is essentially the same process as that in the first example. Blitting from an Off-Screen Surface
- •Step 1: Creating the Off-Screen Surfaces. The following code is added to the doInit function in ddex3 to create the two off-screen buffers:
- •Color Keys and Bitmap Animation
- •Dynamically Modifying Palettes
- •Optimizations and Customizations
- •Blitting with Color Fill
- •Determining the Capabilities of the Display Hardware
- •Storing Bitmaps in Display Memory
- •Triple Buffering
- •15. General information on OpenGl
- •15.1 Common information
- •Primitives and Commands
- •OpenGl Graphic Control
- •Execution Model
- •15.2 Basic OpenGl Operation
- •OpenGl Correctness Tips
- •15.3 OpenGl example program
- •Ph.D. Assosiate prof. Tsimbal Alexander m. System software, summary of lectures.
6.2 The toolbar using
The tool bar creation
Maybe, the most widely used common control is a toolbar. A Windows toolbar common control is a rectangular child window that contains one or more buttons. These buttons can display a bitmap image, a string, or both. When the user chooses a button, it sends a command message to the toolbar's owner window. Typically, the buttons in a toolbar correspond to items in the application's menu; they provide a more direct way for the user to access an application's commands.
The CToolBarCtrl class provides the functionality of the Windows toolbar common control. This control (and therefore the CToolBarCtrl class) is available only to programs running under Windows 95 and Windows NT version 3.51 and later.
CToolBarCtrl objects contain several important internal data structures: a list of button image bitmaps, a list of button label stings, and a list of TBBUTTON structures which associate an image and/or string with the position, style, state, and command ID of the button. Each of the elements of these data structures is referred to by a zero-based index. Before you can use a CToolBarCtrl object, you must set up these data structures. The list of strings can only be used for button labels; you cannot retrieve strings from the toolbar.
To use a CToolBarCtrl object, you will typically follow these steps:
Construct the CToolBarCtrl object.
Call Create to create the Windows toolbar common control and attach it to the CToolBarCtrl object.
If you want bitmap images for buttons, add the button bitmaps to the toolbar by calling AddBitmap. If you want string labels for buttons, add the strings to the toolbar by calling AddString and/or AddStrings.
Add button structures to the toolbar by calling AddButtons.
If you want tool tips for a toolbar button in an owner window that is not a CFrameWnd, you need to handle the TTN_NEEDTEXT messages in the toolbar's owner window as described in CToolBarCtrl: Handling Tool Tip Notifications. If the parent window of the toolbar is derived from CFrameWnd, tool tips are displayed without any extra effort from you because CFrameWnd provides a default handler.
The Create() function provides the creation of toolbar object:
BOOL CToolBarCtrl::Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
Parameters
dwStyle Specifies the toolbar control's style. Toolbars must always have the WS_CHILD style. In addition, you can specify any combination of toolbar styles and window styles as described under Remarks.
rect Specifies the toolbar control's size and position. (CRect object or a RECT structure)
pParentWnd Specifies the toolbar control's parent window. It must not be NULL.
nID Specifies the toolbar control's ID.
You construct a CToolBarCtrl in two steps. First call the constructor, then call Create, which creates the toolbar control and attaches it to the CToolBarCtrl object.
The toolbar control automatically sets the size and position of the toolbar window. The height is based on the height of the buttons in the toolbar. The width is the same as the width of the parent window's client area. The CCS_TOP and CCS_BOTTOM styles determine whether the toolbar is positioned along the top or bottom of the client area. By default, a toolbar has the CCS_TOP style.
Apply the following window styles to a toolbar control: WS_CHILD - Always, WS_VISIBLE - Usually, WS_DISABLED – Rarely.
Next, you may want to apply one or more of the common control styles:
CCS_ADJUSTABLE Allows toolbars to be customized by the user. If this style is used, the toolbar's owner window must handle the customization notification messages sent by the toolbar.
CCS_BOTTOM Causes the control to position itself at the bottom of the parent window's client area and sets the width to be the same as the parent window's width.
CCS_NODIVIDER Prevents a two-pixel highlight from being drawn at the top of the control.
CCS_NOHILITE Prevents a one-pixel highlight from being drawn at the top of the control.
CCS_NOMOVEY Causes the control to resize and move itself horizontally, but not vertically, in response to a WM_SIZE message. If the CCS_NORESIZE style is used, this style does not apply.
CCS_NOPARENTALIGN Prevents the control from automatically moving to the top or bottom of the parent window. Instead, the control keeps its position within the parent window despite changes to the size of the parent window. If the CCS_TOP or CCS_BOTTOM style is also used, the height is adjusted to the default, but the position and width remain unchanged.
CCS_NORESIZE Prevents the control from using the default width and height when setting its initial size or a new size. Instead, the control uses the width and height specified in the request for creation or sizing.
CCS_TOP Causes the control to position itself at the top of the parent window's client area and sets the width to be the same as the parent window's width. Toolbars have this style by default.
Finally, you may want to apply one or both of the following toolbar control styles to a toolbar control:
TBSTYLE_TOOLTIPS Causes the toolbar to create and manage a tool tip control. A tool tip is a small pop-up window that contains a line of text describing a toolbar button. It appears only when the user puts the cursor on a toolbar button and leaves it there for approximately one-half second. The tool tip is displayed near the cursor. If you use this style, you must handle tool tip notifications.
TBSTYLE_WRAPABLE Creates a toolbar control that can have multiple lines of buttons. Toolbar buttons can "wrap" to the next line when the toolbar becomes too narrow to include all buttons on the same line.
The toolbar, constructed after Create() call, isn’t yet initiated and can’t be used. To make that, it’s need to make two additional actions: At first, the buttons must be added, at second, you must add the image of every button of such toolbar. Also, the text label can be linked to the every image.
Adding button to the toolbar
The buttons are added by AddButtons() function:
BOOL CToolBarCtrl::AddButtons( int nNumButtons, LPTBBUTTON lpButtons );
Parameters:
nNumButtons Number of buttons to add.
lpButtons Address of an array of TBBUTTON structures that contains information about the buttons to add. There must be the same number of elements in the array as buttons specified by nNumButtons
The lpButtons pointer points to an array of TBBUTTON structures. Each TBBUTTON structure associates the button being added with the button's style, image and/or string, command ID, state, and user-defined data:
typedef struct _TBBUTTON {
int iBitmap; // zero-based index of button image
int idCommand; // command to be sent when button pressed
BYTE fsState; // button state--see below
BYTE fsStyle; // button style--see below
DWORD dwData; // application-defined value
int iString; // zero-based index of button label string
} TBBUTTON;
The members are as follows:
iBitmap Zero-based index of button image. NULL if no image for this button.
idCommand Command identifier associated with the button. This identifier is sent in a WM_COMMAND message when the button is chosen. If the fsStyle member has the TBSTYLE_SEP value, this member must be zero.
fsState Button state flags. It can be a combination of the values listed below:
TBSTATE_CHECKED The button has the TBSTYLE_CHECKED style and is being pressed.
TBSTATE_ENABLED The button accepts user input. A button that does not have this state does not accept user input and is grayed.
TBSTATE_HIDDEN The button is not visible and cannot receive user input.
TBSTATE_INDETERMINATE The button is grayed.
TBSTATE_PRESSED The button is being pressed.
TBSTATE_WRAP A line break follows the button. The button must also have the TBSTATE_ENABLED state.
fsStyle Button style. It can be a combination of the values listed below:
TBSTYLE_BUTTON Creates a standard push button.
TBSTYLE_CHECK Creates a button that toggles between the pressed and unpressed states each time the user clicks it. The button has a different background color when it is in the pressed state.
TBSTYLE_CHECKGROUP Creates a check button that stays pressed until another button in the group is pressed.
TBSTYLE_GROUP Creates a button that stays pressed until another button in the group is pressed.
TBSTYLE_SEP Creates a separator, providing a small gap between button groups. A button that has this style does not receive user input.
dwData User-defined data.
iString Zero-based index of the string to use as the button's label. NULL if there is no string for this button.
The image and/or string whose index you provide must have previously been added to the toolbar control's list using AddBitmap, AddString, and/or AddStrings.
Adding images to the toolbar
Adding images is provided by AddBitmap function. The image of button is a 16x15 pixels, the button size 24x22. To the toolbar there is linked only one image, which contains the images of all buttons. For example, six buttons has size 16x6 = 96 pixels. Default name of file to save the buttons images is TOOLBAR.BMP.
int CToolBarCtrl::AddBitmap( int nNumButtons, UINT nBitmapID );
int CToolBarCtrl::AddBitmap( int nNumButtons, CBitmap* pBitmap );
Return Value: Zero-based index of the first new image if successful; otherwise – 1.
Parameters:
nNumButtons Number of button images in the bitmap.
nBitmapID Resource identifier of the bitmap that contains the button image or images to add.
pBitmap Pointer to the CBitmap object that contains the button image or images to add.
Additional functions to work with toolbar
After the toolbar initiation, the size is set accordingly to the size of parent window. If to change the window size, the toolbar dimension will not change. That problem is decided by AutoSize() function:
void CToolBarCtrl::AutoSize( ); // Call this function to resize the entire toolbar control. You should call this function when the size of the parent window changes or when the size of the toolbar changes (such as when you set the button or bitmap size, or add strings).