HTML Help keyword lookup

后端 未结 2 404
南笙
南笙 2021-01-07 12:06

I\'m having trouble figuring out how to get keyword lookups (HH_KEYWORD_LOOKUP) to work in HTML Help. If I have an index that displays like this:

Machine
           


        
2条回答
  •  Happy的楠姐
    2021-01-07 12:36

    I think I read (in my many google searches) that HH_KEYWORD_LOOKUP is broken in HTML help, sigh. So Ie came up with this solution to do a search. It will bring up the chm file and enter the keyword into the search box and press the ENTER key to manually do the search.

    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;
    

提交回复
热议问题