Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching OnHelp in Delphi 7 - Event never fires 2

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
US
I have been trying to detect when the user is trying to open the help for something. Switching a form to "KeyPreview:= True" and catching the "OnKeyDown" event works, but does not cut it. Plus, this project has hundreds of forms, and I'm not going to go do this on each and every form, and try to remember later to add it to any new forms, etc.

Therefore, I have been seeking a global application-level event handler for catching the help. In the "Application" object, there is in fact an event "OnHelp" which I tried to use, but for some reason this event is never triggered. The goal is to provide 2 help resources for the application: A) regular HTML help (.chm files) which is already there and working, and B) online help to open a corresponding webpage instead of the local help file. In order to do so, I have to catch any possible event of trying to open the help (not just F1), catch the HelpContext ID, cancel the local help file from opening, then open the web page in its place.

Here's my code related to what I'm trying to do...
Code:
function TForm1.AppHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
begin
  //Breakpoint here is never reached
  if WebHelp then begin //Check if user's option to use Web Help is enabled
    CallHelp:= False; //Cancel local help from opening
    DoHelp(Data); //Open web help instead
    //is "Data" supposed to be the HelpContext ID?
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnHelp:= AppHelp; //assigning function to event
end;

procedure TForm1.DoHelp(const HelpContext: Integer);
const
  WebRoot = '[URL unfurl="true"]http://mycompanywebsiteroot.com/Help.htm?id=';[/URL]
begin
  //Help.htm is a page that redirects to proper page based on 'id' parameter
  ShellExecute(WindowHandle, 'open', PChar(WebRoot+IntToStr(HelpContext)), nil, nil, SW_SHOWNORMAL); //launch web page in default browser
end;


JD Solutions
 
Wow, that works beautifully =D Thanks

JD Solutions
 
Basically I've been trying to learn how to use HtmlHelp and try to figure out all the things I could ever want to know, as well as get it working with my things. One of the things I've run into is the following code. What it does is that it puts a text window on top of a specified form with the text you want in the position you want it in. Found it interesting anyway.

Code:
function HtmlHelp(hwndCaller: THandle; pszFile: PChar; uCommand: cardinal; dwData: longint): THandle; stdcall;

implementation

function HtmlHelp; external hhctrllib name 'HtmlHelpA';

function ShowPopupString1(Parent: TForm; Text: string; Position: TPoint): HWnd;
var
  popupstruct: TPopupStruct;
begin
  with popupstruct do
    begin
      cbStruct := sizeof(popupstruct);
      hinst := 0; // instance handle if str res
      idString := 0; // zero, resourceid or topicid
      pszText := PChar(Text); // text to display if idString = 0
      pt := Position;
      clrForeground := COLORREF(-1); // default RGB value
      clrBackground := COLORREF(-1); // default RGB value
      rcMargins := Rect(-1, -1, -1, -1);
      pszFont := 'MS Sans Serif, 10, , BOLD';
   end;
  Result := HtmlHelp(Parent.Handle, nil, HH_DISPLAY_TEXT_POPUP,
            DWord(@popupstruct));
end;

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Some pieces I forgot in the previous post:

Code:
const
  hhctrllib = 'hhctrl.ocx';

type
TPopupStruct = packed record
    cbStruct:      Integer;     // sizeof this structure
    hinst:         HINST;       // instance handle 
   // string resource id, or text id if pszFile is specified 
    idString:      cardinal; 
    pszText:       PChar;       // used if idString is zero
    pt:            TPOINT;      // top center of popup window
    clrForeground: COLORREF;    // use -1 for default
    clrBackground: COLORREF;    // use -1 for default
// amount of space between edges of window and text,
// -1 for each member to ignore
    rcMargins:     TRect;       
   // facename, point size, char set, BOLD ITALIC UNDERLINE
    pszFont:       PChar;    
  end;

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top