6

我只是打开我的 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。

4

2 回答 2

4

我想这是有原因的。与查找对话框不是表单而是对话框(通用对话框)有关。

可以尝试设置类光标(对对话框的控件没有影响);

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;



编辑

An alternative could be to subclass the FindDialog during the search time and respond to WM_SETCURSOR messages with "SetCursor". If we prevent further processing of the message the controls on the dialog won't set their own cursors.

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;
于 2010-04-18T04:00:33.940 回答
0

尝试添加 Application.ProcessMessages;设置光标后。

如果可行,请务必给您的母亲打电话,帮助一位老妇人过马路,或者种一棵树。否则,魔鬼将拥有你灵魂的另一小块。

于 2010-04-18T03:06:36.743 回答