home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / READTUT / READTUT.CPP < prev    next >
C/C++ Source or Header  |  1997-01-09  |  6KB  |  175 lines

  1. /*+==========================================================================
  2.   File:      READTUT.CPP
  3.  
  4.   Summary:   Implementation file for the READTUT.EXE code sample
  5.              application. READTUT is a very simple Win32 EXE application
  6.              that uses the ReadTutorial function from the APPUTIL library
  7.              to launch a web browser to view an accompanying HTML tutorial
  8.              file.
  9.  
  10.              For a comprehensive tutorial code tour of READTUT's contents
  11.              and offerings see the accompanying READTUT.HTM file. For
  12.              more specific technical details on the internal workings see
  13.              the comments dispersed throughout the READTUT source code.
  14.  
  15.   Classes:   .
  16.  
  17.   Functions: WinMain.
  18.  
  19.   Origin:    12-18-96: atrent - Created for ActiveX Tutorial Samples.
  20.  
  21. ----------------------------------------------------------------------------
  22.   This file is part of the Microsoft ActiveX Tutorial Code Samples.
  23.  
  24.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  25.  
  26.   This source code is only intended as a supplement to Microsoft
  27.   Development Tools and/or on-line documentation.  See these other
  28.   materials for detailed information regarding Microsoft code samples.
  29.  
  30.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  31.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  32.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  33.   PARTICULAR PURPOSE.
  34. ==========================================================================+*/
  35.  
  36. /*---------------------------------------------------------------------------
  37.   We include WINDOWS.H for all Win32 applications.
  38.   We include OLE2.H because we will be calling the COM/OLE Libraries.
  39.   We include APPUTIL.H because we will be building this application using
  40.     the utility functions in the APPUTIL Library (ie, APPUTIL.LIB).
  41.   We include READTUT.H because it has resource definitions specific to
  42.     this tutorial application.
  43. ---------------------------------------------------------------------------*/
  44. #include <windows.h>
  45. #include <ole2.h>
  46. #include <apputil.h>
  47. #include "readtut.h"
  48.  
  49.  
  50. /*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  51.   Function: WinMain
  52.  
  53.   Summary:  The Windows main entry point function for this application.
  54.  
  55.   Args:     HINSTANCE hInstance,
  56.               Instance handle; a new one for each invocation of this app.
  57.             HINSTANCE hPrevInstance,
  58.               Instance handle of the previous instance. NULL in Win32.
  59.             LPSTR lpCmdLine,
  60.               Windows passes a pointer to the application's
  61.               invocation command line.
  62.             int nCmdShow)
  63.               Bits telling the show state of the application.
  64.  
  65.   Returns:  int
  66.               msg.wParam (upon exit of message loop).
  67.               FALSE if this instance couldn't initialize and run.
  68. F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
  69. extern "C" int PASCAL WinMain(
  70.                         HINSTANCE hInstance,
  71.                         HINSTANCE hPrevInstance,
  72.                         LPSTR pszCmdLine,
  73.                         int nCmdShow)
  74. {
  75.   int   iFail = FALSE;
  76.   LPSTR psz;
  77.   char  ch;
  78.  
  79.   if (SUCCEEDED(CoInitialize(NULL)))
  80.   {
  81.     // Show a message box saying that loading of tutorial is underway.
  82.     DelayBox(hInstance, MAKEINTRESOURCE(IDD_LOADING_MSG), NULL);
  83.  
  84.     /*--------------------------------------------------------------------
  85.       Walk down the command line looking for an HTML target. The first
  86.       non-whitespace character after whitespace is assumed to be the
  87.       beginning of the HTML target specification. This can be a fully
  88.       qualified internet URL or a path/filename. This is all done in ANSI
  89.       because pszCmdLine is in ANSI. Any command line switches are
  90.       skipped and ignored.
  91.     --------------------------------------------------------------------*/
  92.     psz = pszCmdLine;
  93.  
  94.     while (ch = *psz)
  95.     {
  96.       BOOL bStop = FALSE;
  97.  
  98.       switch (ch)
  99.       {
  100.         case '\t':
  101.         case '\n':
  102.         case '\r':
  103.         case ' ':
  104.           // Skip any white space.
  105.           psz = SkipAnsi(psz, TRUE);
  106.           continue;
  107.  
  108.         case '/':
  109.           // Handle '/' switches here. If '//' then assume it's a URL.
  110.           ch = *(++psz);
  111.           if ('/' == ch)
  112.           {
  113.             --psz;
  114.             bStop = TRUE;
  115.             break;
  116.           }
  117.           else
  118.           {
  119.             // If any '/' switches found skip to next white space.
  120.             psz = SkipAnsi(psz, FALSE);
  121.             continue;
  122.           }
  123.  
  124.         case '-':
  125.           // If any '-' switches found skip to next white space.
  126.           psz = SkipAnsi(psz, FALSE);
  127.           continue;
  128.  
  129.         default:
  130.           bStop = TRUE;
  131.           break;
  132.       }
  133.  
  134.       if (bStop)
  135.         break;
  136.  
  137.       psz++;
  138.     }
  139.  
  140.     if (0 == ch)
  141.     {
  142.       /*------------------------------------------------------------------
  143.         If the command line has no HTML target specified then assume a
  144.         file with name <thismodulename>.HTM in the same directory as this
  145.         executing EXE. In this case, the assumed file is READTUT.HTM. Call
  146.         the APPUTIL ReadTutorial utility function to Browse this HTML
  147.         file. If READTUT.EXE is renamed to TUTORIAL.EXE then the assumed
  148.         file to browse is TUTORIAL.HTM.
  149.       ------------------------------------------------------------------*/
  150.       ReadTutorial(hInstance, NULL, NULL);
  151.     }
  152.     else
  153.     {
  154.       // If the command line has an HTML target specified then use it
  155.       // to call the APPUTIL GoWeb utility function to Browse to the
  156.       // specified HTML web file.
  157.       GoWeb(hInstance, psz);
  158.     }
  159.  
  160.     // We're exiting this app so shut down the COM Library.
  161.     CoUninitialize();
  162.   }
  163.   else
  164.   {
  165.     // Show error message box if we can't initialize the COM libraries.
  166.     MessageBox(NULL,
  167.                TEXT(NOCOM_ERROR_STR),
  168.                TEXT(ERROR_TITLE_STR),
  169.                MB_OK | MB_ICONEXCLAMATION);
  170.     iFail = TRUE;
  171.   }
  172.  
  173.   return iFail;
  174. }
  175.