The below code asks user to select Yes or No using CreateInputOptionPage, with the below code I want to prompt message "Yes selected" if user selects "Yes" if user selects no then prompt "No selected".
My code doesn't seem to work. Please help.
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DisableProgramGroupPage=yes
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=D:\authorized\Builds\Custom wizard
[Code]
//#include "Solo - detectVersionFInal.iss"
var
UsagePage: TInputOptionWizardPage;
InstallationTypeIsClient: boolean;
Initialize:boolean;
procedure InitializeWizard;
begin
{ Create the pages }
UsagePage := CreateInputOptionPage(wpWelcome,
'KMOffline setup information', 'How would you like to install KMOffline?',
'Would you like to insall KMOffline as a service?.',
True, False);
UsagePage.Add('Yes');
UsagePage.Add('No');
UsagePage.Values[0] := False;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID=UsagePage.ID then
begin
InstallationTypeIsClient := UsagePage.Values[0];
MsgBox('InstallationTypeIsClient value is ' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
end;
Result := True;
end;
function InitializeSetup: Boolean;
var
begin
if (InstallationTypeIsClient=True) then
begin
MsgBox('Yes selected' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
end;
if (InstallationTypeIsClient=False) then
begin
MsgBox('No selected ' + Format('%d', [InstallationTypeIsClient]), mbInformation, MB_OK);
end;
Result := True;
end;
Just move your code from InitializeSetup to NextButtonClick:
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = UsagePage.ID then
begin
if UsagePage.Values[0] then
begin
MsgBox('Yes selected', mbInformation, MB_OK);
end
else
begin
MsgBox('No selected', mbInformation, MB_OK);
end;
end;
Result := True;
end;
Related
I want to detect when user press the Tab key in setup (e.g. when focus is being changed from one control to another).
Here is my code, but the MsgBox is never executed.
What am I doing wrong?
[Code]
procedure OnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
MsgBox('Hello.', mbInformation, MB_OK);
end;
procedure OnKeyPress(Sender: TObject; var Key: Char);
begin
MsgBox('Hello.', mbInformation, MB_OK);
end;
procedure OnKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
MsgBox('Hello.', mbInformation, MB_OK);
end;
procedure InitializeWizard();
begin
MainForm.OnKeyDown := #OnKeyDown;
MainForm.OnKeyPress := #OnKeyPress;
MainForm.OnKeyUp := #OnKeyUp;
end;
You should use WizardForm instead of MainForm and also set the KeyPreView to true:
procedure InitializeWizard();
begin
WizardForm.OnKeyDown := #OnKeyDown;
WizardForm.OnKeyPress := #OnKeyPress;
WizardForm.OnKeyUp := #OnKeyUp;
WizardForm.KeyPreview:=true;
end;
But I'm not sure if it catches Virtual Keys.
I have created some custom checkboxes in the finished page of Inno Setup.
For example launching an app, opening a text file etc.
I need when the user clicks on the finish button I check those checkboxes and do whatever that is needed. How can I do such a thing in Inno Setup?
Here is the code:
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
begin
Launch := TNewCheckBox.Create(WizardForm);
Launch.Parent := WizardForm;
Launch.Left := WizardForm.ClientWidth - 350;
Launch.Top := WizardForm.CancelButton.Top;
Launch.Width := 120;
Launch.Height := WizardForm.CancelButton.Height;
Launch.Caption := 'Launch';
end;
end;
In NextButtonClick event handler, test if your checkbox is checked and act accordingly.
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
Path: string;
Message: string;
begin
if CurPageID = wpFinished then
begin
if Launch.Checked then
begin
Path := ExpandConstant('{app}\MyProg.exe');
if ExecAsOriginalUser(Path, '', '', SW_SHOW, ewNoWait, ResultCode) then
begin
Log('Executed MyProg');
end
else
begin
Message := 'Error executing MyProg: ' + SysErrorMessage(ResultCode);
MsgBox(Message, mbError, MB_OK);
end;
end;
end;
Result := True;
end;
Simply check the checkbox state:
if (Launch.Checked = True) then
begin
// checkbox is checked
end
else
begin
// Checkbox is unchecked
end;
The best place is to use function NextButtonClick(CurPageID: Integer): Boolean;
however in that case you need to make your checkbox a global variable (so it is accessible).
I am new to INNO and getting better every but I am having a problem with the CreateInputQueryPage that is running after the install is complete. It is returning the initial values that I put in as the defaults, not the edited values the user has edited.
Here is the code that creates the page. This seems to be fine.
procedure InitializeWizard();
var
ret : boolean;
begin
SvrSetup := CreateInputQueryPage(wpInfoAfter,
'i2x Server setup', '',
'Please specify your Company name, Listener host name and Port. then click Next.');
SvrSetup.Add('Company name:', False);
SvrSetup.Add('Listener host name:', False);
SvrSetup.Add('Port:', False);
SvrSetup.Values[1] := 'computer name'
SvrSetup.Values[2] := '5551';
end;
I run this code on the NEXTBUTTONCLICK event to validate my input
function NextButtonClick(CurPageID: Integer): Boolean;
begin
Result := true;
{ Validate certain pages before allowing the user to proceed }
if CurPageID = SvrSetup.ID then
begin
if SvrSetup.Values[0] = '' then begin
MsgBox('You must enter company name.', mbError, MB_OK);
Result := False;
end;
if SvrSetup.Values[1] = '' then begin
MsgBox('You must enter listner host.', mbError, MB_OK);
Result := False;
end;
if SvrSetup.Values[2] = '' then begin
MsgBox('You must enter listner port.', mbError, MB_OK);
Result := False;
end;
end;
end;
Now when the install is over but before the final page I do this.
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
WriteXML;
end;
end;
And WriteXML is this.
procedure WriteXML;
var
FileData: String;
begin
FileData := ''
LoadStringFromFile(ExpandConstant('{app}\EMailer\EMailer.exe.config'), FileData);
StringChange(FileData, '!OVERRIDE_COMP!',ExpandConstant('{code:GetEmailerCompany}'));
SaveStringToFile(ExpandConstant('{app}\EMailer\EMailer.exe.config'), FileData, False);
end;
With the value I need to insert into the XML as code:GetEmailerCompanyas
function GetEmailerCompany(Param: String): String;
begin
// Return the company for email
Result := SvrSetup.Values[0];
end;
Aagain, It is returning the initial values that I put in as the defaults, not the edited values the user has edited. What am I missing?
Thanks
I'm trying to override Next/Cancel buttons on wpFinished page - NextButton should show downloaded file and exit the installator - it's working ok but CancelButton doesn't do nothing - it should close the installator with standard confirm. I wonder it is possible with standard inno events or I need to write own code to exit the application and show the confirm?
function NextButtonClick(CurPage: Integer): Boolean;
begin
if CurPage = wpFinished then begin
ShowDownloadedFile();
end;
Result := True;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then begin
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall);
WizardForm.CancelButton.Caption := SetupMessage(msgButtonFinish);
WizardForm.CancelButton.Visible := True;
end;
end;
Here it is, but don't do this at home kids :-)
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
[Code]
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess#kernel32.dll stdcall';
function NextButtonClick(CurPage: Integer): Boolean;
begin
Result := True;
// if the fake Finish button was clicked...
if CurPage = wpFinished then
MsgBox('Welcome to the next installation!', mbInformation, MB_OK);
end;
procedure CancelButtonClickFinishedPage(Sender: TObject);
begin
// display the "Exit Setup ?" message box and if the user selects "Yes",
// then exit the process; it is currently the only way how to exit setup
// process manually
if ExitSetupMsgBox then
ExitProcess(0);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpFinished then
begin
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall);
WizardForm.CancelButton.Caption := SetupMessage(msgButtonFinish);
WizardForm.CancelButton.Visible := True;
// bind your own OnClick event for the Cancel button; the original one
// is already disconnected at this stage
WizardForm.CancelButton.OnClick := #CancelButtonClickFinishedPage;
end;
end;
The proper alternative to what you're trying to do is to include a [Run] entry like so:
[Run]
Filename: {app}\yourfile.exe; Description: Run my application; Flags: postinstall nowait
This will display a checkbox on the wpFinished page giving them the choice to run the app or not.
within the inno setup compiler there are regions like:
[Setup]
DefaultDirName={pf}\cow1
function NextButtonClick(CurPageID: Integer): Boolean;
var
ExecInfo: TShellExecuteInfo;
begin
Result := True;
if CurPageID = wpFinished then
begin
ExecInfo.cbSize := SizeOf(ExecInfo);
ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfo.Wnd := 0;
ExecInfo.lpFile := DefaultDirName + '\{#Exewampmanager}';
ExecInfo.nShow := SW_HIDE;
if ShellExecuteEx(ExecInfo) then
begin
if WaitForSingleObject(ExecInfo.hProcess, 3000) = WAIT_TIMEOUT then
begin
TerminateProcess(ExecInfo.hProcess, 666);
MsgBox('You just killed a little kitty!', mbError, MB_OK);
end
else
MsgBox('The process was terminated in time!', mbInformation, MB_OK);
end;
end;
end;
how can i use the DefaultDirName const from the [Setup] region, within the function?
ps:
ExecInfo.lpFile := DefaultDirName + '\{#Exewampmanager}'; does not work
You must expand the constant, like:
ExpandConstant('{app}\myapp.exe')
where {app} is the final destination folder