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


/* 
  
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. 
 
*/ 
 
/************************************************************************* 
* 
* LIBMAIN.C 
* DLL Entry and help window management routines.      
* 
* Author: Paul E. Kissel 
* 
**************************************************************************/ 
 
/************************************* 
* 
*  System Includes 
* 
**************************************/ 
#include <windows.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <ctype.h> 
 
 
/************************************* 
* 
*  Custom Includes 
* 
**************************************/ 
#include "twinhelp.h" 
#include "twhlprc.h" 
#include "general.h" 
#include "msgbox.h" 
#include "winmem.h" 
#include "globals.h" 
#include "wndlist.h" 
#include "helpapi.h" 
#include "btnbar.h" 
#include "inifile.h" 
#include "wndpos.h" 
#include "hlpfile.h" 
 
 
/************************************* 
* 
*  Private Defines 
* 
**************************************/ 
 
/*  
** Window class name for all real/visible help windows. 
*/ 
#define MS_WINDOC_CLASS   "MS_WINDOC" 
 
 
/************************************* 
* 
*  Function Prototypes 
* 
**************************************/ 
 
BOOL WINAPI DllEntryPoint( HINSTANCE hLibInst, DWORD fdwReason,	LPVOID lpvReserved ); 
LRESULT CALLBACK ShellWndProc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ); 
 
 
/************************************* 
* 
*  LibMain() 
* 
**************************************/ 
 
