Inno自定义界面学习笔记(三)之替换背景

Inno自定义界面学习笔记(三)之替换背景

上一篇我们学习了窗口拖动,这一篇,我们要研究如何替换背景图片。

思路

首先,我们要将背景图添加进安装包中,然后在初始化的时候将图片解压,并载入图片替换。

将botva2和InnoCallback添加进安装包

 在这么干之前,我们还要载入botva2.dll 和 InnoCallback.dll 的api。

这两个插件是用于界面的美化和功能完善的。

后期创建按钮,替换背景图片,绘图,函数回调等功能,都要通过这两个插件来实现。

在Inno中[Files]区将这两个文件添加进去,设置安装目录为{tmp}。

同时将背景图片文件也添加到[Files]区

[Files]
Source: ".\{tmp}\InnoCallback.dll";             DestDir: "{tmp}"; Flags: dontcopy solidbreak; Attribs: hidden system
Source: ".\{tmp}\botva2.dll";                   DestDir: "{tmp}"; Flags: dontcopy solidbreak; Attribs: hidden system
Source: ".\{tmp}\background_welcome.png";        DestDir: "{tmp}"; Flags: dontcopy solidbreak; Attribs: hidden system

然后声明插件中的api (注:下面这段代码,还包括很多常用的系统api的声明)

//代码区
[Code]

//声明 botva2 API
function ImgLoad(h : hwnd; FileName : PAnsiChar; Left, Top, Width, Height : integer; Stretch, IsBkg : boolean) : longint; external 'ImgLoad@files:botva2.dll stdcall delayload';
procedure ImgSetVisibility(img : longint; Visible : boolean); external 'ImgSetVisibility@files:botva2.dll stdcall delayload';
procedure ImgApplyChanges(h : hwnd); external 'ImgApplyChanges@files:botva2.dll stdcall delayload';
procedure ImgSetPosition(img : longint; NewLeft, NewTop, NewWidth, NewHeight : integer); external 'ImgSetPosition@files:botva2.dll stdcall delayload';
procedure ImgRelease(img : longint); external 'ImgRelease@files:botva2.dll stdcall delayload';
procedure CreateFormFromImage(h : hwnd; FileName : PAnsiChar); external 'CreateFormFromImage@files:botva2.dll stdcall delayload';
procedure gdipShutdown();  external 'gdipShutdown@files:botva2.dll stdcall delayload';
//function WrapBtnCallback(Callback : TBtnEventProc; ParamCount : integer) : longword; external 'wrapcallback@files:innocallback.dll stdcall delayload';
function BtnCreate(hParent : hwnd; Left, Top, Width, Height : integer; FileName : PAnsiChar; ShadowWidth : integer; IsCheckBtn : boolean) : hwnd;  external 'BtnCreate@files:botva2.dll stdcall delayload';
procedure BtnSetVisibility(h : hwnd; Value : boolean); external 'BtnSetVisibility@files:botva2.dll stdcall delayload';
procedure BtnSetEvent(h : hwnd; EventID : integer; Event : longword); external 'BtnSetEvent@files:botva2.dll stdcall delayload';
procedure BtnSetEnabled(h : hwnd; Value : boolean); external 'BtnSetEnabled@files:botva2.dll stdcall delayload';
function BtnGetChecked(h : hwnd) : boolean; external 'BtnGetChecked@files:botva2.dll stdcall delayload';
procedure BtnSetChecked(h : hwnd; Value : boolean); external 'BtnSetChecked@files:botva2.dll stdcall delayload';
procedure BtnSetPosition(h : hwnd; NewLeft, NewTop, NewWidth, NewHeight : integer);  external 'BtnSetPosition@files:botva2.dll stdcall delayload';
//function PBCallBack(P : TPBProc; ParamCount : integer) : longword; external 'wrapcallback@files:innocallback.dll stdcall delayload';
procedure ImgSetVisiblePart(img : longint; NewLeft, NewTop, NewWidth, NewHeight : integer); external 'ImgSetVisiblePart@files:botva2.dll stdcall delayload';
//function WrapTimerProc(Callback: Win7TTimerProc; ParamCount: integer): longword; external 'wrapcallback@files:InnoCallback.dll stdcall delayload';
//声明Windows API
function CreateRoundRectRgn(p1, p2, p3, p4, p5, p6 : integer) : THandle; external 'CreateRoundRectRgn@gdi32.dll stdcall';
function SetWindowRgn(h : hwnd; hRgn : THandle; bRedraw : boolean) : integer; external 'SetWindowRgn@user32.dll stdcall';
function ReleaseCapture() : longint; external 'ReleaseCapture@user32.dll stdcall';
function CallWindowProc(lpPrevWndFunc : longint; h : hwnd; Msg : UINT; wParam, lParam : longint) : longint; external 'CallWindowProcW@user32.dll stdcall';
function SetWindowLong(h : hwnd; Index : integer; NewLong : longint) : longint; external 'SetWindowLongW@user32.dll stdcall';
function GetWindowLong(h : hwnd; Index : integer) : longint; external 'GetWindowLongW@user32.dll stdcall';
function GetDC(hWnd: HWND): longword; external 'GetDC@user32.dll stdcall';
function BitBlt(DestDC: longword; X, Y, Width, Height: integer; SrcDC: longword; XSrc, YSrc: integer; Rop: DWORD): BOOL; external 'BitBlt@gdi32.dll stdcall';
function ReleaseDC(hWnd: HWND; hDC: longword): integer; external 'ReleaseDC@user32.dll stdcall';
function SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc: longword): longword; external 'SetTimer@user32.dll stdcall';
function KillTimer(hWnd, nIDEvent: longword): longword; external 'KillTimer@user32.dll stdcall';
function SetClassLong(h : hwnd; nIndex : integer; dwNewLong : longint) : DWORD; external 'SetClassLongW@user32.dll stdcall';
function GetClassLong(h : hwnd; nIndex : integer) : DWORD; external 'GetClassLongW@user32.dll stdcall';

