Hi Marcin,
> -----Original Message-----
> I'm trying to add help file to my app. I have setup the
> Application.HelpFile property with proper help filename and
> it's path and F1 key should display help viewer but it does
> not. What should I do more.
> I don't want to play with help context I only want to display
> help file when user press F1 in any place in the application.
One of the simplest ways is to have an application keyboard hook. In your
app's main form add the following code:
var
__KBHook: HHOOK;
function KeyBdHook(code: Integer; wparam: WPARAM;
lparam: LPARAM): LRESULT stdcall;
const
Key_Shift = 4128 { $1020 };
Key_Control = 4129 { $1021 };
Key_Alt = 4131 { $1023 };
var
SysKeyState: Integer;
begin
Result := CallNextHookEx(__KBHook, code, wparam, lparam);
SysKeyState := 0;
if ((GetAsyncKeyState(VK_CONTROL) shr 31) > 0) then
SysKeyState := SysKeyState or KEY_CONTROL;
if ((GetAsyncKeyState(VK_MENU) shr 31) > 0) then
SysKeyState := SysKeyState or KEY_ALT;
if ((GetAsyncKeyState(VK_SHIFT) shr 31) > 0) then
SysKeyState := SysKeyState or KEY_SHIFT;
MainForm.DoKeyboardEvent(SysKeyState, wParam);
end;
In the constructor add the following code:
Application.HelpFile := 'myhelp.hlp';
__KBHook := SetWindowsHookEx(WH_KEYBOARD, @KeyBdHook,
0, GetCurrentThreadId());
In the destructor add the following code:
if (not UnhookWindowsHookEx(__KBHook)) then
MsgBox(SysErrorMessage(GetLastError));
Now add a new method to the main form:
procedure TMainForm.DoKeyboardEvent(SysKeyState: Integer; wParam: Word);
begin
case (wParam) of
VK_F1:
begin
Application.HelpCommand(HELP_FINDER, 0);
end;
end; // case
end;
Using the above code it doesn't matter which form is active you will always
show the help file in response to F1 key press.
Hih
Si Carter
http://www.tectsoft.net/
__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk