我想我读过(在我的很多谷歌搜索中)在HTML帮助中HH\u关键字\u查找被破坏了,叹气。所以我想出了这个方法来做搜索。它将调出chm文件并在搜索框中输入关键字,然后按回车键手动进行搜索。
procedure PostKey(aKey: Word; const aShift: TShiftState; aSpeciaKey: Boolean);
type
TShiftKeyInfo = record
shift: Byte;
vkey: Byte;
end;
byteset = set of 0..7;
const
shiftkeys: array [1..3] of TShiftKeyInfo =
((shift: Ord(ssCtrl); vkey: VK_CONTROL),
(shift: Ord(ssShift); vkey: VK_SHIFT),
(shift: Ord(ssAlt); vkey: VK_MENU));
var
flag: DWORD;
bShift: ByteSet absolute aShift;
i: Integer;
begin
for i := 1 to 3 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), 0, 0);
end; { For }
if aSpeciaKey then
flag := KEYEVENTF_EXTENDEDKEY
else
flag := 0;
keybd_event(aKey, MapvirtualKey(aKey, 0), flag, 0);
flag := flag or KEYEVENTF_KEYUP;
keybd_event(aKey, MapvirtualKey(aKey, 0), flag, 0);
for i := 3 downto 1 do
begin
if shiftkeys[i].shift in bShift then
keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0),
KEYEVENTF_KEYUP, 0);
end; { For }
end;
procedure CHMSearch(aCHMFilename, aSearch: string);
var
cfn: string;
qry: THHFtsQuery;
hnd: HWND;
procedure DoSearch(aMsg: string);
var
i,n: Integer;
c: Char;
shift: TShiftState;
begin
if hnd = 0 then Exit;
Windows.SetFocus(hnd);
n := Length(aMsg);
if n > 0 then
begin
for i := 1 to n do
begin
c := aMsg[i];
shift := [];
case c of
'a'..'z': shift := [];
'A'..'Z': shift := [ssShift];
'_': // underscore key
begin
keybd_event(VK_SHIFT, 0, 0, 0);
keybd_event(VK_OEM_MINUS, 0, 0, 0);
keybd_event(VK_OEM_MINUS, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
continue;
end;
'$': // $ key
begin
PostKey(Ord('4'), [ssShift], False);
continue;
end;
end;
PostKey(Ord(UpCase(c)), shift, False);
end;
PostKey(VK_RETURN, [], False);
PostKey(VK_RETURN, [], False);
end;
end;
begin
cfn := ChangeFileExt(aCHMFilename, '.chm');
FillChar(qry, SizeOf(qry), 0);
qry.cbStruct := SizeOf(THHFtsQuery);
qry.fExecute := TRUE;
HH.HtmlHelpA(GetDesktopWindow, PAnsiChar(AnsiString(cfn)), HH_DISPLAY_TOC, 0);
hnd := HH.HtmlHelpA(GetDesktopWindow, PAnsiChar(AnsiString(cfn)), HH_DISPLAY_SEARCH,
Cardinal(@qry));
DoSearch(aSearch);
end;