gpt4 book ai didi

delphi - 为什么我的光标在 Delphi 的 FindDialog 中没有变成沙漏?

转载 作者:行者123 更新时间:2023-12-03 15:13:23 27 4
gpt4 key购买 nike

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

关于delphi - 为什么我的光标在 Delphi 的 FindDialog 中没有变成沙漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2660799/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com