为什么我的光标在Delphi的FindDialog中不会变成沙漏? [英] Why doesn't my cursor change to an Hourglass in my FindDialog in Delphi?

查看:257
本文介绍了为什么我的光标在Delphi的FindDialog中不会变成沙漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是打开我的FindDialog:

I am simply opening my FindDialog with:

FindDialog.Execute;

在我的FindDialog.OnFind事件中,我想将光标更改为沙漏以搜索大文件,这可能需要几秒钟。所以在OnFind事件中我这样做:

In my FindDialog.OnFind event, I want to change the cursor to an hourglass for searches through large files, which may take a few seconds. So in the OnFind event I do this:

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

在搜索文本时会发生什么,光标正确地更改为沙漏Vista),然后在搜索完成时返回指针。

What happens is while searching for the text, the cursor properly changes to the hourglass (or rotating circle in Vista) and then back to the pointer when the search is completed.

但是,这只发生在主窗体上。它不会发生在FindDialog本身。搜索期间默认光标保留在FindDialog上。在搜索时,如果我把光标移动到FindDialog上,它会变成默认值,如果我把它移开,在主窗体上就变成沙漏。

However, this only happens on the main form. It does not happen on the FindDialog itself. The default cursor remains on the FindDialog during the search. While the search is happening if I move the cursor over the FindDialog it changes to the default, and if I move it off and over the main form it becomes the hourglass.

这似乎不是应该发生的事情。我做错了什么,或者需要做特别的事情,以使光标在所有形式上都成为沙漏?

This does not seem like what is supposed to happen. Am I doing something wrong or does something special need to be done to get the cursor to be the hourglass on all forms?

为了参考,我使用Delphi 2009。

For reference, I'm using Delphi 2009.

推荐答案

我想这个原因是sth。与查找对话框不是一个形式而是一个对话框(一个公共对话框)。

I guess the reason for this has got sth. to do with Find Dialog being not a form but a Dialog (a Common Dialog).

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

You can try setting the class cursor (does not have an effect on the controls of the dialog);

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;






EDIT

另一种方法是在搜索期间对FindDialog进行子类化,并使用SetCursor响应WM_SETCURSOR消息。如果我们阻止进一步处理消息,对话框上的控件将不会设置自己的游标。

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;

这篇关于为什么我的光标在Delphi的FindDialog中不会变成沙漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