用Delphi编写一个请等待屏幕的最简单的方法是什么? [英] What's the easiest way to write a please wait screen with Delphi?

查看:184
本文介绍了用Delphi编写一个请等待屏幕的最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想要一个快速而肮脏的非模态,不可关闭的屏幕弹出并消失,使2秒钟似乎更像... 1秒。使用3-5行代码。



这太多问了吗?

解决方案>

如果你想以编程方式(即,如果你不想在Delphi表单设计器中设计你的表单),你可以写出

  type 
TStatusWindowHandle = type HWND;

函数CreateStatusWindow(const Text:string):TStatusWindowHandle;
var
FormWidth,
FormHeight:integer;
begin
FormWidth:= 400;
FormHeight:= 164;
result:= CreateWindow('STATIC',
PChar(Text),
WS_OVERLAPPED或WS_POPUPWINDOW或WS_THICKFRAME或SS_CENTER或SS_CENTERIMAGE,
(Screen.Width - FormWidth)div 2,
(Screen.Height - FormHeight)div 2,
FormWidth,
FormHeight,
Application.MainForm.Handle,
0,
HInstance,
无);
ShowWindow(result,SW_SHOWNORMAL);
UpdateWindow(result);
结束

程序RemoveStatusWindow(StatusWindow:TStatusWindowHandle);
begin
DestroyWindow(StatusWindow);
结束

在新的单位。那么你可以随时调用这些函数:

  procedure TForm3.Button1Click(Sender:TObject); 
var
status:TStatusWindowHandle;
begin
status = = CreateStatusWindow('Please Wait ...');
try
睡眠(2000);
finally
RemoveStatusWindow(status);
结束
结束


I just want a quick and dirty non-modal, non-closable screen that pops up and goes away to make 2 seconds seem more like... 1 second. Using 3-5 lines of code.

Is this too much to ask?

解决方案

If you want to do everything programmatically (that is, if you do not want to design your form in the Delphi form designer), than you can write

type
  TStatusWindowHandle = type HWND;

function CreateStatusWindow(const Text: string): TStatusWindowHandle;
var
  FormWidth,
  FormHeight: integer;
begin
  FormWidth := 400;
  FormHeight := 164;
  result := CreateWindow('STATIC',
                         PChar(Text),
                         WS_OVERLAPPED or WS_POPUPWINDOW or WS_THICKFRAME or SS_CENTER or SS_CENTERIMAGE,
                         (Screen.Width - FormWidth) div 2,
                         (Screen.Height - FormHeight) div 2,
                         FormWidth,
                         FormHeight,
                         Application.MainForm.Handle,
                         0,
                         HInstance,
                         nil);
  ShowWindow(result, SW_SHOWNORMAL);
  UpdateWindow(result);
end;

procedure RemoveStatusWindow(StatusWindow: TStatusWindowHandle);
begin
  DestroyWindow(StatusWindow);
end;

in a new unit. Then you can always call these functions like this:

procedure TForm3.Button1Click(Sender: TObject);
var
  status: TStatusWindowHandle;
begin
  status := CreateStatusWindow('Please Wait...');
  try
    Sleep(2000);
  finally
    RemoveStatusWindow(status);
  end;
end;

这篇关于用Delphi编写一个请等待屏幕的最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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