VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets e In this section, we 'll talk a little bit of the document-view architecture e Learn to create and use menus and keyboard accelerators e Talk about command message handling in two dimensions o Use rich edit control for text editing o Use property sheet for setting edit options
VC++ Programming @ UESTC 1 Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets ⚫ In this section, we’ll talk a little bit of the document-view architecture ⚫ Learn to create and use menus and keyboard accelerators. ⚫ Talk about command message handling in two dimensions. ⚫ Use rich edit control for text editing. ⚫ Use property sheet for setting edit options
VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Class goals as the followings Understand document-view architecture and know how the document main frame window. view window. toolbar window. status bar window and menu talk to each other 2. Know how to make windows menu and floating pop-up menu 3. Use resource editor to add keyboard accelerators 4. Understand command routing system and command message handling 5. Use rich edit control to play with text fonts, etc 6. Know the usage of property sheets including the DDX
VC++ Programming @ UESTC 2 ⚫ Class Goals as the followings: 1. Understand document-view architecture and know how the document,main frame window, view window, toolbar window, status bar window and menu talk to each other. 2. Know how to make windows menu and floating pop-up menu. 3. Use resource editor to add keyboard accelerators. 4. Understand command routing system and command message handling. 5. Use rich edit control to play with text fonts,etc. 6. Know the usage of property sheets including the DDX. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming@UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Window structure Title Bar Menu bar oolbar window SDI Child View window Main wIndows Frame window Status bar window 3
VC++ Programming @ UESTC 3 Window Structure Title Bar Menu Bar Toolbar window View window Status bar window SDI Main Frame window Child windows Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets DOCUMENT-VIEW architecture The view window is just a child window inside the client area of the main frame window which is the window we ordinarily talk about o The title bar and menu bar belongs to the main frame window e The view window. the toolbar window and status bar window are inside the client area of the main frame window o The application framework provides a sophisticated routing system for the command messages
VC++ Programming @ UESTC 4 DOCUMENT-VIEW architecture The view window is just a child window inside the client area of the main frame window which is the window we ordinarily talk about. ⚫ The title bar and menu bar belongs to the main frame window. ⚫ The view window, the toolbar window and status bar window are inside the client area of the main frame window. ⚫ The application framework provides a sophisticated routing system for the command messages. . Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming@UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Document is the content of our application and the view is how we look at it For instance document is just like data in excel file and the views like different chart tables(row chart, Column chart, Pivot Chart, etc) based on that same data o The view's inherited GetDocument member function returns a pointer to the document object o The key is to separate data from how we look at them. It adds another layer in the ood world for easy organizing our work
VC++ Programming @ UESTC 5 ⚫ Document is the content of our application and the view is how we look at it. For instance, document is just like data in excel file and the views like different chart tables(Row chart, Column chart,PivotChart,etc) based on that same data. ⚫ The view’s inherited GetDocument member function returns a pointer to the document object. ⚫ The key is to separate data from how we look at them. It adds another layer in the OOD world for easy organizing our work. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Let's create a Single Document Interface(SDI application and add menus and keyboard accelerators Step One: create a SDI exe project Step two: create menu items Open resource editor Drag the empty box to the place you want to put and click the right mouse button then click the properties"item on the popup menu 3. Dont give a Id number for the first level menu item(let it be gray), make sure you check the box. Give a caption you like and put"&""inside a bracelet following the caption, then click Enterkey
VC++ Programming @ UESTC 6 ⚫ Let’s create a Single Document Interface (SDI) application and add menus and keyboard accelerators. ⚫ Step One: create a SDI exe project ⚫ Step two : create menu items 1. Open resource editor 2. Drag the empty box to the place you want to put and click the right mouse button then click the “properties” item on the popup menu. 3. Don’t give a ID number for the first level menu item(let it be gray), make sure you check the “Pop-up” box. Give a caption you like and put “&I” inside a bracelet following the caption, then click “Enter” key. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Step two: create menu items 4. The Pop-up option give you a chance to create a next level menu items. The&I' is the shortcut system the framework gives you. The Ctrl-I will activate the menu Item 5. Click the newly created top level menu item and right click the empty box under, click the"properties item and do the similar job as above except you give a id this time Uncheck thePop-up"option
VC++ Programming @ UESTC 7 ⚫ Step two : create menu items 4. The Pop-up option give you a chance to create a next level menu items. The “&I” is the shortcut system the framework gives you. The Ctrl-I will activate the menu item. 5. Click the newly created top level menu item and right click the empty box under, click the “properties” item and do the similar job as above except you give a ID this time. Uncheck the “Pop-up” option. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming@UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Step two: create menu items 6. This D will respond to user events inside your VC++ code. The ID's structure reflects the menu levels. like ID INSERT LINES LINE which is a three level submenu d 7. create another second level menu, dont give id this time and check the" Pop-up?"option. Now you can create a sub menu under this one 8. In this way you may create any level sub-menu as you like
VC++ Programming @ UESTC 8 ⚫ Step two : create menu items 6. This ID will respond to user events inside your VC++ code. The ID’s structure reflects the menu levels, like ID_INSERT_LINES_LINE which is a three level submenu ID. 7. create another second level menu , don’t give ID this time and check the “Pop-up” option. Now you can create a sub menu under this one. 8. In this way you may create any level sub-menu as you like. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Step three: create keyboard accelerators 1. Click the Accelerator--IDR MAINFRAME inside resource editor and you' ll see many IDs associated ith Keys Inside the right panel, right click your mouse and click the new accelerator"on the popup menu. You'lI see a popup Accel Properties window Choose a Id you may want to respond to Type a letter and choose any combination of modifiers Dont make the same accelerator for any two different user events 5. A accelerator does not have to be associated with a menu item. It connects the keystrokes with your responding VC++ codes
VC++ Programming @ UESTC 9 ⚫ Step three: create keyboard accelerators 1. Click the Accelerator--IDR_MAINFRAME inside resource editor and you’ll see many IDs associated with Keys. 2. Inside the right panel, right click your mouse and click the “new accelerator” on the popup menu. You’ll see a popup “Accel Properties” window. 3. Choose a ID you may want to respond to. 4. Type a letter and choose any combination of modifiers. Don’t make the same accelerator for any two different user events. 5. A accelerator does not have to be associated with a menu item. It connects the keystrokes with your responding VC++ codes. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets
VC++ Programming@UESTC Chapter 12 Menus, Keyboard Accelerators, the rich Edit Control and Property sheets Command Message Handling The Id connects the menu items to the message handling. Make menu items first, then map the associated Id to the application Use Class wizard to add command message handlers in view class Step One: Use the framework to make your life easier Choose the view class under the"Class Name 2. Select Objects ID you want to respond 3. Choose"COMMAND inside"Messages, panel and you' ll see a popup dialog window 4. Click Enter", and go to view class"*. h?and"*.cpp?to see what's added there Step two: add codes inside view class to do the real work 0
VC++ Programming @ UESTC 10 ⚫ Command Message Handling The ID connects the menu items to the message handling. Make menu items first, then map the associated ID to the application. Use ClassWizard to add command message handlers in view class. Step One: Use the framework to make your life easier 1. Choose the view class under the “Class Name”; 2. Select Object’s ID you want to respond; 3. Choose “COMMAND” inside “Messages” panel and you’ll see a popup dialog window; 4. Click “Enter”, and go to view class “*.h” and “*.cpp” to see what’s added there. Step two: add codes inside view class to do the real work. Chapter 12 Menus, Keyboard Accelerators, the RichEdit Control and Property Sheets