![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Listing 3.1 HTMLViewView.h and HTMLViewView.cpp // HTMLViewView.h : interface of the CHTMLViewView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_HTMLVIEWVIEW_H__093DDFC9_9FB2_11D1_887F_D42B07C10710__INCLUDED_) #define AFX_HTMLVIEWVIEW_H__093DDFC9_9FB2_11D1_887F_D42B07C10710__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CHTMLViewView : public CHtmlView { protected: // create from serialization only CHTMLViewView(); DECLARE_DYNCREATE(CHTMLViewView) // Attributes public: CHTMLViewDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CHTMLViewView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual void OnInitialUpdate(); // called first time after construct virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL // Implementation public: virtual ~CHTMLViewView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CHTMLViewView) afx_msg void OnFileNavigate(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in HTMLViewView.cpp inline CHTMLViewDoc* CHTMLViewView::GetDocument() { return (CHTMLViewDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_HTMLVIEWVIEW_H__093DDFC9_9FB2_11D1_887F_D42B07C10710__INCLUDED_) // HTMLViewView.cpp : implementation of the CHTMLViewView class // #include stdafx.h #include HTMLView.h #include HTMLViewDoc.h #include HTMLViewView.h #include URLDlg.h #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView IMPLEMENT_DYNCREATE(CHTMLViewView, CHtmlView) BEGIN_MESSAGE_MAP(CHTMLViewView, CHtmlView) //{{AFX_MSG_MAP(CHTMLViewView) ON_COMMAND(ID_FILE_NAVIGATE, OnFileNavigate) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CHtmlView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CHtmlView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CHtmlView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView construction/destruction CHTMLViewView::CHTMLViewView() { // TODO: add construction code here } CHTMLViewView::~CHTMLViewView() { } BOOL CHTMLViewView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CHtmlView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView drawing void CHTMLViewView::OnDraw(CDC* pDC) { CHTMLViewDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } void CHTMLViewView::OnInitialUpdate() { CHtmlView::OnInitialUpdate(); // TODO: This code navigates to a popular spot on the Web. // change the code to go where youd like. Navigate2(_T(http://www.microsoft.com/visualc/),NULL,NULL); } ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView printing BOOL CHTMLViewView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CHTMLViewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CHTMLViewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView diagnostics #ifdef _DEBUG void CHTMLViewView::AssertValid() const { CHtmlView::AssertValid(); } void CHTMLViewView::Dump(CDumpContext& dc) const { CHtmlView::Dump(dc); } CHTMLViewDoc* CHTMLViewView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHTMLViewDoc))); return (CHTMLViewDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CHTMLViewView message handlers void CHTMLViewView::OnFileNavigate() { URLDlg urldlg; int dlgvalue = urldlg.DoModal(); if(dlgvalue == IDOK){ Navigate(urldlg.m_URL); } // TODO: Add your command handler code here } That completes our work with HTML views. Lets move on to tree views. Tree ViewsTree views are based on tree controls, which let you list items in trees consisting of expandable nodes. If youve used the Windows Explorer, youre familiar with trees, because the Explorer uses trees to present the directory structure of a disk: as folders that contain other folders and files. You can collapse or expand folders with a click of the mouse. We can put tree views to use by creating a new program that supports them. Our program will support expandable nodes, bitmapped items, and will tell you what item in the tree youve clicked. Create a new MDI program named TreeView. In Step 6 of the AppWizard, select CTreeView as the base class for our view class. We add items to the tree viewa process called populatingin the OnInitialUpdate() function. Add that function to the view class now. Note the comment from the Visual C++ framework providing us with a tip here: void CTreeViewView::OnInitialUpdate() { CTreeView::OnInitialUpdate(); // TODO: You may populate your TreeView with items by directly accessing // its tree control through a call to GetTreeCtrl(). } The CTreeCtrl class functions appear in Table 3.3.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |