3

Is it possible to check the position of ScrollBar in wpLicense Page in Inno Setup without having to write custom memo page?

e.g.

procedure CurPageChanged(CurPageID: Integer);
 begin

     if CurPageID = wpLicense then
        WizardForm.LicenseAcceptedRadio.Enabled := False;
        WizardForm.LicenseNotAcceptedRadio.Enabled := False;

     if ScrollBar.Position := ScrollBar.Max then
        WizardForm.LicenseAcceptedRadio.Enabled := True;
        WizardForm.LicenseNotAcceptedRadio.Enabled := True;
  end;
RobeN
  • 5,346
  • 1
  • 33
  • 50

2 Answers2

4

There is no direct access to those scroll bars, however you can use the GetScrollInfo function this way:

[code]
const
  SB_VERT = 1;
  SIF_RANGE = 1;
  SIF_POS = 4;
  SIF_PAGE = 2;

type
  TScrollInfo = record
    cbSize: UINT;
    fMask: UINT;
    nMin: Integer;
    nMax: Integer;
    nPage: UINT;
    nPos: Integer;
    nTrackPos: Integer;
  end;

function GetScrollInfo(hWnd: HWND; BarFlag: Integer; 
  var ScrollInfo: TScrollInfo): BOOL;
  external 'GetScrollInfo@user32.dll stdcall';

procedure CurPageChanged(CurPageID: Integer);
var
  ScrollInfo: TScrollInfo;
begin
  if CurPageID = wpLicense then
  begin
    ScrollInfo.cbSize := SizeOf(ScrollInfo);
    ScrollInfo.fMask := SIF_RANGE or SIF_POS or SIF_PAGE;
    if GetScrollInfo(WizardForm.LicenseMemo.Handle, SB_VERT, ScrollInfo) then
      if ScrollInfo.nPos = ScrollInfo.nMax - ScrollInfo.nPage then
        MsgBox('You are at the end of the license!', mbInformation, MB_OK);
  end;
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • I just wanted to ask about it. It is easy to wrap the function up with CallBack to repeat check in time. But in this state you would have to set the length basing on License file. It may be tricky though because of e.g. Fonts DPI in Windows. – RobeN May 14 '12 at 14:35
  • 1
    I'm not sure I get your last comment however this should be DPI independent (because the memo itself does this for you). And the `LicenseMemo` is ready to be used since the `InitializeWizard` event fires. – TLama May 15 '12 at 07:32
2

That is what I have now. It works, however if you find any issues, just say as I like comments.

procedure OnScrollPosition(Wnd: HWND; Msg: UINT; TimerID: UINT_PTR; 
  SysTime: DWORD);
  var
    ScrollInfo: TScrollInfo;
begin
  ScrollInfo.cbSize := SizeOf(ScrollInfo);
  ScrollInfo.fMask := SIF_RANGE or SIF_POS or SIF_PAGE;
    if GetScrollInfo(WizardForm.LicenseMemo.Handle, SB_VERT, ScrollInfo) then
       if ScrollInfo.nPos = ScrollInfo.nMax - ScrollInfo.nPage then
          begin
            WizardForm.LicenseAcceptedRadio.Enabled := True;
            WizardForm.LicenseNotAcceptedRadio.Enabled := True;
          end;
end;

procedure ScrollPosition();
var
  TimerCallback: LongWord;
begin
  TimerCallback := WrapTimerProc(@OnScrollPosition, 4);
  TimerID := SetTimer(0, 0, 500, TimerCallback);
end;

procedure CurPageChanged(CurPageID: Integer);
var
  ScrollInfo: TScrollInfo;
begin
   if CurPageID = wpInstalling then
     StartSlideTimer
   else
     KillSlideTimer;
if CurPageID = wpLicense then
  WizardForm.LicenseAcceptedRadio.Enabled := False;
  WizardForm.LicenseNotAcceptedRadio.Enabled := False;
  ScrollPosition
end;
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • 1
    In fact you want to allow users accept the license only when they read the license to the end. It a harm that InnoSetup doesn't have a support for redirecting `WndProc`. You would be easily able to catch `WM_VSCROLL`. – TLama May 15 '12 at 08:19