实现原理:
按纽的实现,从Tbitbtn继承下来最理想,但需要过滤TbitBtn的焦点响应消息,使其不能获得焦点状态。
按纽的功能的实现是比较关键的,Delphi中提供了标准action对象(Twindowclose)来实现关闭当前激活的子窗体的功能。
当没有提供最小化及恢复功能的Action,因此有必须编程实现该两个对象分别命名为TWindowMinimize和TWindowRestore;并且编程是十分简单的。
为什么要采用action来实现最小化,恢复和关闭MDI子窗体具体的功能呢,这是因为,Delphi已经实现了其状态的自动变更。
另外,这三按纽必须保持在主界面的位置一直处于右上角.因此,需要在主窗体改变大小的时候,重新计算其位置。
由于只有子窗体最大化时,这三个按纽才能出现,因此,需要在idel事件中去判断当前的子窗体的状态,以便决定这三个按纽是否隐藏或可见.
具体代码如下:
unit ufrmMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms,
Dialogs, ActnList, AppEvnts, ImgList, StdCtrls,
Buttons, StdActns, Menus,
ToolWin, ComCtrls;
type
//最大最小化按纽类
TMDIButton =
class(TBitbtn)
private
public
//由于由Tbitn继承而来,因此需要屏蔽其获得焦点的消息
procedure
wndproc(var message: Tmessage); override;
end;
TWindowMinimize =
class(TWindowAction)
public
//按纽功能,将当前最前的子window状态改为wsMinimize;
procedure
ExecuteTarget(Target: TObject); override;
end;
TWindowRestore =
class(TWindowAction)
public
//按纽功能,将当前最前的子window状态改为wsNormal;
procedure
ExecuteTarget(Target: TObject); override;
end;
TFrmMain =
class(TForm)
//保存windows的最小化,恢复,关闭的图标
MDIImageList:
TImageList;
//当程序不忙时,判断最大,最小化按纽的是否应该隐藏还是可见
ApplicationEvents1:
TApplicationEvents;
//
ActMdiForm: TActionList;
ToolBar1:
TToolBar;
MainMenu1: TMainMenu;
N1: TMenuItem;
open1:
TMenuItem;
help1: TMenuItem;
procedure FormCreate(Sender:
TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done:
Boolean);
procedure FormResize(Sender: TObject);
procedure
FormDestroy(Sender: TObject);
procedure open1Click(Sender:
TObject);
private
//模拟mdiform窗体最小化,关闭及恢复按纽对象
BtnMin, BtnRestore,
BtnClose: TMDIButton;
Windowclose: TWindowClose;
WindowMinimize:
TWindowMinimize;
WindowRestore: TWindowRestore;
procedure
SetMDIFormActionPos;
public
{ Public declarations }
end;
var
FrmMain: TFrmMain;
implementation
{$R *.dfm}
procedure TFrmMain.FormCreate(Sender:
TObject);
begin
//建立关闭Button
BtnClose :=
TMDIButton.Create(self);
BtnClose.Visible := false;
BtnClose.Parent
:= self;
BtnClose.Width := 16;
Btnclose.Height :=
15;
//建立关闭功能Action
WindowClose :=
TWindowClose.Create(nil);
//指定其图标
WindowClose.ActionList :=
ActMdiForm;
WindowClose.ImageIndex := 2;
//关闭;
WindowClose.Caption :=
'';
//将action与button关联
BtnClose.Action :=
WindowClose;
BtnClose.BringToFront;
BtnClose.Visible := false;
//建立最小化Button
BtnMin := TMDIButton.Create(self);
BtnMin.Visible
:= false;
BtnMin.Parent := self;
BtnMin.width :=
16;
BtnMin.height := 15;
//建立最小化功能action
WindowMinimize :=
TWindowMinimize.Create(nil);
//指定其图标
WindowMinimize.ActionList :=
ActMdiForm;
WindowMinimize.Caption := '';
WindowMinimize.ImageIndex
:= 0;
//将action与button关联
BtnMin.Action := WindowMinimize;
//最小化
BtnMin.BringToFront;
BtnMin.Visible := false;
//建立恢复功能Button
BtnRestore :=
TMDIButton.Create(self);
BtnRestore.Visible :=
false;
BtnRestore.Parent := self;
BtnRestore.Width :=
16;
BtnRestore.height := 15;
//建立恢复功能action
WindowRestore :=
TWindowRestore.Create(nil);
//指定其图标
WindowRestore.ActionList :=
ActMdiForm;
WindowRestore.Caption := '';
WindowRestore.ImageIndex :=
1;
//将action与button关联
BtnRestore.Action :=
WindowRestore;
BtnRestore.BringToFront;
BtnRestore.Visible :=
false;
//设置按纽位置,位置保持在主界面上相对不变
SetMDIFormActionPos;
end;
procedure TFrmMain.ApplicationEvents1Idle(Sender: TObject;
var Done:
Boolean);
var
show:
boolean;
begin
//当前子窗体的状态为最大化时,显示三个按纽
show :=
(self.ActiveMDIChild <> nil) and (self.ActiveMDIChild.WindowState
=
wsMaximized);
if assigned(BtnClose) and BtnClose.Visible <>
Show then
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
- AnsiString?PChar?赋值
- Report Machine 3.0 (报表
- MapX v5.02.25 破解文件
- WDBOX v1.0 多选下拉列表
- 用Delphi开发视频聊天软件
- Delphi客户服务器应用开发
- AES 加密算法函数包及演示
- ACCESS/SQL 数据库存取图
- 熊猫烧香核心源码(Delphi
- 把整个网页保存成JPG图片(
- 高级计算器 V1.0 (含代码)
- Delphi版模仿熊猫烧香病毒
- 精确定位打印程序 (含源代
- Delphi文件管理(六)
- 将数字四舍五入保留两位小
- 绝地程序编辑器 v1.0.1.4
- 关于自定义界面的方案(Eas
- Delphi 对象链接与嵌入(
- 用HTML页面做程序界面演示
- Delphi模拟最小化恢复关闭
- 用Delphi实现24位真彩色图
- 限制客户机运行程序 (有关
- Delphi中用API实现在MSN的
- DELPHI数据库应用程序的开
- Delphi 动态链接库编程(
- QQ号码自动申请器及源代码
- Win9x 下调整系统时钟控件
- delphi中的XML解析控件TXM
- 几个游戏内存修改器代码
- TT8 DevExpress 最新系列
- Tnt Delphi Unicode Contr
- DelphiTwain 2004-1-20 (
- Delphi中数据的自动录入
- 经验技巧:分享两条Delphi
- Delphi中Hash表的使用方法
网站运营 建站经验 策划盈利 搜索优化 网站推广 免费资源
网站联盟 联盟新闻 联盟介绍 联盟点评 网赚技巧
行业资讯 业界动态 搜索引擎 网络游戏 门户动态 电子商务 广告传媒
网络编程 Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术 Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 Internet Explorer
网页制作 FrontPages Dreamweaver Javascript css photoshop fireworks Flash
程序设计 Java技术 C/C++ VB delphi
网络知识 网络协议 网络安全 网络管理 组网方案 Cisco技术
操作系统 Win2000 WinXP Win2003 Mac OS Linux FreeBSD




