Reputation: 67
I want to make a simple installation script with Inno Setup. How can I load a custom .cur
or .ani
cursor file while setup is started? Thanks.
UPDATE: Changing standard cursors code is working well with .cur
files but animated cursor files (.ani
) are not animating when installer started. Is there any solution for this? Thanks.
Upvotes: 1
Views: 903
Reputation: 202642
Depends, what cursors you want to change. You may want to change some of the standard cursors. Or the default (normal) cursor of some (or all) installer window controls.
Changing standard cursors
You can hardly change these for the installer process only, without using some external DLL library.
With Inno Setup itself only, you can change a system cursors. But this will affect all other applications, while the installer is running.
[Files]
Source: "MyCursor.cur"; Flags: dontcopy
[Code]
const
OCR_NORMAL = 32512;
function SetSystemCursor(hcur: LongWord; id: DWORD): BOOL;
external '[email protected] stdcall';
function LoadCursorFromFile(lpFileName: string): LongWord;
external '[email protected] stdcall';
function CopyIcon(hIcon: LongWord): LongWord;
external '[email protected] stdcall';
function LoadCursor(hInstance: LongWord; lpCursorName: LongWord): LongWord;
external '[email protected] stdcall';
var
OriginalCursor: LongWord;
procedure InitializeWizard();
var
PathToCursorFile: string;
Cursor: LongWord;
begin
// Remember the original custom
OriginalCursor := CopyIcon(LoadCursor(0, OCR_NORMAL));
// Load our cursor
ExtractTemporaryFile('MyCursor.cur')
PathToCursorFile := ExpandConstant('{tmp}\MyCursor.cur');
Cursor := LoadCursorFromFile(PathToCursorFile);
SetSystemCursor(Cursor, OCR_NORMAL);
end;
procedure DeinitializeSetup();
begin
// Restore original cursor on exit
SetSystemCursor(OriginalCursor, OCR_NORMAL);
end;
Changing default (normal) cursor of some (or all) installer window controls
[Files]
Source: "MyCursor.cur"; Flags: dontcopy
[Code]
const
GCL_HCURSOR = (-12);
function LoadCursorFromFile(lpFileName: string): LongWord;
external '[email protected] stdcall';
function SetClassLong(hWnd: HWND; Index, NewLong: Longint): Longint;
external 'SetClassLongA@user32 stdcall';
procedure InitializeWizard();
var
PathToCursorFile: string;
Cursor: LongWord;
begin
ExtractTemporaryFile('MyCursor.cur')
PathToCursorFile := ExpandConstant('{tmp}\MyCursor.cur');
Cursor := LoadCursorFromFile(PathToCursorFile);
SetClassLong(WizardForm.NextButton.Handle, GCL_HCURSOR, Cursor);
end;
The above code changes cursor for the Next button. If you want to use the same custom cursor for all control, you can iterate the control tree.
procedure SetControlsCursor(Control: TWinControl; Cursor: LongWord);
var
I: Integer;
begin
SetClassLong(Control.Handle, GCL_HCURSOR, Cursor);
for I := 0 to Control.ControlCount - 1 do
begin
if Control.Controls[I] is TWinControl then
begin
SetControlsCursor(TWinControl(Control.Controls[I]), Cursor);
end;
end;
end;
procedure InitializeWizard();
...
begin
...
SetControlsCursor(WizardForm, Cursor);
end;
Upvotes: 2