Change the focused control on Inno Setup start - inno-setup

How can I change the focused control on welcome page? It is currently focused on NextButton. But I need to change it to CancelButton (or even any other buttons which I have added them programmatically like an About Button)
I tried this on InitializeWizard event:
WizardForm.ActiveControl := CancelButton;
CancelButton.Default := true;
but no success. Even I tried something described here: http://www.delphigroups.info/2/f3/324879.html
SendMessage(Handle, WM_NEXTDLGCTL, 0, 0 );
and no success.
How to solve this issue?

Changing wizard's ActiveControl in InitializeWizard is too early. It will get changed afterwards to the Next button.
Do it in the CurPageChanged(wpWelcome):
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpWelcome then
WizardForm.ActiveControl := WizardForm.CancelButton;
end;

Related

Changing background color of task list box and other controls in Inno Setup

In Inno Setup, I am trying to change the color of the setup to white. The problem is that when I try to do it by the Unicode version of installer, in the Select Additional Task Screen, I am getting grey section (screenshot is below). The important part is that when I move to next screen and comes back to that screen again, that grey section is gone.
I am using following code, based on Inno Setup: How to change background color.
procedure CurPageChanged(CurPageID: Integer);
begin
case CurPageID of
wpWelcome: WizardForm.Color := WizardForm.WelcomePage.Color;
wpFinished: WizardForm.Color := WizardForm.FinishedPage.Color;
wpLicense: WizardForm.InnerPage.Color := clWhite;
wpSelectDir: WizardForm.InnerPage.Color := clWhite;
wpSelectTasks: WizardForm.TasksList.Color := clWhite;
wpReady: WizardForm.ReadyMemo.Color := clWhite
else
WizardForm.Color := clWhite;
end;
end;
It seems that the checklist box does not repaint completely, when the color changes.
But actually your code is too complicated (and actually not even correct). You can set the color of all components directly in InitializeWizard, instead of CurPageChanged. This way, the list box has the correct color, when painted for the first time already.
procedure InitializeWizard();
begin
WizardForm.Color := clWhite;
WizardForm.InnerPage.Color := WizardForm.Color;
WizardForm.TasksList.Color := WizardForm.Color;
WizardForm.ReadyMemo.Color := WizardForm.Color;
end;
Note that Inno Setup 6 has modern wizard style:
[Setup]
WizardStyle=modern
It looks like this:

Inno Setup Detect changed task/item in TasksList.OnClickCheck event

I'm stuck on simple situation with OnClickCheck property. The problem is that I see a Msgbox every time I turn on backup task, but also (while it's switched on) OnClickCheckappeared on pressing uninst task too! Seems that OnClickCheck checks all clicks, but I need to check click only on the first task.
It is logical to add to "WizardForm.TasksList.OnClickCheck" exact number of task (WizardForm.TasksList.OnClickCheck[0]), but compiler doesn't agree with it.
[Tasks]
Name: backup; Description: do backup
Name: uninst; Description: do not create uninstaller
[Code]
procedure TaskOnClick(Sender: TObject);
begin
if IsTaskSelected('backup') then
begin
MsgBox('backup task has been checked.', mbInformation, MB_OK)
end;
end;
procedure InitializeWizard();
begin
WizardForm.TasksList.OnClickCheck := #TaskOnClick;
end;
There's no way tell exactly what task (list item) was changed in the OnClickCheck event.
To tell which item was checked by the user, you can use the ItemIndex property. The user can check only the selected item.
Though if you have a task hierarchy, even unselected task can be toggled automatically by the installer due to a change in child/parent items. So to tell all changes, all you can do is to remember the previous state and compare it against the current state, when the OnClickCheck is called.
var
TasksState: array of TCheckBoxState;
procedure TasksClickCheck(Sender: TObject);
var
I: Integer;
begin
for I := 0 to WizardForm.TasksList.Items.Count - 1 do
begin
if TasksState[I] <> WizardForm.TasksList.State[I] then
begin
Log(Format('Task %d state changed from %d to %d',
[I, TasksState[I], WizardForm.TasksList.State[I]]));
TasksState[I] := WizardForm.TasksList.State[I];
end;
end;
end;
procedure CurPageChanged(CurPageID: Integer);
var
I: Integer;
begin
if CurPageID = wpSelectTasks then
begin
{ Only now is the task list initialized (e.g. based on selected setup }
{ type and components). Remember what is the current/initial state. }
SetArrayLength(TasksState, WizardForm.TasksList.Items.Count);
for I := 0 to WizardForm.TasksList.Items.Count - 1 do
TasksState[I] := WizardForm.TasksList.State[I];
end;
end;
procedure InitializeWizard();
begin
WizardForm.TasksList.OnClickCheck := #TasksClickCheck;
end;
Instead of using indexes, you can also use task names with use of WizardSelectedTasks or WizardIsTaskSelected. For an example, see Inno Setup: how to auto select a component if another component is selected?
Also see:
Inno Setup ComponentsList OnClick event
Inno Setup Uncheck a task when another task is checked
Inno Setup - Show children component as sibling and show check instead of square in checkbox

