DAOVIEW: Database Browser

Click to open or copy the DAOVIEW project files.

DAOVIEW illustrates the use of many new features in MFC 4.0 to implement a moderately sophisticated database browser. It relies heavily on the new DAO classes to communicate with the Microsoft Jet database engine. It allows the user to view the database schema and data. It can also be used to create or modify stored SQL queries.

DAOVIEW uses the new CTreeView and CListView classes to create the same look as the Windows® 95 Explorer. Drag and drop of tables and queries is also implemented using OLE.

Using DAOVIEW is relatively straightforward. Simply click Open on the File menu to select a database (.mdb file) to view. Note that you can also use drag and drop from File Manager to open a database. We provide a sample database, Sampdata.mdb, in the same directory as the DAOVIEW sample. This database is a Microsoft Access 7.0-compatible database modeled on the Northwind Traders example that ships with Access.

Once the database has been opened, DAOVIEW will show you the components (tables, relations, and queries) in the form of a tree-view. At this point, you can see more information about a particular item of interest by clicking one of the "+" symbols shown in the tree.

Context-sensitive menus have been implemented for table and query objects. These can be used by right-clicking the item and selecting the operation from the pop-up menu. It is also possible to copy objects via drag and drop. This works for both tables and queries. The drop destination can be the current database or a database being viewed in another instance of DAOVIEW.

Note about CTRLEXT.H, CTRLEXT.CPP, and CTRLEXT.INL

Of particular interest in the DAOVIEW sample are the above three files. These files contain the classes CTreeCtrlEx, CListCtrlEx, and CTreeCursor, which facilitate manipulation of the tree and list controls. The CTreeCtrlEx is identical to the MFC class CTreeCtrl except that where the MFC class returns an HTREEITEM, CTreeCtrlEx returns a CTreeCursor.

The class CTreeCursor wraps an HTREEITEM and a pointer to a CTreeCtrl. It implements the majority of functions in CTreeCtrl, which are specific to an HTREEITEM. It is, in effect, an iterator.

Also of interest is CListCtrlEx, which is virtually identical to the MFC CListCtrl class but has a couple of new member functions that make insertion into the list control easier.

This sample demonstrates the following keywords:

AddItem; AfxGetApp; AfxGetMainWnd; AfxMessageBox; AfxOleInit; CArchive::Close; CArchive::IsStoring; CControlBar::EnableDocking; CControlBar::GetBarStyle; CControlBar::SetBarStyle; CDialog::DoModal; CDialog::OnInitDialog; CDocument::OnNewDocument; CDocument::OnOpenDocument; CFrameWnd::DockControlBar; CFrameWnd::EnableDocking; CFrameWnd::GetActiveDocument; CFrameWnd::OnCreateClient; CFrameWnd::SetActiveView; CMenu::GetSubMenu; CMenu::LoadMenu; CObject::AssertValid; CObject::Dump; CObject::Serialize; COleDataObject::GetGlobalData; COleDataObject::IsDataAvailable; COleDataSource::CacheGlobalData; COleDataSource::DoDragDrop; COleDropTarget::Register; CSplitterWnd::CreateStatic; CSplitterWnd::CreateView; CSplitterWnd::GetPane; CStatusBar::Create; CStatusBar::SetIndicators; CString::Find; CString::Format; CString::Left; CString::LoadString; CString::Mid; CToolBar::Create; CWinApp::AddDocTemplate; CWinApp::Enable3dControls; CWinApp::EnableShellOpen; CWinApp::InitInstance; CWinApp::LoadStdProfileSettings; CWinApp::RegisterShellFileTypes; CWnd::DoDataExchange; CWnd::GetDlgItem; CWnd::OnCreate; CWnd::PreCreateWindow; CWnd::SetFocus; CWnd::SetWindowText; CreateProcess; DeleteItem; DragAcceptFiles; GetCursorPos; GetDesktopWindow; GetParent; GetSysColor; GetVersion; MessageBox; RGB; RegisterClipboardFormat; ScreenToClient; SetBkColor; TrackPopupMenu; UpdateWindow; WinHelp; memset.