HH_PRETRANSLATEMESSAGE

Call this command in the applications messsage loop to ensure proper message handling.

Argument Description
hwndCaller Handle of parent or owner window, may be 0/GetDesktopWindow
pszFile Must be nil
uCommand HH_PRETRANSLATEMESSAGE
dwData Pointer to the Win32 TMessage record retrieved from GetMessage

Return value:
True if the message was translated or False if the command failed.

Description:
When using HTML Help on the same thread as you application you must call the HH_PRETRANSLATEMESSAGE command in your applications message loop to ensure proper handling of Windows messages, especially mouse and keyboard messages. Note that pre-translating messages is only necessary when running HTML Help in the applications thread, meaning you don't have to do this when you haven't issued the HH_INITIALIZE command.

Example:

Assuming you have Delphi 5, drop a TAppicationsEvents component onto your mainform and generate and event handler for the OnMessage event. Also generate event handlers for TForm1 OnCreate and OnDestroy. You should then code them like this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  HtmlHelp(0, nil, HH_INITIALIZE, DWORD(@FCookie));
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  HtmlHelp(0, nil, HH_UNINITIALIZE, FCookie);
end;

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
  Handled := BOOL(HtmlHelp(0, nil, HH_PRETRANSLATEMESSAGE, DWORD(@Msg)));
end;

Notes:
The HTML Help API is not thread safe and therefore must be called only from one thread, usually your applications main thread. You command HTML Help to run in your applications thread by using HH_INITIALIZE which must be called before any other HTML Help command. On application shutdown you must uninitialize HTML Help by using the HH_UNINITIALIZE command, which must be the last command issued to HTML Help.

See also:
HH_INITIALIZE
HH_UNINITIALIZE