Delphi 7下Edit控件的气泡提示

来源:互联网 发布:编程入门书籍 知乎 编辑:程序博客网 时间:2024/04/29 19:45

   在Windows XP以及以上版本,基本控件Edit都有一个好看的气泡提示框,可惜Delphi 7还不支持这种效果,但是因为Edit是基本控件,只要在XP及以上版本,发送气泡显示消息,也就可以让其显示气泡提示。
MSDN介绍EDITBALLOONTIP结构体如下:

1
2
3
4
5
6
typedef struct tagEDITBALLOONTIP { 
  DWORD   cbStruct; 
  LPCWSTR pszTitle; 
  LPCWSTR pszText; 
  INT     ttiIcon; 
} EDITBALLOONTIP, *PEDITBALLOONTIP; 

Delphi 7下必须要放置XPMan控件,才能显示出XP风格的气泡提示框。具体实现示例源码:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
unit Unit1;  
  
interface  
  
uses  
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  Dialogs, StdCtrls, XPMan;  
  
//---------------------开始:Delphi 7 添加此声明消息----------------------------  
const  
  ECM_FIRST               = $1500;      // Edit control messages  
  EM_SHOWBALLOONTIP   = ECM_FIRST + 3// Show a balloon tip associated to the edit control  
  EM_HIDEBALLOONTIP   = ECM_FIRST + 4// Hide any balloon tip associated with the edit control  
type  
  _tagEDITBALLOONTIP = packed record  
    cbStruct: DWORD;  
    pszTitle,  
    pszText : PWideChar;  
    ttiIcon : integer;  
  end;  
  TEditBalloonTip = _tagEDITBALLOONTIP;  
//---------------------结束:Delphi 7 添加此声明消息----------------------------  
type  
  TForm1 = class(TForm)  
    edt1: TEdit;  
    btn1: TButton;  
    xpmnfst1: TXPManifest;  
    procedure btn1Click(Sender: TObject);  
  private  
    { Private declarations }  
  public  
    { Public declarations }  
  end;  
  
var  
  Form1: TForm1;  
  
implementation  
  
{$R *.dfm}  
  
procedure TForm1.btn1Click(Sender: TObject);  
var  
  ebt: TEditBalloonTip;  
begin  
  with ebt do  
  begin  
    cbStruct := SizeOf(ebt);  
    pszTitle := '提示';  
    pszText := '请输入内容';  
    ttiIcon := 1;      {NONE:0;INFO:1;WARNING:2;ERROR:3}  
  end;  
  SendMessage(edt1.Handle,EM_SHOWBALLOONTIP,0,Longint(@ebt));  
end;  
  
end.  

运行结果如下图所示:

原创粉丝点击