Welcome page not showing, SelectDir page is showing first instead

I'm trying to make installer using Inno Setup.
And I want to show Welcome page first, then SelectDir.
This is CurPageChanged example code:
procedure CurPageChanged(CurPageID: integer);
begin
if CurPageID = wpWelcome then
begin
HideComponents;
WLabel.show;
WizardForm.NextButton.Show;
WizardForm.NextButton.Caption := 'Configure';
end;
if CurPageID = wpSelectDir then
begin
HideComponents;
BmpFile.Bitmap.LoadFromFile(ExpandConstant('{tmp}\2.bmp'));
WizardForm.DirEdit.Show;
WizardForm.NextButton.Show;
WizardForm.NextButton.Caption := 'Install';
WizardForm.DirBrowseButton.Show;
TasksSeparateBevel.Show;
TasksSeparateBevel2.Show;
InstallpathLabel.Show;
DiskSpaceLablel.Show;
ShortcutLabel.Show;
ShortcutCB.Show;
CreateDLabel.Show;
end;
if CurPageID = wpInstalling then
begin
HideComponents;
MakeSlideShow;
TimerID := SetTimer(0, 0, 10000, WrapTimerProc(#OnTimer, 4));
WizardForm.CancelButton.show;
WizardForm.ProgressGauge.show;
end;
end;
But the SelectDir shows first then Install. Welcome page does not show!
The Welcome page is by default skipped since Inno Setup 5.5.7:
As recommended by Microsoft's desktop applications guideline, DisableWelcomePage now defaults to yes. ... The defaults in all previous versions were no.
To show it, you have to set:
[Setup]
DisableWelcomePage=no
Thought as mentioned in the quote above, the defaults are recommended, so you should follow them.

The official Inno Setup code to change Next button to Install with DisableReadyPage directive does not work

I'm using the code from:
http://www.jrsoftware.org/ishelp/index.php?topic=setup_disablereadypage
It should change the Next button caption to Install when the "Ready" page is disabled using DisableReadyPage directive.
[Setup]
DisableReadyPage=yes
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectProgramGroup then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
But it does not change Next button caption.
As the description of the code says:
For example, if the new last pre-installation wizard page is the Select Program Group page: ...
In your case the last pre-installation page is not Select Program Group page. It's the Select Destination Location page. Probably because you have DisableProgramGroupPage set to no, or you have set it to auto and you are upgrading (the application is installed already).
If you have the DisableProgramGroupPage set to no, the solution is simple, as the Select Destination Location page is always the last. Just replace the wpSelectProgramGroup with wpSelectDir.
[Code]
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpSelectDir then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
With auto (the default), you do not get any of Select Program Group and Select Destination Location on upgrade, but you get the Ready to Install even with DisableProgramGroupPage (as there would not be any other page before installation). You can use that fact to use Install both for Select Program Group page (for fresh installs) and Ready to Install (for upgrades).
Another issue with their code is that you should get a Finish button on the "Finished" page (wpFinished). What their code does not care for.
The complete solution is:
procedure CurPageChanged(CurPageID: Integer);
begin
// On fresh install the last pre-install page is "Select Program Group".
// On upgrade the last pre-install page is "Read to Install"
// (forced even with DisableReadyPage)
if (CurPageID = wpSelectProgramGroup) or (CurPageID = wpReady) then
WizardForm.NextButton.Caption := SetupMessage(msgButtonInstall)
// On the Finished page, use "Finish" caption.
else if (CurPageID = wpFinished) then
WizardForm.NextButton.Caption := SetupMessage(msgButtonFinish)
// On all other pages, use "Next" caption.
else
WizardForm.NextButton.Caption := SetupMessage(msgButtonNext);
end;
Had you have other pages, like Tasks page, you would have to alter the code accordingly.
Your screenshot shows the wpSelectDir page while in your code you change the button of the wpSelectProgramGroup page.

Inno Setup remove/hide (not just disable) the Back button on a Wizard Page

I am aware that it is possible to disable (so it appears dimmed) the Back button on a Wizard Page using the following code:
procedure CurPageChanged(CurPageID: Integer);
begin
//Define whether the Back button is enabled
if CurPageID = UnlockCodePage.ID then
begin
WizardForm.BackButton.Enabled := False;
end;
end;
However, is there a way to actually completely remove/hide the Back button so that it can't be seen at all?
You should be able to use the Button.Visible property:
if CurPageID = UnlockCodePage.ID then
WizardForm.BackButton.Visible := False;

Resources