BOOL WINAPI DllEntryPoint 
( 
  HINSTANCE hLibInst,	  /* Handle to DLL module. */ 
  DWORD fdwReason,	    /* Reason for calling function. */ 
  LPVOID lpvReserved 	  /* Reserved. */ 
) 
{ 
  ATOM ReturnValue;  
  WNDCLASS wndclass; 
   
 
  /* LoadLibrary().*/ 
  if( fdwReason == DLL_PROCESS_ATTACH ) 
  {  
    /* Save instance of library. */  
    SetLibInst( hLibInst ); 
   
    /* Register special help messages. */ 
    SetWINHELPMsg( RegisterWindowMessage( MSWIN_HELP_MSG_STRING ) ); 
 
    /*  
    ** Register the window class for the visible main help window. 
    */ 
    wndclass.style         = 0 ; 
    wndclass.lpfnWndProc   = MainWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    wndclass.hIcon         = LoadIcon( hLibInst, MAIN_ICON ); 
    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ; 
    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
    wndclass.lpszMenuName  = 0; 
    wndclass.lpszClassName = MS_WINDOC_CLASS ; 
   
    ReturnValue = RegisterClass (&wndclass) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
 
    /*  
    ** Register the window class for the visible topic help window that 
    ** is scrollable. 
    */ 
    wndclass.style         = CS_BYTEALIGNWINDOW | CS_OWNDC; 
    wndclass.lpfnWndProc   = TopicWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    /*  
    ** If you use the Arrow cursor for the class, windows restores 
    ** that for every mouse move and movement will be jerky. 
    ** So Class Cursor is made NULL and we will manually set the  
    ** cursor ourselves on mouse moves.  
    */ 
    wndclass.hCursor       = (HCURSOR) NULL; 
 
    wndclass.hIcon         = (HICON) NULL; 
    wndclass.hbrBackground = NULL; 
    wndclass.lpszMenuName  = NULL; 
    wndclass.lpszClassName = JUMPSCROLL_CLASS; 
 
    ReturnValue = RegisterClass ( &wndclass ) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
 
    /*  
    ** Register the window class for the visible topic help window that 
    ** is not scrollable. 
    */ 
    wndclass.style         = CS_BYTEALIGNWINDOW | CS_OWNDC; 
    wndclass.lpfnWndProc   = NoScrollTopicWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    /*  
    ** If you use the Arrow cursor for the class, windows restores 
    ** that for every mouse move and movement will be jerky. 
    ** So Class Cursor is made NULL and we will manually set the  
    ** cursor ourselves on mouse moves.  
    */ 
    wndclass.hCursor       = (HCURSOR) NULL; 
 
    wndclass.hIcon         = (HICON) NULL; 
    wndclass.hbrBackground = NULL; 
    wndclass.lpszMenuName  = NULL; 
    wndclass.lpszClassName = JUMPNOSCROLL_CLASS; 
 
    ReturnValue = RegisterClass ( &wndclass ) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
 
 
    /*  
    ** Register the window class for the visible popup help window. 
    */ 
    wndclass.style         = CS_BYTEALIGNWINDOW | CS_OWNDC; 
    wndclass.lpfnWndProc   = PopupWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    /*  
    ** If you use the Arrow cursor for the class, windows restores 
    ** that for every mouse move and movement will be jerky. 
    ** So Class Cursor is made NULL and we will manually set the  
    ** cursor ourselves on mouse moves.  
    */ 
    wndclass.hCursor       = (HCURSOR)NULL; 
 
    wndclass.hIcon         = (HICON)NULL; 
    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
    wndclass.lpszMenuName  = NULL; 
    wndclass.lpszClassName = POPUP_CLASS; 
 
    ReturnValue = RegisterClass ( &wndclass ) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
 
    /*  
    ** Register the window class for the visible main secondary help window. 
    */ 
    wndclass.style         = 0 ; 
    wndclass.lpfnWndProc   = MainSecWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    wndclass.hIcon         = LoadIcon( hLibInst, MAIN_ICON ); 
    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ; 
    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
    wndclass.lpszMenuName  = NULL ; 
    wndclass.lpszClassName = MAINSEC_CLASS ; 
   
    ReturnValue = RegisterClass (&wndclass) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
 
    /*  
    ** Register the window class for the visible secondary window's 
    ** topic help window that is scrollable. 
    */ 
    wndclass.style         = CS_BYTEALIGNWINDOW | CS_OWNDC; 
    wndclass.lpfnWndProc   = TopicSecWndProc ; 
    wndclass.cbClsExtra    = 0 ; 
    wndclass.cbWndExtra    = sizeof( HGLOBAL ); 
    wndclass.hInstance     = hLibInst; 
    /*  
    ** If you use the Arrow cursor for the class, windows restores 
    ** that for every mouse move and movement will be jerky. 
    ** So Class Cursor is made NULL and we will manually set the  
    ** cursor ourselves on mouse moves.  
    */ 
    wndclass.hCursor       = (HCURSOR) NULL; 
 
    wndclass.hIcon         = (HICON) NULL; 
    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); 
    wndclass.lpszMenuName  = NULL; 
    wndclass.lpszClassName = TOPICSEC_CLASS; 
 
    ReturnValue = RegisterClass ( &wndclass ) ; 
   
    /* return 1 = success; 0 = fail */ 
    if( ReturnValue == 0 ) return(FALSE); 
 
    /* Register the button bar's class. */ 
    if( ! RegisterButtonBarClass( GetLibInst() ) ) return(FALSE); 
 
    /* Build hash map table one time. */ 
    BuildContextHashMapTable(); 
 
    /* Success. */ 
    return(TRUE); 
  } 
 
  /* All other messages pass. */ 
  else 
  { 
    return( TRUE ); 
  } 
} 
 
 
/*********************************************** 
* 
*  Launcher wants to open a help window. 
* 
************************************************/ 
BOOL __declspec(dllexport) OpenHelpWindow( HWND hOwnerWnd, LPSTR szHelpFilePath ) 
{ 
  HWND hHelpWnd; 
 
  /* Create a main help window. */ 
  hHelpWnd = CreateWindow  
              ( 
                (LPSTR) MS_WINDOC_CLASS, 
                (LPSTR) NULL, 
                WS_OVERLAPPEDWINDOW, 
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
                NULL,  
                NULL,  
                GetLibInst(),  
                (void *) (HWND *) &hOwnerWnd 
              ); 
 
  if( !hHelpWnd ) 
  { 
    /* Cannot create the help window. */  
    MsgBox( GetLibInst(), hOwnerWnd, IDS_ERRORTITLE, IDS_WINDOWCREATE, MB_ICONHAND | MB_OK ); 
    return -1; 
  } 
 
  /* Show window. */ 
  ShowWindow ( hHelpWnd, SW_SHOW ) ; 
  UpdateWindow ( hHelpWnd ) ; 
 
  /* Show the help file's default topic. */ 
  SendMessage( hHelpWnd, PRIVMSG_HELP_CONTENTS, 0, (LPARAM) (char *) szHelpFilePath );  
 
  /* Success. */   
  return( TRUE ); 
}