并将文件解压,并在初始化时调用

//释放需要的临时资源文件
procedure extract_temp_files();
begin
  ExtractTemporaryFile('background_welcome.png');
end;

procedure InitializeWizard();
begin              
  extract_temp_files();//释放临时资源,用于界面渲染
  ....
end

重载CurPageChanged

//安装页面改变时会调用这个函数
procedure CurPageChanged(CurPageID : integer);
begin
  if (CurPageID = wpWelcome) then
  begin
    //初始化背景图
    image_wizardform_background := ImgLoad(WizardForm.Handle, ExpandConstant('{tmp}\background_welcome.png'), 0, 0, ScaleX(WIZARDFORM_WIDTH_NORMAL), ScaleY(WIZARDFORM_HEIGHT_NORMAL), True, True);
    WizardForm.ClientHeight := ScaleY(WIZARDFORM_HEIGHT_NORMAL);
    ImgApplyChanges(WizardForm.Handle);
  end;
  
end;

ImgLoad就是botva2.dll中的api,将图片载入到 image_wizardform_background 

ImgApplyChanges 也是botva的api,将载入的图片应用到界面上。

效果图:

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
InnoSetup是一个开放源代码的安装程序制作工具,它提供了自定义安装界面的功能,可以方便地在安装过程中添加文本框等控件。以下是如何使用InnoSetup制作带有文本框的自定义界面的简要步骤: 1. 在InnoSetup的脚本文件中声明变量,用于存储用户在文本框中输入的内容。例如: ``` [Code] var MyTextBox: TNewEdit; function InitializeSetup(): Boolean; begin MyTextBox := TNewEdit.Create(WizardForm); MyTextBox.Parent := WizardForm; MyTextBox.Left := 100; MyTextBox.Top := 100; MyTextBox.Width := ScaleX(200); MyTextBox.Text := '请输入您的名字'; Result := True; end; function NextButtonClick(CurPageID: Integer): Boolean; begin if CurPageID = wpWelcome then begin MsgBox('您好,' + MyTextBox.Text + '!', mbInformation, MB_OK); end; Result := True; end; ``` 在上述代码中,通过使用TNewEdit控件创建一个文本框,并在InitializeSetup()函数中将其添加到安装向导中。在NextButtonClick()函数中,当用户点击“下一步”按钮时,会弹出一个消息框,显示用户在文本框中输入的内容。 2. 根据需要,可以对文本框进行进一步格式设置,例如设置文本框的字体、背景色等属性,以及添加输入限制等功能。例如: ``` MyTextBox.Color := clYellow; MyTextBox.Font.Style := [fsBold]; MyTextBox.MaxLength := 10; MyTextBox.CharCase := ecUpperCase; ``` 在上述代码中,通过设置MyTextBox的Color属性和Font.Style属性,使文本框的外观更加美观。通过设置MaxLength属性,可以限制用户在文本框中输入的字符个数;通过设置CharCase属性,可以将用户在文本框中输入的字符自动转换为大写字母。 3. 最后,可以将自定义界面整合到安装程序的完整过程中。在InnoSetup的脚本文件中,可以将各个自定义页面添加到页面序列中,并在各自定义页面中添加相应的控件。例如: ``` [Code] procedure InitializeWizard(); begin WizardForm.WizardPages.Add(CreateInputPage(wpWelcome, '欢迎使用InnoSetup', '请输入您的名字:')); end; function NextButtonClick(CurPageID: Integer): Boolean; begin case CurPageID of wpWelcome: begin if MyTextBox.Text = '' then begin MsgBox('请输入您的名字!', mbError, MB_OK); Result := False; Exit; end; end; end; Result := True; end; ``` 在上述代码中,通过使用CreateInputPage()函数创建一个自定义页面,并在其中添加一个文本框。在NextButtonClick()函数中,可以对用户在文本框中输入的内容进行检查,确保用户输入了有效的内容。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值