通用的关于对话框

每当完成一个软件作品的时候,我们需要一个about对话框!

为了省去这样的重复工作,我们有必要制作一个通用的关于对话框!


根据他们的共性,可以分两部分:

一、单位信息

二、程序信息


单位信息:主要为单位名称、单位地址、单位电话、单位E-Mail、单位网址;

程序信息:主要为此程序对计算机硬件需求、计算机软件需求和程序版本。


为了美观,可以在对话框左上方,放一个logo!

整体的窗体布局图,如下图,所示:


在程序实现部分,需要填写打开网址和主程序版本号。


打开网址需要使用WIN32函数ShellExecute

他的原型为:

HINSTANCE ShellExecute(
  __in_optHWND hwnd,
  __in_optLPCTSTR lpOperation,
  __inLPCTSTR lpFile,
  __in_optLPCTSTR lpParameters,
  __in_optLPCTSTR lpDirectory,
  __inINT nShowCmd
);

我们只要三个参数即可:句柄、网址、打开方式

代码如下:

ShellExecute(Handle, nil, PChar(Label10.Caption), nil, nil, SW_SHOWNORMAL);
读取程序版本号,需要使用如下函数:

1. GetFileVersionInfo

函数原型:

BOOL WINAPI GetFileVersionInfo(
  __inLPCTSTR lptstrFilename,
  __reservedDWORD dwHandle,
  __inDWORD dwLen,
  __outLPVOID lpData
);

2. VerQueryValue

函数原型:

BOOL WINAPI VerQueryValue(
  __inLPCVOID pBlock,
  __inLPCTSTR lpSubBlock,
  __outLPVOID *lplpBuffer,
  __outPUINT puLen
);

3. GetModuleFileName

DWORD WINAPI GetModuleFileName(
  __in_optHMODULE hModule,
  __outLPTSTR lpFilename,
  __inDWORD nSize
);

具体代码u_about.pas

unit u_about; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, jpeg, ExtCtrls, ShellApi; type Tfrm_about = class(TForm) mo_about: TMemo; Label7: TLabel; Label8: TLabel; Label5: TLabel; Label6: TLabel; Label9: TLabel; Label10: TLabel; Image1: TImage; Label2: TLabel; StaticText1: TStaticText; StaticText2: TStaticText; Label1: TLabel; procedure Label10Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public verStr:string; function GetCDPFileVersion(FileName: String): String; { Public declarations } end; var frm_about: Tfrm_about; implementation {$R *.dfm} procedure Tfrm_about.Label10Click(Sender: TObject); begin // ShellExecute(Handle, nil, PChar(Label10.Caption), nil, nil, SW_SHOWNORMAL); end; function Tfrm_about.GetCDPFileVersion(FileName: String): String; var InfoSize, Wnd: DWORD; VerBuf: Pointer; VerInfo: ^VS_FIXEDFILEINFO; begin Result := '1.0.0.0'; InfoSize := GetFileVersionInfoSize(PChar(FileName), Wnd); if InfoSize<>0 then begin GetMem(VerBuf, InfoSize); try if GetFileVersionInfo(PChar(FileName), Wnd, InfoSize, VerBuf) then begin VerInfo:=nil; VerQueryValue(VerBuf, '\', Pointer(VerInfo), Wnd); if VerInfo<>nil then Result:=Format('%d.%d.%d.%d', [VerInfo^.dwFileVersionMS shr 16, VerInfo^.dwFileVersionMS and $0000ffff, VerInfo^.dwFileVersionLS shr 16, VerInfo^.dwFileVersionLS and $0000ffff]); end; finally FreeMem(VerBuf, InfoSize); end; end; end; procedure Tfrm_about.FormShow(Sender: TObject); var szExePathname: array [0..266] of char; hMoudleA: DWORD; begin hMoudleA := GetModuleHandle(nil); GetModuleFileName(hMoudleA, szExePathname, MAX_PATH); verStr := GetCDPFileVersion(string(szExePathname)); mo_about.Lines.Append(#13); mo_about.Lines.Append('主程序版本号:'); mo_about.Lines.Add(' ' + verStr); end; end.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值