Using FindVCLWindow to call WinHelp32 (WinXP Pro SP3 32bit) in Delphi

前端 未结 2 1019
北海茫月
北海茫月 2021-01-16 20:50

what is wrong there?

procedure TForm1.VCLHelpClick(Sender: TObject);
var Ctrl : TWinControl;
 begin
 Ctrl := FindVCLWindow(Mouse.CursorPos);
 if Ctrl <>         


        
相关标签:
2条回答
  • 2021-01-16 21:30

    Working code:

    procedure TForm1.VCLHelpClick(Sender: TObject);
    var WCtrl : TWinControl;
    begin
      WCtrl := FindVCLWindow(Mouse.CursorPos);
      if WCtrl <> nil then
       Application.HelpCommand(HELP_CONTEXT, wCtrl.HelpContext);
    end;
    

    P.S. all previous code probobly was ok too, but i rechecked my event handlers and found that in one tlabel it was missing ( althought when I clicked to the ones that had onclick, it did not work). Plus ... problem probobly was the faulty cursor check.

    Ok, thanks for support, guys!

    0 讨论(0)
  • 2021-01-16 21:46

    Have you tried debugging the code? And can you tell us what part went wrong.

    Besides, why don't you use the helpcontext like:

    procedure TForm1.VCLHelpClick(Sender: TObject);
    var Ctrl : TWinControl;
    begin
      if Form2.Cursor <> crHelp then   // Are you sure this is Form2???
        Exit;
      Ctrl := FindVCLWindow(Mouse.CursorPos);
      if Ctrl = nil then Exit;
    
      Application.HelpCommand(HELP_CONTEXT, Ctrl.HelpoContext);
    end;
    

    Looks like FindVCLControl does some other things. But the following code works:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ctrl : TControl;
      point : TPoint;
    begin
      point := Mouse.CursorPos; // Mouse pos at screen
      Dec(point.X, Left); // Adjust for window.
      Dec(point.Y, Top);
      Dec(point.Y, GetSystemMetrics(SM_CYCAPTION)); // Adjust to client area.
    
      ctrl := ControlAtPos(point, True, True, True);
    
      // Do something with the control
    end;
    

    You probably need some more tweaking, but this works to get the control of a window from the position.

    0 讨论(0)
提交回复
热议问题