Cover a check box in the image to require a code for its selection

Viewed 26

I'm trying to create something like this:

I want the check box to be hidden behind the lock image, and clicking on it will open a form requesting code entry, and if the code is correct the image will be removed and the check box will be available.

Here's what I tried:

[files]
Source: "Lock.bmp"; Flags: dontcopy
{...}

[code]
var
  CustomFuncPage: TWizardPage;
  CBAdvFunctions: TNewCheckBox;
  Locked: TBitmapImage;

procedure OnClickLock(Sender: TObject);
var
  PassForm: TSetupForm;
  Edit: TNewEdit;
  OKButton, CancelButton: TNewButton;
begin
  PassForm := CreateCustomForm();
  PassForm.ClientWidth := ScaleX(256);
  PassForm.ClientHeight := ScaleY(128);
  PassForm.Caption := 'Password required';

  Edit := TNewEdit.Create(PassForm);
  Edit.Top := ScaleY(10);
  Edit.Left := ScaleX(10);
  Edit.Width := PassForm.ClientWidth - ScaleX(20);
  Edit.Height := ScaleY(23);
  Edit.Anchors := [akLeft, akTop, akRight];
  Edit.Parent := PassForm;

  OKButton := TNewButton.Create(PassForm);
  OKButton.Parent := PassForm;
  OKButton.Caption := 'OK';
  OKButton.Left := PassForm.ClientWidth - ScaleX(166);
  OKButton.Top := PassForm.ClientHeight - ScaleY(33);
  OKButton.Height := ScaleY(23);
  OKButton.Anchors := [akRight, akBottom]
  OKButton.ModalResult := mrOk;
  OKButton.Default := True;

  CancelButton := TNewButton.Create(PassForm);
  CancelButton.Parent := PassForm;
  CancelButton.Caption := 'Cancel';
  CancelButton.Left := PassForm.ClientWidth - ScaleX(85);
  CancelButton.Top := PassForm.ClientHeight - ScaleY(33);
  CancelButton.Height := ScaleY(23);
  CancelButton.Anchors := [akRight, akBottom]
  CancelButton.ModalResult := mrCancel;
  CancelButton.Cancel := True;

  PassForm.ActiveControl := Edit;

  if PassForm.ShowModal() = mrOk then
  begin
    if Edit.Text = '1234' then
    begin
    Locked.Free;
    PassForm.Free;
    end else
    begin
    MsgBox('Password incorrect', mbError, MB_OK);
    PassForm.Free;
    end;
  end else
  begin
    PassForm.Free;
  end;
end;
  

Procedure InitializeWizard;
begin
  CustomFuncPage := CreateCustomPage(wpSelectProgramGroup, {...}, {...});
  
  CBAdvFunctions := TNewCheckBox.Create(CustomFuncPage);
  CBAdvFunctions.Parent := CustomFuncPage.Surface;
  CBAdvFunctions.Top := 0;
  CBAdvFunctions.Left := 0;
  CBAdvFunctions.Caption := 'Advanced Functions'
  CBAdvFunctions.Width := ScaleX(130);
  CBAdvFunctions.Cursor := 1;
  CBAdvFunctions.SendToBack;

  ExtractTemporaryFile('Lock.bmp');

  Locked := TBitmapImage.Create(CustomFuncPage);
  Locked.Parent := CustomFuncPage.Surface;
  Locked.Bitmap.LoadFromFile(ExpandConstant('{tmp}\Lock.bmp'));
  Locked.Bitmap.AlphaFormat := afPremultiplied;
  Locked.SetBounds(0, 0, CBAdvFunctions.Width, CBAdvFunctions.Height);
  Locked.Stretch := True;
  Locked.BringToFront;
  Locked.OnClick := @OnClickLock;
  {...}

And this is the result:

lock

This is the image I used:

locked

I tried a few ways, but was unable to get the image to cover the checkbox.

Maybe someone has an idea?

By the way, maybe someone has an explanation for why the background of the image is not transparent?

0 Answers
Related