home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / internet / mfcie / mfcievw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  7.5 KB  |  304 lines

  1. // This is part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. //
  11. // mfcieVw.cpp : implementation of the CMfcieView class
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "mfcie.h"
  16. #include "MainFrm.h"
  17.  
  18. #include "mfcieDoc.h"
  19. #include "mfcieVw.h"
  20.  
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMfcieView
  29.  
  30. IMPLEMENT_DYNCREATE(CMfcieView, CHtmlView)
  31.  
  32. BEGIN_MESSAGE_MAP(CMfcieView, CHtmlView)
  33.     //{{AFX_MSG_MAP(CMfcieView)
  34.     ON_COMMAND(ID_GO_BACK, OnGoBack)
  35.     ON_COMMAND(ID_GO_FORWARD, OnGoForward)
  36.     ON_COMMAND(ID_GO_SEARCH_THE_WEB, OnGoSearchTheWeb)
  37.     ON_COMMAND(ID_GO_START_PAGE, OnGoStartPage)
  38.     ON_COMMAND(ID_VIEW_STOP, OnViewStop)
  39.     ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
  40.     ON_COMMAND(ID_HELP_WEB_TUTORIAL, OnHelpWebTutorial)
  41.     ON_COMMAND(ID_HELP_ONLINE_SUPPORT, OnHelpOnlineSupport)
  42.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_FREE_STUFF, OnHelpMicrosoftOnTheWebFreeStuff)
  43.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_FREQUENTLY_ASKED_QUESTIONS, OnHelpMicrosoftOnTheWebFrequentlyAskedQuestions)
  44.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_GET_FASTER_INTERNET_ACCESS, OnHelpMicrosoftOnTheWebGetFasterInternetAccess)
  45.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_MICROSOFT_HOME_PAGE, OnHelpMicrosoftOnTheWebMicrosoftHomePage)
  46.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_SEARCH_THE_WEB, OnHelpMicrosoftOnTheWebSearchTheWeb)
  47.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_SEND_FEEDBACK, OnHelpMicrosoftOnTheWebSendFeedback)
  48.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_INTERNET_START_PAGE, OnHelpMicrosoftOnTheWebInternetStartPage)
  49.     ON_COMMAND(ID_HELP_MICROSOFT_ON_THE_WEB_BEST_OF_THE_WEB, OnHelpMicrosoftOnTheWebBestOfTheWeb)
  50.     ON_COMMAND(ID_VIEW_FONTS_LARGEST, OnViewFontsLargest)
  51.     ON_COMMAND(ID_VIEW_FONTS_LARGE, OnViewFontsLarge)
  52.     ON_COMMAND(ID_VIEW_FONTS_MEDIUM, OnViewFontsMedium)
  53.     ON_COMMAND(ID_VIEW_FONTS_SMALL, OnViewFontsSmall)
  54.     ON_COMMAND(ID_VIEW_FONTS_SMALLEST, OnViewFontsSmallest)
  55.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMfcieView construction/destruction
  61.  
  62. CMfcieView::CMfcieView()
  63. {
  64. }
  65.  
  66. CMfcieView::~CMfcieView()
  67. {
  68. }
  69.  
  70. BOOL CMfcieView::PreCreateWindow(CREATESTRUCT& cs)
  71. {
  72.     cs.lpszClass = AfxRegisterWndClass(0);
  73.     return CView::PreCreateWindow(cs);
  74. }
  75.  
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CMfcieView drawing
  78.  
  79. void CMfcieView::OnDraw(CDC* pDC)
  80. {
  81.     CMfcieDoc* pDoc = GetDocument();
  82.     ASSERT_VALID(pDoc);
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CMfcieView diagnostics
  87.  
  88. #ifdef _DEBUG
  89. void CMfcieView::AssertValid() const
  90. {
  91.     CView::AssertValid();
  92. }
  93.  
  94. void CMfcieView::Dump(CDumpContext& dc) const
  95. {
  96.     CView::Dump(dc);
  97. }
  98.  
  99. CMfcieDoc* CMfcieView::GetDocument() // non-debug version is inline
  100. {
  101.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcieDoc)));
  102.     return (CMfcieDoc*)m_pDocument;
  103. }
  104. #endif //_DEBUG
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CMfcieView message handlers
  108.  
  109. void CMfcieView::OnTitleChange(LPCTSTR lpszText)
  110. {
  111.     // this will change the main frame's title bar
  112.     if (m_pDocument != NULL)
  113.         m_pDocument->SetTitle(lpszText);
  114. }
  115.  
  116. void CMfcieView::OnDocumentComplete(LPCTSTR lpszUrl)
  117. {
  118.     // make sure the main frame has the new URL.  This call also stops the animation
  119.     ((CMainFrame*)GetParentFrame())->SetAddress(lpszUrl);
  120. }
  121.  
  122. void CMfcieView::OnInitialUpdate()
  123. {
  124.     // Go to the home page initially
  125.     CHtmlView::OnInitialUpdate();
  126.     GoHome();
  127. }
  128.  
  129. void CMfcieView::OnBeforeNavigate2(LPCTSTR /*lpszURL*/, DWORD /*nFlags*/,
  130.     LPCTSTR /*lpszTargetFrameName*/, CByteArray& /*baPostedData*/,
  131.     LPCTSTR /*lpszHeaders*/, BOOL* /*pbCancel*/)
  132. {
  133.     // start the animation so that is plays while the new page is being loaded
  134.     ((CMainFrame*)GetParentFrame())->StartAnimation();
  135. }
  136.  
  137. // these are all simple one-liners to do simple controlling of the browser
  138. void CMfcieView::OnGoBack()
  139. {
  140.     GoBack();
  141. }
  142.  
  143. void CMfcieView::OnGoForward()
  144. {
  145.     GoForward();
  146. }
  147.  
  148. void CMfcieView::OnGoSearchTheWeb()
  149. {
  150.     GoSearch();
  151. }
  152.  
  153. void CMfcieView::OnGoStartPage()
  154. {
  155.     GoHome();
  156. }
  157.  
  158. void CMfcieView::OnViewStop()
  159. {
  160.     Stop();
  161. }
  162.  
  163. void CMfcieView::OnViewRefresh()
  164. {
  165.     Refresh();
  166. }
  167.  
  168. // these all go to specific web pages, just like Internet Explorer's help menu
  169. void CMfcieView::OnHelpWebTutorial()
  170. {
  171.     CString str;
  172.  
  173.     str.LoadString(IDS_WEB_TUTORIAL);
  174.     Navigate2(str, 0, NULL);
  175. }
  176.  
  177. void CMfcieView::OnHelpOnlineSupport()
  178. {
  179.     CString str;
  180.  
  181.     str.LoadString(IDS_ONLINE_SUPPORT);
  182.     Navigate2(str, 0, NULL);
  183. }
  184.  
  185. void CMfcieView::OnHelpMicrosoftOnTheWebBestOfTheWeb()
  186. {
  187.     CString str;
  188.  
  189.     str.LoadString(IDS_BEST_OF_THE_WEB);
  190.     Navigate2(str, 0, NULL);
  191. }
  192.  
  193. void CMfcieView::OnHelpMicrosoftOnTheWebFreeStuff()
  194. {
  195.     CString str;
  196.  
  197.     str.LoadString(IDS_FREE_STUFF);
  198.     Navigate2(str, 0, NULL);
  199. }
  200.  
  201. void CMfcieView::OnHelpMicrosoftOnTheWebFrequentlyAskedQuestions()
  202. {
  203.     CString str;
  204.  
  205.     str.LoadString(IDS_FREQUENTLY_ASKED_QUESTIONS);
  206.     Navigate2(str, 0, NULL);
  207. }
  208.  
  209. void CMfcieView::OnHelpMicrosoftOnTheWebGetFasterInternetAccess()
  210. {
  211.     CString str;
  212.  
  213.     str.LoadString(IDS_GET_FASTER_INTERNET_ACCESS);
  214.     Navigate2(str, 0, NULL);
  215. }
  216.  
  217. void CMfcieView::OnHelpMicrosoftOnTheWebMicrosoftHomePage()
  218. {
  219.     CString str;
  220.  
  221.     str.LoadString(IDS_MICROSOFT_HOME_PAGE);
  222.     Navigate2(str, 0, NULL);
  223. }
  224.  
  225. void CMfcieView::OnHelpMicrosoftOnTheWebSearchTheWeb()
  226. {
  227.     CString str;
  228.  
  229.     str.LoadString(IDS_SEARCH_THE_WEB);
  230.     Navigate2(str, 0, NULL);
  231. }
  232.  
  233. void CMfcieView::OnHelpMicrosoftOnTheWebSendFeedback()
  234. {
  235.     CString str;
  236.  
  237.     str.LoadString(IDS_SEND_FEEDBACK);
  238.     Navigate2(str, 0, NULL);
  239. }
  240.  
  241. void CMfcieView::OnHelpMicrosoftOnTheWebInternetStartPage()
  242. {
  243.     CString str;
  244.  
  245.     str.LoadString(IDS_INTERNET_START_PAGE);
  246.     Navigate2(str, 0, NULL);
  247. }
  248.  
  249. // these functions control the font size.  There is no explicit command in the
  250. // CHtmlView class to do this, but we can do it by using the ExecWB() function.
  251. void CMfcieView::OnViewFontsLargest()
  252. {
  253.     COleVariant vaZoomFactor(4l);
  254.  
  255.     ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
  256.            &vaZoomFactor, NULL);
  257. }
  258.  
  259. void CMfcieView::OnViewFontsLarge()
  260. {
  261.     COleVariant vaZoomFactor(3l);
  262.  
  263.     ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
  264.            &vaZoomFactor, NULL);
  265. }
  266.  
  267. void CMfcieView::OnViewFontsMedium()
  268. {
  269.     COleVariant vaZoomFactor(2l);
  270.  
  271.     ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
  272.            &vaZoomFactor, NULL);
  273. }
  274.  
  275. void CMfcieView::OnViewFontsSmall()
  276. {
  277.     COleVariant vaZoomFactor(1l);
  278.  
  279.     ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
  280.            &vaZoomFactor, NULL);
  281. }
  282.  
  283. void CMfcieView::OnViewFontsSmallest()
  284. {
  285.     COleVariant vaZoomFactor(0l);
  286.  
  287.     ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
  288.            &vaZoomFactor, NULL);
  289. }
  290.  
  291. // This demonstrates how we can use the Navigate2() function to load local files
  292. // including local HTML pages, GIFs, AIFF files, etc.
  293. void CMfcieView::OnFileOpen()
  294. {
  295.     CString str;
  296.  
  297.     str.LoadString(IDS_FILETYPES);
  298.  
  299.     CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, str);
  300.  
  301.     if(fileDlg.DoModal() == IDOK)
  302.         Navigate2(fileDlg.GetPathName(), 0, NULL);
  303. }
  304.