Flicker free background image

From ISXKB

Jump to: navigation, search

This example can be useful to display a background image. The code has been provided by Sandor Hincs (http://news.jrsoftware.org/news/innosetup.code/msg15975.html).

[Setup]
WindowVisible=no

[Files]
Source: image\kjk_640.bmp; DestDir: {tmp}; Flags: dontcopy
Source: image\kjk_800.bmp; DestDir: {tmp}; Flags: dontcopy
Source: image\kjk_1024.bmp; DestDir: {tmp}; Flags: dontcopy
Source: image\kjk_1152.bmp; DestDir: {tmp}; Flags: dontcopy
Source: image\kjk_1280.bmp; DestDir: {tmp}; Flags: dontcopy
Source: image\kjk_1600.bmp; DestDir: {tmp}; Flags: dontcopy

[Code]
//importing a Windows API function
function GetDC(HWND: DWord): DWord;
external 'GetDC@user32.dll stdcall';
function GetDeviceCaps(DC: DWord; Index: Integer): Integer;
external 'GetDeviceCaps@gdi32.dll stdcall';
function ReleaseDC(HWND: DWord;DC: DWord): Integer;
external 'ReleaseDC@user32.dll stdcall';
function ShowWindow(hWnd: DWord; nCmdShow: Integer): boolean;
external 'ShowWindow@user32.dll stdcall';
function SetWindowLong(hWnd: DWord; nIndex: Integer; dwNewLong: Longint):
Longint;
external 'SetWindowLongA@user32.dll stdcall';

procedure InitializeWizard();
var
  bgImage : TBitmapImage;
  bgImageName: String;
  width: integer;
  dc: DWord;

begin
  bgImage:=TBitmapImage.Create(MainForm);
  bgImage.Align:=alClient;
  bgImage.Stretch:=true;
  bgImage.Parent:=MainForm;

  dc:=GetDC(MainForm.Handle);
  width:=GetDeviceCaps(dc,8);
  ReleaseDC(MainForm.Handle,dc);

  if width <=640 then
    bgImageName:='kjk_640.bmp'
  else if width<=800 then
    bgImageName:='kjk_800.bmp'
  else if width<=1024 then
    bgImageName:='kjk_1024.bmp'
  else if width<=1152 then
    bgImageName:='kjk_1152.bmp'
  else if width<=1280 then
    bgImageName:='kjk_1280.bmp'
  else
    bgImageName:='kjk_1600.bmp';

  ExtractTemporaryFile(bgImageName);
  bgImage.bitmap.LoadFromFile(expandConstant('{tmp}\'+bgImageName));

  SetWindowLong(MainForm.Handle,-16,$80000000);
  ShowWindow(Mainform.Handle,SW_SHOWMAXIMIZED);
end;
Personal tools
Ads: