每当完成一个软件作品的时候,我们需要一个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);
读取程序版本号,需要使用如下函数:
函数原型:
BOOL WINAPI GetFileVersionInfo( __inLPCTSTR lptstrFilename, __reservedDWORD dwHandle, __inDWORD dwLen, __outLPVOID lpData );
函数原型:
BOOL WINAPI VerQueryValue( __inLPCVOID pBlock, __inLPCTSTR lpSubBlock, __outLPVOID *lplpBuffer, __outPUINT puLen );
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.