Invoke close button click

396 views
Skip to first unread message

Sam Oxigen

unread,
Feb 21, 2022, 2:47:53 AM2/21/22
to innosetup
I have two buttons on my installer finished page; 'close' and 'launch <something>.'
A user has two options , my design requirements on this page is:
Option 1: close the installer with 'close' button (no problem here), and
Option 2: when the user clicks the  'launch < something>'  button then I should open a local url then I should close the installer.
I do launch the local url but I can't find a way to invoke the 'close' button from 'launch <something>' button click event. What I do currently, I terminate the installer process with exit code 0, but ideally, I should invoke the 'close' button with some parameter to make installer exit with silent mode, without a confirmation.

I found some solution on how to close the installer silently, but that works when close button is clicked and  NextButtonClick built in event is involved.
https://stackoverflow.com/a/21737577

My question is:
Is there an invoke method for a control to do its assigned event?
say: buttonClose.Invoke('Click');

Thanks,
Sam
 

Laurent Combémorel

unread,
Feb 21, 2022, 4:31:30 AM2/21/22
to innosetup
Can you please share how you have created the close button ? In a regular installer, there is a finish button and no close button...
The main idea is to have a your close button as a global variable, so it could be accessed from everywhere. And calling the onclick  should be a piece of cake!

Sam Oxigen

unread,
Feb 21, 2022, 11:43:49 AM2/21/22
to innosetup

[Messages]
ButtonFinish=Close


[Code]
...

@ <some-procedure>
...
  Button := TButton.Create(WizardForm);
  with Button do begin
    Parent := WizardForm;
    Top := WizardForm.CancelButton.Top;
    Left := LaunchButtonLeft;
    Width := ScaleX(120);
    Height := WizardForm.CancelButton.Height;
    Anchors := [akRight, akBottom];
    Caption := 'Launch Uploader';
    OnClick := @LaunchUploaderClick;
  end;
...

procedure LaunchUploaderClick(Sender: TObject);
begin

     // simplified
     ShellExec('open', 'https://Localhost:5555/', '', '', SW_SHOWNORMAL, ewNoWait, ResultCode);

    // simplified
    // This method will write no log to installer logger (empty string) then terminate the installer with exit code 0.
   // This however will abort the installer from  existing properly, logging too.
    TerminateSetup('',0);
 
   // What I need here, is to invoke finish/close button click event.

end;

Laurent Combémorel

unread,
Feb 21, 2022, 2:10:39 PM2/21/22
to innosetup
OK so in fact the Close button is the Finish button on which you changed the message, and in fact the Finish button is the WizardForm.NextButton with a special finish message.

I confirmed this with this small code :

Procedure CurPageChanged(CurPageId: Integer);
begin
  if CurPageId = wpFinished then MessageBox('Finish button caption: ' + WizardForm.NextButton.Caption, mbInformation, MB_OK);
end;

So your intention is to send a click message from inside of LaunchUploaderClick to WizardForm.NextButton object... You don't wish to wait the message to be processed before returning from the program, so you must use PostMessage function.

Something like PostMessage(WizardForm.NextButton.handle,...

with the appropriate other parameters to indicate a click...

I leave it up to you to find what they should be (and to report your findings to help other developpers to know about)...

Sam Oxigen

unread,
Feb 21, 2022, 3:19:43 PM2/21/22
to innosetup
It didn't work (with quick tests)
SendMessage(WizardForm. NextButton.Handle, 512,0,0)
PostMessage(WizardForm. NextButton.Handle, 512,0,0)

SendMessage(WizardForm. CancelButton.Handle, 512,0,0)
PostMessage(WizardForm.   CancelButton.Handle, 512,0,0)

I'll do some more tests tonight.
Thanks for the tip.

Sam

Jernej Simončič

unread,
Feb 21, 2022, 3:23:58 PM2/21/22
to Sam Oxigen on [innosetup]

On Monday, February 21, 2022, 08:47:52, Sam Oxigen wrote:


Is there an invoke method for a control to do its assigned event?
say: buttonClose.Invoke('Click');

This should work:

 

WizardForm.NextButton.OnClick(TNewButton(Sender).Parent);

 

-- 
< Jernej Simončič ><><><><>< https://eternallybored.org/ >


Buttered bread tends to fall with the buttered side down.
       -- Bernstein's First Law

Gavin Lambert

unread,
Feb 21, 2022, 4:57:53 PM2/21/22
to inno...@googlegroups.com
On 21/02/2022 20:47, Sam Oxigen wrote:
> I have two buttons on my installer finished page; 'close' and 'launch
> <something>.'
> A user has two options , my design requirements on this page is:
> Option 1: close the installer with 'close' button (no problem here), and
> Option 2: when the user clicks the 'launch < something>'  button then I
> should open a local url then I should close the installer.

Get rid of your custom button and just use a [Run] entry with the
"postinstall" flag to run your application, as shown in the examples and
the wizard generated script.

When ticked, this will run your app when the user clicks Finish, and
also close the installer. This has equivalent functionality to what
you're trying to make.

Laurent Combémorel

unread,
Feb 22, 2022, 3:16:33 AM2/22/22
to innosetup
The solution given by Gavin is the best one for the functionality...
BTW, 512 is not the correct value of  BM_CLICK... From http://www.jasinskionline.com/windowsapi/ref/b/bm_click.html, it is 245...

Reply all
Reply to author
Forward
0 new messages