⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在信息框中使用自定义的图标 (2001年5月26日).txt

📁 delphi 编程技巧
💻 TXT
字号:
在信息框中使用自定义的图标 (2001年5月26日) 

本站更新  分类:控件使用   作者:CoDelphi  推荐:   阅读次数:211  
(http://www.codesky.net)  

--------------------------------------------------------------------------------

可以使用API函数MessgeBoxIndirect,它把信息框的结构作为参数。把这个API函数封装在过程MyAboutBox里,通过应用程序中的图标显示一个信息框:

{------}
procedure MyAboutBox(Text: String);
var
MsgPars: TMsgBoxParams;
begin
with MsgPars do
begin
cbSize := SizeOf(MsgPars);
hwndOwner := Sysinit.HInstance;
hInstance := Sysinit.hInstance; //寻找资源
lpszText := PChar(Text); //若使用Delphi 1,必须使用StrPCopy
lpszCaption := 'About';
dwStyle := MB_OK or MB_USERICON;
lpszIcon := 'MAINICON'; //应用程序的主图标,包含在*.exe中
dwContextHelpId := 0; //帮助
lpfnMsgBoxCallback := nil;
dwLanguageId := LANG_NEUTRAL;
end; //with
MessageBoxIndirect(MsgPars);
end;
{------}

现在,你可以使用它了:

{------}
procedure TForm1.Button1Click(Sender: TObject);
begin
MyAboutBox('Example of changing the default MessageBox icons'#13 +
'by Odilon Nelson - odilon.nelson@usa.net');
end;
{------}

注意,在过程 MyAboutBox 中加入以下代码:

{------}
hwndOwner := Sysinit.HInstance;
hInstance := Sysinit.hInstance;
{------}

使用with语句为了避免两个变量hinstance冲突。Hinstance是记录 TMsgBoxParams 的一个成员,另一个是应用程序的句柄,在Sysinit 单元中定义 (在ObjectPascal中: hInstance 和 HInstance 是相同的)。

这个方法的优点是明显的:产生一个‘关于’信息框,而不需要在工程中包含一个额外的窗体。
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -