Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu đang bị lỗi
File tài liệu này hiện đang bị hỏng, chúng tôi đang cố gắng khắc phục.
Visual C++ and MFC Fundamentals programming phần 2 pdf
Nội dung xem thử
Mô tả chi tiết
Visual C++ and MFC Fundamentals Chapter 3: Windows Resources
© FunctionX, Inc. 77
12. On the Colors window, click the red color (3rd column, 2nd row).
13. Draw a reverse graphic with regard to the above dialog as follows:
14. Using the blue and the red colors, design the other diamonds as follows:
15. On the Colors window, click the white button
16. Using the Line Tool, draw four borders as follows:
Chapter 3: Windows Resources Visual C++ and MFC Fundamentals
78 © FunctionX, Inc.
17. Still using the Line Tool and the white color, draw new white lines as follows:
18. On the Image Editor toolbar, click the Fill Tool button .
19. Using the white, red, and blue colors, fill the icon as follows:
20. To create the smaller equivalent icon, on the main menu, click Image -> New Image
Type...
21. Make sure that 16x16, 16 Colors is selected and click OK.
22. Using the same above approach, design the icon as follows:
Visual C++ and MFC Fundamentals Chapter 3: Windows Resources
© FunctionX, Inc. 79
23. To save the icon, click the system Close button of the window that is displaying
the icon
24. Change the Exercise.cpp file as follows:
#include <afxwin.h>
#include "ResourceDlg.h"
class CResApp: public CWinApp
{
public:
BOOL InitInstance();
};
class CResFrame : public CFrameWnd
{
public:
CResFrame()
{
Create(NULL, "Resources Fundamentals");
}
};
BOOL CResApp::InitInstance()
{
m_pMainWnd = new CResFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CResApp theApp;
25. Test the application:
Chapter 3: Windows Resources Visual C++ and MFC Fundamentals
80 © FunctionX, Inc.
26. Close the window and return to MSVC
27. Create another icon identified as IDI_APP_ICO and design it follows:
28. Save All
3.3 Menu Fundamentals
3.3.1 Overview
A menu is a list of actions the user can perform on an application. Each item of the list is
primarily a word or a group of words on a line. Different menu items are used for
different reasons. For example, some menu items simply display a word or a group of
words. Some other items display a check mark. This indicates that the item toggles the
availability or disappearance of an object.
When a menu item is only meant to lead to a sub-menu, such a menu item is call a popup
menu. There are two types of popup menus. If the menu displays on top of a window,
which is the type of menu under the title bar, the word on top, which represents a
category of menu, is a popup menu. If a menu item is equipped with an arrow in its right
, which means the menu item has a submenu, such a
menu item is also a popup menu. Popup menus are used only to represent a submenu. No
inherent action is produced by clicking them, except that, when placed on top, such menu
items allow opening the submenu.
To create menus that belong to a group, menu items are separated by a horizontal line
called a separator. Separators are created differently in MSVC 6 and MSVC 7.
There are two primary types of menus in most applications: a main menu and a popup
menu.
3.3.2 The Main Menu
A menu is considered a main menu, when it carries most or all of the actions the user can
perform on an application. Such a menu is positioned on the top section of the main
Visual C++ and MFC Fundamentals Chapter 3: Windows Resources
© FunctionX, Inc. 81
window in which it is used. A main menu is divided in categories of items and each
category is represented by a word. Here is an example:
On the Visual Studio IDE, the categories of menus are File , Edit, View, Project, etc. To
use a menu, the user first clicks one of the words that displays on top. Upon clicking, the
menu expands and displays a list of items that belong to that category. Here is an
example where the View menu of WordPerfect was clicked and got expanded:
There is no strict rule on how a menu is organized, only suggestions. For example,
actions that are related to file processing, such as creating a new file, opening an existing
file, saving a file, printing the open file, or closing the file usually stay under a category
called File. In the same way, actions related to viewing things can be listed under a View
menu.
3.3.3 Main Menu Design
There are two ways you can create a main menu. You can use the Win32 approach in
which case you would create or open your .rc file and create a section as follows:
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New", IDM_FILENEW
MENUITEM "&Open", IDM_FILEOPEN
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_FILEEXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&About", IDM_HELPABOUT
END
END
Chapter 3: Windows Resources Visual C++ and MFC Fundamentals
82 © FunctionX, Inc.
If you create your file manually, you must also remember to create or edit the resource.h
file in order to specify an identifier for each menu. The alternative, which we will use, is
to "visually" create the menu in Visual Studio. When doing this, the studio itself would
update the resource.h as items are added or removed.
To create a menu, first add a resource of type Menu. To create a popup menu that would
display on top of the main menu, click the item on top and type the desired string in the
Caption field of the Properties window. Such a popup menu item would not use a specify
identifier.
To create a menu item, click the line under the popup menu, provide an identifier and a
caption. The arrow for the popup menu is readily available so you can use or ignore it.
Practical Learning: Creating a Main Menu
1. On the main menu, click Project -> Add Resource...
2. On the Add Resource dialog box, double-click Menu
3. In the Resource View, click IDR_MENU1 to select it and change its identifier to
IDR_MENU_RES
4. In the main window, click the top box (in MSVC .Net, it displays Type Here), type
Family and press Enter
5. Click the item under Family. Type Father and press Enter
6. Type Mother and press Enter
7. To add a separator, click the item under mother, type - and press Enter
8. Complete the menu as follows (remember to add the lower separator):
9. To move the Grand-Child item and position it under the lower separator, click and
hold the mouse on Grand-Child, then drag in the bottom direction until the selection
is in the desired position: