//--------------------------------------------------------------------------- 

#include <vcl.h> 
#pragma hdrstop 

#include <htmlhelp.h> 
#include "CMSDNHelp.h" 

//--------------------------------------------------------------------------- 
#pragma package(smart_init) 


__fastcall TCMSDNHelp::TCMSDNHelp() 
{ 
 HtmlHelp = NULL ; 
 helpWnd = NULL ; 
 ocxModule = NULL ; 
} 
//--------------------------------------------------------------------------- 

__fastcall TCMSDNHelp::~TCMSDNHelp() 
{ 
 if( ocxModule != NULL ) 
   FreeLibrary( ocxModule  ) ; 
} 
//--------------------------------------------------------------------------- 
bool __fastcall TCMSDNHelp::load() 
{ 
 if( ocxModule != NULL && HtmlHelp != NULL ) 
  return true ; 
 ocxModule = LoadLibrary( "hhctrl.ocx" ) ; 
 if( ocxModule == NULL ) 
  return false  ; 
 FARPROC p = GetProcAddress( ocxModule,  "HtmlHelpA" ) ; 
 if( p == NULL ) 
  return false  ; 
 HtmlHelp = (THtmlHelpFunc)p ; 
 return true ; 
} 
//--------------------------------------------------------------------------- 

bool __fastcall TCMSDNHelp::help( const AnsiString& keyWord, const AnsiString& fileName ) 
{ 
 if( load() == false ) 
  return false ; 
 const char* szHelpName = fileName.c_str() ; 
 if( keyWord.Length() == 0 ) 
 { 
  helpWnd = HtmlHelp( NULL, szHelpName,  HH_DISPLAY_TOPIC, NULL ) ; 
  if( helpWnd == NULL ) 
    return false ; 
  return true  ; 
 } 
 HH_AKLINK link; 
 link.cbStruct =     sizeof(HH_AKLINK) ; 
 link.fReserved =    FALSE ; 
 link.pszKeywords =  keyWord.c_str() ; 
 link.pszUrl =       NULL ; 
 link.pszMsgText =   NULL ; 
 link.pszMsgTitle =  NULL ; 
 link.pszWindow =    NULL ; 
 link.fIndexOnFail = TRUE ; 

//&link); 
 helpWnd = HtmlHelp( NULL, szHelpName, HH_KEYWORD_LOOKUP, (DWORD)&link); 
 if( helpWnd == NULL ) 
   return false ; 

  return true  ; 
} 

bool TCMSDNHelp::showChm( const AnsiString& fileName ) 
{ 
 if( load() == false ) 
  return false ; 
 helpWnd = HtmlHelp( NULL, fileName.c_str(),  HH_DISPLAY_TOPIC, NULL ) ; 
 if( helpWnd == NULL ) 
   return false ; 
 return true ; 
}