簡體   English   中英

為什么我的光標沒有變成Delphi中的FindDialog中的沙漏?

[英]Why doesn't my cursor change to an Hourglass in my FindDialog in Delphi?

我只是打開我的FindDialog:

FindDialog.Execute;

在我的FindDialog.OnFind事件中,我想將光標更改為沙漏以搜索大文件,這可能需要幾秒鍾。 所以在OnFind事件中我這樣做:

Screen.Cursor := crHourglass;
(code that searches for the text and displays it) ...
Screen.Cursor := crDefault;

搜索文本時,光標會正確地更改為沙漏(或Vista中的旋轉圓圈),然后在搜索完成時返回指針。

但是,這只發生在主窗體上。 它不會發生在FindDialog本身上。 搜索期間,默認光標仍保留在FindDialog上。 如果我將光標移到FindDialog上進行搜索,則會更改為默認值,如果我將其移出主表單,則會成為沙漏。

這似乎不應該發生。 我做錯了什么或者需要做些什么來使光標成為所有表格上的沙漏?

作為參考,我正在使用Delphi 2009。

我猜這個的原因有點...... 查找對話框不是表單而是對話框(通用對話框)。

您可以嘗試設置類光標(對對話框的控件沒有影響);

procedure TForm1.FindDialog1Find(Sender: TObject);
begin
  SetClassLong(TFindDialog(Sender).Handle, GCL_HCURSOR, Screen.Cursors[crHourGlass]);
  try
    Screen.Cursor := crHourglass;
    try
//    (code that searches for the text and displays it) ...
    finally
      Screen.Cursor := crDefault;
    end;
  finally
    SetClassLong(TFindDialog(Sender).Handle, GCL_HCURSOR, Screen.Cursors[crDefault]);
  end;
end;



編輯

另一種方法是在搜索時間內對FindDialog進行子類化,並使用“SetCursor”響應WM_SETCURSOR消息。 如果我們阻止進一步處理消息,則對話框上的控件將不會設置自己的游標。

 type TForm1 = class(TForm) FindDialog1: TFindDialog; ... private FSaveWndProc, FWndProc: Pointer; procedure FindDlgProc(var Message: TMessage); ... end; .... procedure TForm1.FormCreate(Sender: TObject); begin FWndProc := classes.MakeObjectInstance(FindDlgProc); end; procedure TForm1.FormDestroy(Sender: TObject); begin classes.FreeObjectInstance(FWndProc); end; procedure TForm1.FindDialog1Find(Sender: TObject); begin FSaveWndProc := Pointer(SetWindowLong(FindDialog1.Handle, GWL_WNDPROC, Longint(FWndProc))); try Screen.Cursor := crHourGlass; try // (code that searches for the text and displays it) ... finally Screen.Cursor := crDefault; end; finally if Assigned(FWndProc) then SetWindowLong(FindDialog1.Handle, GWL_WNDPROC, Longint(FSaveWndProc)); // SendMessage(FindDialog1.Handle, WM_SETCURSOR, FindDialog1.Handle, // MakeLong(HTNOWHERE, WM_MOUSEMOVE)); SetCursor(Screen.Cursors[crDefault]); end; end; procedure TForm1.FindDlgProc(var Message: TMessage); begin if Message.Msg = WM_SETCURSOR then begin SetCursor(Screen.Cursors[crHourGlass]); Message.Result := 1; Exit; end; Message.Result := CallWindowProc(FSaveWndProc, FindDialog1.Handle, Message.Msg, Message.WParam, Message.LParam); end; 

嘗試添加Application.ProcessMessages; 設置光標后。

如果這樣做,一定要打電話給你的母親,幫助一位老太太過馬路,或者種一棵樹。 否則,魔鬼將擁有你靈魂的另一小部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM