- •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.
9. The special types of menu and their implementation in mfc
9.1 The description of special menu styles
This section is devoted to the two stand-alone types of falling menus: dynamic and floating. They provide incredibly more possibilities on control and usage of menus in applications. But first of all, it’s need to have a view on important type of functions, presented in MFC – the handlers of menu changing, using which it’s possible to control the state of menu elements.
The handlers of changing define the status of menu elements display. In MFC-program, there is a special processing level, executing in time, then the falling menu is activated, but isn’t displayed on the display yet. Between these two events, there is called the set of handlers, switched to that menu. For every element of falling menu there is own handler of changing, defining is the selected element accessed or no. This handler can also set the label of selection with the name of element and change the text of title. The menu is displayed, when all the handlers are executed. Therefore, the handlers of changing are used for a definite state of falling menu on every it’s displaying.
There is the question: why we haven’t said anything about the handlers of changing earlier, because they are fundamental in working with MFC. Answer is simple; all the menus are linked to the in-built handlers of changing, containing in MFC. But on increasing of our program difficulty, we need control that process.
The mechanism to make changes in menus
On falling menu activation, the program is sent by WM_INITMENUPOPUP. That message is automatically intercepted by MFC and transformed to the call of corresponding handler of changing. As it was already said, every element of falling menu is linked to own handler of changing. If for some element it isn’t defined in the program, there is called the corresponding handler.
The standard handlers of changing, implemented in MFC, provide the simple but effective way to control the menu. Their work is organized in the following way: every element of falling menu, which is referenced by macro-command ON_COMMAND() in the messages map, is accessible, but the elements, which have no such macro commands have no access.
Any actions, made with menu, can be overfilled by actions of standard handlers of changing, because these handlers always executed the last. For example, if to declare any menu element as inaccessible, that declaration will not be active, if for the considered element the macro command ON_COMMAND is included to the messages map. In that case, the standard handler of changing automatically makes elements accessible, and there is no difference, what actions were fulfilled before.
The mechanism of automatic change making in the menu can be switched off. To make that, it’s need the variable m_pAutoMenuEnable of class CFrameWnd setting to FALSE. In that case, all the actions, provided in the program, will actually provided. That means, there is need to make the software engine to control the elements of menu (that way is used really seldom, because it’s more simple to implement own handlers).
The definition for handlers of changing
To define the own handler of changing is easy enough. It’s really need to make two steps. Firstly, you need for every processed menu element, to include the macro-command ON_UPDATE_COMMAND_UI() to the messages map. After you need to implement the handler. Macro ON_UPDATE_COMMAND_UI() has the following view:
ON_UPDATE_COMMAND_UI(ID, Handler)
Here, the ID is identity of processed menu element, Handler is the name of corresponding handler. Every handler of changing have to be of the following prototype:
afx_msg void Handler(CCmdUI *UIOb);
Here, the parameter UIOb is a pointer to CCmdUI class object.
CCmdUI is a special class, existing exclusively to support the mechanism of changing make in the menu. It isn’t part of MFC, so isn’t derived from CObject. It is used to define the types of parameters only. Class CCmdUI contains a number of functions to control the elements of menu. One of them is Enable() function. It’s has the following prototype:
void CCmdUI::Enable( BOOL bOn = TRUE );
Parameters: bOn TRUE to enable the item, FALSE to disable it.
Also, the functions of CCmdUi class provide the label of choice selection for menu items.
When, every of two actions are provided, the handler of changing will be call in place of standard handler. Remember, that you needn’t define the all handlers for menu item. Some of them are provided automatically.
The Dynamic menus
While the most of simple programs in Windows use the static menu definition, the complex programs often require dynamically to insert or to delete the elements of menu directly in time of application working on some conditions/ For example, in the text editors, there can be different commands, in dependence of file type. The menu, context of which can change in time of application work is usually called dynamic menu.
Adding elements to the menu
To add the elements in time of application execution there is used InsertItem() function with such prototypes:
BOOL CMenu::InsertMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
BOOL CMenu::InsertMenu(UINT nPosition, UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp );
Parameters
nPosition Specifies the menu item before which the new menu item is to be inserted. The nFlags parameter can be used to interpret nPosition in the following ways:
nFlags |
Interpretation of nPosition |
MF_BYCOMMAND |
Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set. |
MF_BYPOSITION |
Specifies that the parameter gives the position of the existing menu item. The first item is at position 0. If nPosition is –1, the new menu item is appended to the end of the menu. |
nFlags Specifies how nPosition is interpreted and specifies information about the state of the new menu item when it is added to the menu. For a list of the flags that may be set, see the AppendMenu member function. To specify more than one value, use the bitwise OR operator to combine them with the MF_BYCOMMAND or MF_BYPOSITION flag.
nIDNewItem Specifies either the command ID of the new menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of the pop-up menu. The nIDNewItem parameter is ignored (not needed) if nFlags is set to MF_SEPARATOR.
lpszNewItem Specifies the content of the new menu item. nFlags can be used to interpret lpszNewItem in the following ways:
nFlags |
Interpretation of lpszNewItem |
MF_OWNERDRAW |
Contains an application-supplied 32-bit value that the application can use to maintain additional data associated with the menu item. This 32-bit value is available to the application in the itemData member of the structure supplied by the WM_MEASUREITEM and WM_DRAWITEM messages. These messages are sent when the menu item is initially displayed or is changed. |
MF_STRING |
Contains a long pointer to a null-terminated string. This is the default interpretation. |
MF_SEPARATOR |
The lpszNewItem parameter is ignored (not needed). |
pBmp Points to a CBitmap object that will be used as the menu item.
To append the new element to the end of menu, there can be used CMenu::AppendMenu() function. It’s definition in MFC:
Начало формы
Конец формы
BOOL CMenu::AppendMenu( UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
BOOL CMenu::AppendMenu( UINT nFlags, UINT nIDNewItem, const CBitmap* pBmp );
Return Value : Nonzero if the function is successful; otherwise 0.
Parameters:
nFlags Specifies information about the state of the new menu item when it is added to the menu. It consists of one or more of the values listed in the Remarks section.
nIDNewItem Specifies either the command ID of the new menu item or, if nFlags is set to MF_POPUP, the menu handle (HMENU) of a pop-up menu. The nIDNewItem parameter is ignored (not needed) if nFlags is set to MF_SEPARATOR.
lpszNewItem Specifies the content of the new menu item. The nFlags parameter is used to interpret lpszNewItem in the following way:
nFlags |
Interpretation of lpszNewItem |
MF_OWNERDRAW |
Contains an application-supplied 32-bit value that the application can use to maintain additional data associated with the menu item. This 32-bit value is available to the application when it processes WM_MEASUREITEM and WM_DRAWITEM messages. The value is stored in the itemData member of the structure supplied with those messages. |
MF_STRING |
Contains a pointer to a null-terminated string. This is the default interpretation. |
MF_SEPARATOR |
The lpszNewItem parameter is ignored (not needed). |
pBmp Points to a CBitmap object that will be used as the menu item.
Appends a new item to the end of a menu. The application can specify the state of the menu item by setting values in nFlags. When nIDNewItem specifies a pop-up menu, it becomes part of the menu to which it is appended. If that menu is destroyed, the appended menu will also be destroyed. An appended menu should be detached from a CMenu object to avoid conflict. Note that MF_STRING and MF_OWNERDRAW are not valid for the bitmap version of AppendMenu.
The following list describes the flags that may be set in nFlags:
MF_CHECKED Acts as a toggle with MF_UNCHECKED to place the default check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the "check mark on" bitmap is displayed.
MF_UNCHECKED Acts as a toggle with MF_CHECKED to remove a check mark next to the item. When the application supplies check-mark bitmaps (see the SetMenuItemBitmaps member function), the "check mark off" bitmap is displayed.
MF_DISABLED Disables the menu item so that it cannot be selected but does not dim it.
MF_ENABLED Enables the menu item so that it can be selected and restores it from its dimmed state.
MF_GRAYED Disables the menu item so that it cannot be selected and dims it.
MF_MENUBARBREAK Places the item on a new line in static menus or in a new column in pop-up menus. The new pop-up menu column will be separated from the old column by a vertical dividing line.
MF_MENUBREAK Places the item on a new line in static menus or in a new column in pop-up menus. No dividing line is placed between the columns.
MF_OWNERDRAW Specifies that the item is an owner-draw item. When the menu is displayed for the first time, the window that owns the menu receives a WM_MEASUREITEM message, which retrieves the height and width of the menu item. The WM_DRAWITEM message is the one sent whenever the owner must update the visual appearance of the menu item. This option is not valid for a top-level menu item.
MF_POPUP Specifies that the menu item has a pop-up menu associated with it. The ID parameter specifies a handle to a pop-up menu that is to be associated with the item. This is used for adding either a top-level pop-up menu or a hierarchical pop-up menu to a pop-up menu item.
MF_SEPARATOR Draws a horizontal dividing line. Can only be used in a pop-up menu. This line cannot be dimmed, disabled, or highlighted. Other parameters are ignored.
MF_STRING Specifies that the menu item is a character string.
Each of the following groups lists flags that are mutually exclusive and cannot be used together:
MF_DISABLED, MF_ENABLED, and MF_GRAYED
MF_STRING, MF_OWNERDRAW, MF_SEPARATOR, and the bitmap version
MF_MENUBARBREAK and MF_MENUBREAK
MF_CHECKED and MF_UNCHECKED
Whenever a menu that resides in a window is changed (whether or not the window is displayed), the application should call CWnd::DrawMenuBar.
To delete the element from menu, there is used DeleteMenu() function. It has the following prototype:
Начало формы
Конец формы
BOOL CMenu::DeleteMenu( UINT nPosition, UINT nFlags );
Return Value : Nonzero if the function is successful; otherwise 0.
Parameters :
nPosition Specifies the menu item that is to be deleted, as determined by nFlags.
nFlags Is used to interpret nPosition in the following way:
nFlags |
Interpretation of nPosition |
MF_BYCOMMAND |
Specifies that the parameter gives the command ID of the existing menu item. This is the default if neither MF_BYCOMMAND nor MF_BYPOSITION is set. |
MF_BYPOSITION |
Specifies that the parameter gives the position of the existing menu item. The first item is at position 0. |
To find the number of elements in menu, use function:
UINT CMenu::GetMenuItemCount();
CMenu class contains a number of functions, to control menu. One of them – EnableMenuItem(), used to change the state of menu element (active / non-active). Really, the need of this function is seldom, because of standard handlers overfilling.
The constructor of CMenu class
To use the functions of CMenu class you need make by means of pointer to CMenu class object or object itself. Often of all, there is used the pointer to the main menu of application. To make that, it’s need to declare the object of CMenu class by the CMenu() constructor. This constructor creates an empty object, so before operations with object, the menu is linked to him.
As it’s known, often of all the main menu is defined in file of program resources. To control this menu dynamically (also all it’s submenus), there is need some kind of access to it. To have the pointer to main menu object, use GetMenu() function with such prototype:
CMenu* CWnd::GetMenu( ) const;
Return Value is identifier of menu. The value is NULL if CWnd has no menu. The return value is undefined if CWnd is a child window.
Having the pointer to main menu object you can easily get the pointers to the objects of submenu, containing in the main menu. That can be provided by GetSubMenu() function:
CMenu* CMenu::GetSubMenu( int nPos ) const;
Return Value: A pointer to a CMenu object whose m_hMenu member contains a handle to the pop-up menu if a pop-up menu exists at the given position; otherwise NULL. If a CMenu object does not exist, then a temporary one is created. The CMenu pointer returned should not be stored.
Parameters :
nPos Specifies the position of the pop-up menu contained in the menu. Position values start at 0 for the first menu item. The pop-up menu's identifier cannot be used in this function.
