-- callhelp.exw
-- ( Wolf's second "abberation" ) Nov.5/98
-- adds a call to Windows HELP,  with the assistance of Irv Mullins.
-- ( our old winhelp.e )

include win32lib.ew
without warning

integer winhlp_id

-- get an id for the WinHelpA routine in user32.dll.
 winhlp_id =
 registerw32Function( user32, "WinHelpA", {C_INT, C_INT, C_INT, C_INT}, C_INT )

-- where atom command is
-- = #0002  ..quits help ( HELP_QUIT ). in YOUR terminate procedure
-- = #0003  ..starts helpfile index ( HELP_INDEX )
-- = #0003  ..starts helpfile contents ( HELP_CONTENTS )
-- = #0004  ..starts help on help ( HELP_HELPONHELP )
-- these are the only ones I've tested ;- )
-- called like this..  LetsCallWinHelp( MYWINDOW, "myhelp.hlp", #0003, 0 )

procedure LetsCallWinHelp( atom hwnd,          -- handle of owner window
                           sequence FileName,  -- help file
                           atom command,       -- type of help needed
                           atom data )         -- value related to type of command
  atom file_ptr,  start
  -- how to pass messages to the help engine !!
  file_ptr = acquire_mem( 0, FileName )
  start = w32Func( winhlp_id,  {NULL,  file_ptr,  command,  data} )
  release_mem( file_ptr )
end procedure

-------- our main program.

constant SimpleWin = create( Window,  "HELP !",  0,  Default,  Default,  160,  80, 0 ), 
         ExitMenu = create( Menu,  "E&xit",  SimpleWin,  0,  0,  0,  0,  0 ),  
         ExitNow  = create( MenuItem, "Now!",  ExitMenu, 0, 0, 0, 0, 0 ), 
         HelpMenu = create( Menu, "&Help",  SimpleWin, 0, 0, 0, 0, 0 ), 
         HelpMe   = create( MenuItem, "Help",  HelpMenu, 0, 0, 0, 0, 0 )

procedure onMenu_Exit( atom self,  atom event,  sequence params )
-- close the HELP window,  IF it is still open.
    LetsCallWinHelp( SimpleWin, "tiny!.hlp", #0002, 0 )
    closeWindow( SimpleWin ) -- this kills the program.
end procedure

procedure onMenu_Help( atom self,  atom event,  sequence params )
-- just start Windows HELP,  with the included example.
    LetsCallWinHelp( SimpleWin, "tiny!.hlp", #0003, 0 )
end procedure

-- the two event handlers.
setHandler( ExitNow, w32HClick, routine_id( "onMenu_Exit" ) )
setHandler( HelpMe, w32HClick, routine_id( "onMenu_Help" ) )

-- 'run' the window.
WinMain( SimpleWin, Normal )

-- end of callhelp.exw
