www.pudn.com > helpview.zip > launcher.c, change:1997-10-15,size:6703b


/* 
  
Copyright 1997 Willows Software, Inc.  
 
This library is free software; you can redistribute it and/or 
modify it under the terms of the GNU Library General Public License as 
published by the Free Software Foundation; either version 2 of the 
License, or (at your option) any later version. 
 
This library is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
Library General Public License for more details. 
 
You should have received a copy of the GNU Library General Public 
License along with this library; see the file COPYING.LIB.  If 
not, write to the Free Software Foundation, Inc., 675 Mass Ave, 
Cambridge, MA 02139, USA. 
 
*/ 
 
/******************************************************************* 
** 
**  File: Launcher.c 
** 
**  Purpose: Contains entry point for winhelp system. 
** 
**  Author: Paul E. Kissel 
** 
**  Date: Dec. 21, 1996 
** 
********************************************************************/ 
 
/*  
** System Includes.  
*/ 
#include <windows.h> 
#include <commdlg.h> 
#include <stdlib.h> 
#include <string.h> 
#include <dos.h> 
#include <direct.h> 
#include <ctype.h> 
 
 
/*  
** Private Includes.  
*/ 
#include "helpapi.h"        /* WinHelp() API defines. */ 
#include "twinhelp.h"       /* TWINHELP.DLL shared defines. */ 
 
 
/*  
** Private Defines.  
*/ 
 
#define NULL_CHAR '\0' 
 
/* Name of the help file viewer library. */ 
#define TWINHELP_DLL "TWINHELP.DLL" 
 
 
/*  
** Global variables.  
*/ 
 
/* Special help message. */ 
UINT MSG_WINHELP = 0;                  
 
 
/*  
** Private Functions.  
*/ 
 
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,	      
                    int nCmdShow ); 
LRESULT CALLBACK AppWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 
static BOOL LaunchViewer( HWND hWnd, LPSTR CmdLinePtr ); 
 
 
/******************************************************************* 
** 
**  Function: WinMain 
** 
**  Purpose: Entry point.  Creates a hidden launcher window. 
** 
**  Author: Paul E. Kissel 
** 
**  Date: Dec. 21, 1996 
** 
********************************************************************/ 
 
int WINAPI WinMain 
(  
  HINSTANCE hInstance,	 
  HINSTANCE hPrevInstance,  
  LPSTR lpszCmdLine,	      
  int  nCmdShow  
) 
{ 
  char      szClassName [] = "TWINHELP_LAUNCH"; /* Name of class. */ 
  WNDCLASS  WndClass ;                          /* Class structure. */ 
  HWND      hWnd;                               /* Window handle returned from CreateWindow(). */ 
  MSG       Msg ;                               /* Window Message. */ 
   
 
  /* First instance. */   
  if( !hPrevInstance )  
  { 
    /* Register the main hidden window. */ 
    WndClass.style         = 0; 
    WndClass.lpfnWndProc   = AppWndProc ; 
    WndClass.cbClsExtra    = 0 ; 
    WndClass.cbWndExtra    = 0 ; 
    WndClass.hInstance     = hInstance ; 
    WndClass.hIcon         = 0 ; 
    WndClass.hCursor       = 0; 
    WndClass.hbrBackground = 0; 
    WndClass.lpszMenuName  = 0; 
   
    WndClass.lpszClassName = (LPSTR) szClassName ; 
    RegisterClass( &WndClass ); 
   
    /* Register special help message. */ 
    MSG_WINHELP = RegisterWindowMessage( MSWIN_HELP_MSG_STRING );  
  } 
   
  /* Create the main window for non-HLP documents. */ 
  hWnd = CreateWindow  
         ( 
           (LPSTR) szClassName, 
           (LPSTR) NULL, 
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
           HWND_DESKTOP,  
           NULL,  
           hInstance,  
           (LPVOID) lpszCmdLine 
         ); 
   
  if( !hWnd ) 
  { 
    /* Window creation error. */ 
    MessageBox( NULL, (LPSTR)"Can't create a window!", (LPSTR)szClassName, MB_ICONHAND | MB_OK ); 
    return 0; 
  } 
 
  /* Enter the message loop. */ 
  while ( GetMessage ( &Msg, (HWND) NULL, 0, 0 )) 
  { 
    TranslateMessage (&Msg) ; 
    DispatchMessage (&Msg) ; 
  } 
 
  return( Msg.wParam ); 
}  
 
 
 
/******************************************************************* 
** 
**  Function: AppWndProc 
** 
**  Purpose: Processes all messages sent to the launcher's hidden  
**           window. 
** 
**           Launches a help window depending on if the program is 
**           started by the WinHelp() API function or the user. 
** 
**  Author: Paul E. Kissel 
** 
**  Date: Dec. 21, 1996 
** 
********************************************************************/ 
 
LRESULT CALLBACK AppWndProc 
(  
  HWND hWnd, 
  UINT uMsg,  
  WPARAM wParam,  
  LPARAM lParam  
) 
{ 
  CREATESTRUCT * lpCreateStruct;        
  LPSTR CmdLinePtr; 
 
 
  /*  
  ** Handle WinHelp special message WM_WINHELP. 
  ** The message is sent from the DLL to the 
  ** this hidden launcher window to tell the 
  ** launcher program to close down. 
  */ 
 
  if( uMsg == MSG_WINHELP ) 
  { 
    DestroyWindow( hWnd ); 
    return 0 ; 
  } 
 
 
  /*  
  ** Other Windows messages.  
  */ 
  switch (uMsg) 
  { 
    case WM_CREATE: 
    { 
      /* Get information of a window to open - info came from command-line. */ 
      lpCreateStruct = (CREATESTRUCT *) lParam;  
      CmdLinePtr = (LPSTR) lpCreateStruct->lpCreateParams; 
       
      /*  
      ** A user started the launcher and wants to view a 
      ** help file. 
      */ 
      if( !LaunchViewer( hWnd, CmdLinePtr ) )  
      { 
        /* Error. */ 
        return -1; 
      } 
       
      /* Successful. */ 
      return 0; 
    } 
 
 
    case WM_DESTROY: 
    { 
      PostQuitMessage(0); 
      return 0; 
    } 
  } 
   
  return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); 
} 
 
 
 
 
 
 
/******************************************************************* 
** 
**  Function: LaunchViewer 
** 
**  Purpose: Launches a help window for the user. 
** 
**  Author: Paul E. Kissel 
** 
**  Date: Dec. 21, 1996 
** 
********************************************************************/ 
 
static BOOL LaunchViewer( HWND hWnd, LPSTR CmdLinePtr ) 
{ 
  char szHelpFilePath[_MAX_PATH]; 
  BOOL bSuccess; 
   
  /* If no command-line argument supplied. */ 
  if( *CmdLinePtr == NULL_CHAR )  
  { 
    /* Get a help file to open. */ 
    bSuccess = GetHelpFileName( hWnd, szHelpFilePath ); 
     
    /* Error? */ 
    if( !bSuccess ) 
    { 
      return( FALSE ); 
    } 
  } 
  else 
  { 
    strcpy( szHelpFilePath, CmdLinePtr ); 
  } 
   
  /* Open the help window redirector window. */ 
  bSuccess = OpenHelpWindow( hWnd, szHelpFilePath ); 
 
  /* Error? */ 
  if( !bSuccess ) 
  { 
    return( FALSE ); 
  } 
   
  /* Success. */ 
  return( TRUE ); 
}