This step adds new menu items for Record|Delete Records and Record|Requery and removes the Window|New Window menu item.
Open the DbQuery project resources (DbQuery.rc).
(To open resources in Visual Studio, select View|Resource View. Right click on DbQuery.rc and select Properties.)
Expand Menu in the resource tree and double-click IDR_DBQUERTYPE.
The IDR_DBQUERTYPE menu resource appears in a resource edit view.
Click View in the menu resource.
Right click and select <Insert New>.
A blank menu item is inserted.
Right click on the newly inserted item and select Properties.
Type &Record in the Caption field.
Press Enter.
Double-click the empty menu item under Record in the menu resource edit view.
Provide a unique ID (ID_RECORD_DELETERECORDS) to the menu item.
Type &Delete Records in the Caption field and Delete selected records\nDelete Records for the Prompt.
Press Enter.
Click on the empty menu item under Record in the menu resource edit view.
Right click and select Insert New.
Double click the newly inserted item.
Provide a unique ID (ID_RECORD_REQUERY) to the menu item.
Type &Requery in the Caption field and Requery result set.\nRequery for the Prompt.
Press Enter.
Click Window in the menu resource.
The Window menu opens.
Click New Window.
Press <Delete> to remove this menu item.
Close and save the resource file.
Select Class View from the View menu.
Select CDbQueryView for the Class name.
Right click CDbQueryView and select Properties.
Click the Events icon, then expand ID_RECORD_REQUERY.
Double-click the COMMAND field and pull down the combo box.
Select <Add> OnRecordRequery from the drop down list.
The source file is opened in the editor and the OnRecordRequery() function is added.
Similarly, add an update handler for the menu item.
Replace the following methods in DbQueryView.cpp:
/////////////////////////////////////////////////////////////// CDbQueryView message handlers void CDbQueryView::OnRecordRequery() { BOOL bLock = LockUpdate(); SetTopRow(1); MoveCurrentCell(GX_TOPLEFT); Requery(); LockUpdate(bLock); Redraw(); } void CDbQueryView::OnUpdateRecordRequery(CCmdUI* pCmdUI) { CRecordset* prs = OnGetRecordset(); // enable if opened and updatable && not last row pCmdUI->Enable(prs->IsOpen()); } |
Search for the message map declaration in DbQueryView.cpp.
Add the following menu handlers for the Delete menu item:
ON_COMMAND(ID_RECORD_DELETERECORDS, CGXRecordView::OnRecordDelete) ON_UPDATE_COMMAND_UI(ID_RECORD_DELETERECORDS, CGXRecordView::OnUpdateRecordDelete) |
The completed message map should look like this:
BEGIN_MESSAGE_MAP(CDbQueryView, CGXRecordView) //{{AFX_MSG_MAP(CDbQueryView) ON_COMMAND(ID_RECORD_REQUERY, OnRecordRequery) ON_UPDATE_COMMAND_UI(ID_RECORD_REQUERY, OnUpdateRecordRequery) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CGXRecordView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CGXRecordView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CGXRecordView::OnFilePrintPreview) ON_COMMAND(ID_RECORD_DELETERECORDS, CGXRecordView::OnRecordDelete) ON_UPDATE_COMMAND_UI(ID_RECORD_DELETERECORDS, CGXRecordView::OnUpdateRecordDelete) END_MESSAGE_MAP() |
Now, you can compile the application and run it.
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.