2016-09-30 3 views
0

응용 프로그램에 힌트 메시지를 보내려면 어떻게해야합니까? 좀 테스트와 시도했다 :코드로 힌트 메시지를 보내는 방법은 무엇입니까?

TForm1 = class(TForm) 
    ApplicationEvents1: TApplicationEvents; 
    Memo1: TMemo; 
    procedure ApplicationEvents1Hint(Sender: TObject); 
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

procedure TForm1.ApplicationEvents1Hint(Sender: TObject); 
begin 
    Memo1.Lines.Add(Application.Hint); 
end; 

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); 
begin 
    Application.Hint := 'Hello'; 
end; 

관측 Memo1에의 라인, 빈 힌트 메시지마다 전송 나는 '안녕하세요'를 설정되어있는 것으로 보인다. 실제 시나리오에서

enter image description here

, 내 힌트 메시지 이해가 안을 숨길 빈 힌트 메시지는 내가 무슨 일을하고있어, 이것은 잘못된 방법이다?

답변

4

마우스가 컨트롤 위로 이동하는 동안 현재 표시되는 힌트를 조정하는 것이 실제로 시도하는 것으로 의심됩니다. 이를 수행하려면 TApplication.OnShowHint 또는 TApplicationEvents.OnShowHint 이벤트를 사용하거나 대상 컨트롤을 서브 클래스 화하여 CM_HINTSHOW 메시지를 처리 ​​할 수 ​​있습니다. 그 중 어떤 사용자 정의 할 수있는 THintInfo 기록, 예를 들어, 액세스 제공 : 이러한 방식으로 표시되는 힌트를 정의하는 것은, 각 힌트 변화에 TApplication.OnHint/TApplicationEvents.OnHint 이벤트를 트리거하지 않습니다

procedure TForm1.ApplicationEvents1ShowHint(var HintStr: string; 
    var CanShow: Boolean; var HintInfo: THintInfo) 
begin 
    // HintInfo.HintControl is the control that is about to display a hint 
    if HintInfo.HintControl = Memo1 then 
    begin 
    // HintInfo.CursorPos is the current mouse position within the HintControl 
    HintStr := Format('Hello, cursor = %d,%d', [HintInfo.CursorPos.X, HintInfo.CursorPos.Y]); 

    // the hint will remain active until it times out (see 
    // TApplication.HintHidePause and THintInfo.HideTimeout) or 
    // the mouse moves outside of the HintInfo.CursorRect. In 
    // the latter case, a new hint will be displayed. This allows 
    // you to change the hint for different sections of the 
    // HintControl. The CursorRect is set to the HintControl's 
    // whole client area by default. 

    // In this example, setting the new CursorRect to a 1x1 square 
    // around the current CursorPos will display a new hint string 
    // on each mouse movement... 
    HintInfo.CursorRect := Rect(HintInfo.CursorPos.X, HintInfo.CursorPos.Y, HintInfo.CursorPos.X, HintInfo.CursorPos.Y); 
    end; 
end; 

참고 경우에만 새를 힌트 팝업이 표시됩니다. OnShowHint/CM_HINTSHOW을 사용하면 기존 힌트 팝업의 실시간 업데이트를 수행 할 수 있습니다.

hint with live updates

4

Application.Hint을 직접 설정하지 않아도됩니다. 프레임 워크는 TApplication.Idle에서 그렇게합니다. 그것은과 같이이 수행합니다

Control := DoMouseIdle; 
if FShowHint and (FMouseControl = nil) then 
    CancelHint; 
Application.Hint := GetLongHint(GetHint(Control)); 

여기 Control가 마우스의 어떤 컨트롤입니다. 프로그램의 모든 컨트롤에 Hint 속성을 지정하지 않았으므로이 코드를 실행할 때마다 Application.Hint''으로 설정합니다.

그래서, 여기에 무슨이다 : Application.Hint을 설정하여 그에게

  • 마우스 이동 처리기가 응답 :

    • 당신은 당신의 마우스를 이동합니다.
    • 메시지 큐가 비어 있고 TApplication.OnIdle이 실행됩니다.
    • 이 업데이트로 Application.Hint이 (가) ''으로 업데이트됩니다.

    그리고 나서 처음으로 돌아가서 앞뒤로 반복하십시오.

    그래, 이건 정말 잘못된 접근법입니다. 올바른 접근 방식이 무엇인지 정확히 알기 때문에 나는 당신의 진정한 문제를 모르기 때문에 정말로 말할 수 없습니다. 일반적으로 액션, 메뉴 항목, 버튼, 도구 버튼 등과 같은 구성 요소에 대해 Hint 속성을 설정합니다.하지만 사용자의 요구가 더 동적 일 수 있습니다. 나는 그들에게 말할 수는 없지만, 왜 내가이 행동을 관찰하는지 설명했다.

    내가 생각하는 다른 점은 힌트가 아주 재미있는 동물이라는 것입니다. 동기식으로 힌트를 표시하지 마십시오. 시스템에서 힌트가 표시 될 때까지 기다린 다음 힌트의 내용을 제공해야합니다. 일반적으로 마우스가 움직이지 않을 때 응용 프로그램이 유휴 상태가되면 힌트가 표시됩니다. OnMouseMove 이벤트에 힌트를 표시하려는 코드는 프레임 워크와의 교차 용도로 작동하는 코드로 가장 잘 묘사됩니다.

  • +0

    감사합니다. 나는 이것을 염두에 두겠다. – ExDev

    관련 문제