1. Уважаемые гости и пользователи форума.
    Администрация настоятельно рекомендует не регистрировать несколько аккаунтов для одного пользователя. При выявлении наличия мультиаккаунтов будут заблокированы все учетные записи данного пользователя.
    Аккаунты, зарегистрированные на временную почту будут также заблокированы.

FAQ FAQ по Inno Setup

Тема в разделе "Inno Setup", создана пользователем Shegorat, 16 июн 2011.

Метки:
  1. Ветеран Модератор

    Регистрация:
    26 июн 2011
    Сообщения:
    1.049
    Симпатии:
    700
    В: Как вывести ComboBox с дисками?
    О: Так (спасибо El Sanchez)
    Код (Inno):
    [Setup]
    AppName=Example
    AppVerName=Example 1.0
    DefaultDirName={pf}\Example
    OutputDir=.

    [Code]
    #define A = (Defined UNICODE) ? "W" : "A"
    const
        DRIVE_NO_ROOT_DIR = 1;
        DRIVE_FIXED = 3;

    var
        cbDrive: TComboBox;

    function GetLogicalDrives: DWORD; external 'GetLogicalDrives@kernel32.dll stdcall';
    function GetDriveType(lpRootPathName: string): UINT; external 'GetDriveType{#A}@kernel32.dll stdcall';

    procedure cbDriveOnClick(Sender: TObject);
    var
        DirValue: string;
    begin
        DirValue := WizardDirValue;
        StringChangeEx(DirValue, AddBackslash(ExtractFileDrive(DirValue)), cbDrive.Items[cbDrive.ItemIndex], True);
        WizardForm.DirEdit.Text := DirValue;
    end;

    procedure DirEditOnChange(Sender: TObject);
    var
        i: Integer;
    begin
        for i := 0 to cbDrive.Items.Count - 1 do
        begin
            if CompareText(cbDrive.Items[i], AddBackslash(ExtractFileDrive(WizardDirValue))) = 0 then
            begin
                cbDrive.ItemIndex := i;
                Break;
            end;
        end;
    end;

    procedure FillCombo;
    var
        dwDrives: DWORD;
        uDriveType: UINT;
        szDriveLetter: string;
        i: Integer;
    begin
        dwDrives := GetLogicalDrives;
        for i := 2 to 25 do if dwDrives and (1 shl i) <> 0 then
        begin
            szDriveLetter := Chr(Ord('A') + i) + ':\';
            uDriveType := GetDriveType(szDriveLetter);
            case uDriveType of
                DRIVE_FIXED:
                    begin
                        cbDrive.Items.Add(szDriveLetter);
                        if CompareText(cbDrive.Items[cbDrive.Items.Count - 1], AddBackslash(ExtractFileDrive(WizardDirValue))) = 0 then
                            cbDrive.ItemIndex := cbDrive.Items.Count - 1;
                    end;
                DRIVE_NO_ROOT_DIR: Continue;
            end;
        end;
    end;

    procedure InitializeWizard;
    begin
        WizardForm.DirEdit.OnChange := @DirEditOnChange;
        cbDrive := TComboBox.Create(WizardForm.SelectDirPage);
        with cbDrive do
        begin
            Parent := WizardForm.DirEdit.Parent;
            Top := WizardForm.DirEdit.Top + WizardForm.DirEdit.Height + ScaleY(5);
            Width := 40;
            Style := csDropDownList;
            OnClick := @cbDriveOnClick;
            FillCombo;
        end;
    end;
     
    Последнее редактирование: 11 фев 2018
    Nemko и YURSHAT нравится это.
  2. Ветеран

    Регистрация:
    28 май 2013
    Сообщения:
    49
    Симпатии:
    7
    В: Как определить системный диск SSD или HDD?
    О: Примерно так (Спасибо El Sanchez)
    Код (Inno):

    [Setup]
    AppName=test
    AppVerName=test
    CreateAppDir=no
    DefaultDirName={tmp}
    Uninstallable=no
    CreateUninstallRegKey=no

    [Languages]
    Name: ru; MessagesFile: compiler:Languages\russian.isl

    [Code]
    #define A = (Defined UNICODE) ? "W" : "A"
    const
      GENERIC_READ = $80000000;
      GENERIC_WRITE = $40000000;
      FILE_SHARE_READ = $1;
      FILE_SHARE_WRITE = $2;
      OPEN_EXISTING = 3;
      INVALID_HANDLE_VALUE = -1;
      IOCTL_ATA_PASS_THROUGH = $0004D02C;
      ATA_FLAGS_DRDY_REQUIRED = $0001;
      ATA_FLAGS_DATA_IN = $0002;
      ID_CMD = $EC;

    type
      TATAPassThroughEx = record
        Length: WORD;
        AtaFlags: WORD;
        PathId: Byte;
        TargetId: Byte;
        Lun: Byte;
        ReservedAsUchar: Byte;
        DataTransferLength: DWORD;
        TimeOutValue: DWORD;
        ReservedAsUlong: DWORD;
        DataBufferOffset: DWORD;
        PreviousTaskFile: array [0..7] of Byte;
        CurrentTaskFile: array [0..7] of Byte;
      end;

      TATAIdentifyDeviceQuery = record
        Header: TATAPassThroughEx;
        Data: array [0..255] of WORD;
      end;

    // Device Management Functions
    function DeviceIoControlATAIdentifyDeviceQuery(hDevice: THandle; dwIoControlCode: DWORD; var lpInBuffer: TATAIdentifyDeviceQuery; nInBufferSize: DWORD; out lpOutBuffer: TATAIdentifyDeviceQuery; nOutBufferSize: DWORD; out lpBytesReturned: DWORD; lpOverlapped: DWORD): BOOL; external 'DeviceIoControl@kernel32.dll stdcall';

    // File Management Functions
    function CreateFile(lpFileName: string; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: Longint; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; external 'CreateFile{#A}@kernel32.dll stdcall';

    // Handle and Object Functions
    function CloseHandle(hObject: THandle): BOOL; external 'CloseHandle@kernel32.dll stdcall';

    /////////////////////////////////////////////////////////
    function IsDriveSSD(const ADriveLetter: string): Boolean;
    var
      BytesReturned: DWORD;
      DeviceHandle: THandle;
      ATAIdentifyDeviceQuery: TATAIdentifyDeviceQuery;
    begin
      Result := False;
      try
        DeviceHandle := CreateFile(Format('\\.\%s', [ADriveLetter]), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
        if DeviceHandle = INVALID_HANDLE_VALUE then
          RaiseException(SysErrorMessage(DLLGetLastError));

        ATAIdentifyDeviceQuery.Header.Length := SizeOf(ATAIdentifyDeviceQuery.Header);
        ATAIdentifyDeviceQuery.Header.AtaFlags := ATA_FLAGS_DATA_IN or ATA_FLAGS_DRDY_REQUIRED;
        ATAIdentifyDeviceQuery.Header.DataTransferLength := SizeOf(ATAIdentifyDeviceQuery.Data);
        ATAIdentifyDeviceQuery.Header.TimeOutValue := 3;
        ATAIdentifyDeviceQuery.Header.DataBufferOffset := SizeOf(ATAIdentifyDeviceQuery.Header);
        ATAIdentifyDeviceQuery.Header.CurrentTaskFile[6{ = Command/Status register }] := ID_CMD; // ATA IDENTIFY DEVICE command

        if not DeviceIoControlATAIdentifyDeviceQuery(DeviceHandle, IOCTL_ATA_PASS_THROUGH, ATAIdentifyDeviceQuery, SizeOf(ATAIdentifyDeviceQuery), ATAIdentifyDeviceQuery, SizeOf(ATAIdentifyDeviceQuery), BytesReturned, 0) then
        begin
          Log(Format('DeviceIoControl failed: %s', [SysErrorMessage(DLLGetLastError)]));
          Exit;
        end;
        Result := ATAIdentifyDeviceQuery.Data[{ Word }217{: Nominal media rotation rate }] = 1;
      finally
        if DeviceHandle > 0 then
          CloseHandle(DeviceHandle);
      end;
    end;

    ///////////////////////////
    procedure InitializeWizard;
    begin
      if IsDriveSSD(ExpandConstant('{sd}')) then
        MsgBox('SSD', mbInformation, MB_OK)
      else
        MsgBox('No SSD', mbInformation, MB_OK);
    end;

     
     
    Simorq и sergey3695 нравится это.
  3. Ветеран Модератор

    Регистрация:
    26 июн 2011
    Сообщения:
    1.049
    Симпатии:
    700
    В: Как сделать анимированный баннер?
    О: Так (спасибо El Sanchez)
    Код (Inno):
    [Setup]
    AppName=test
    AppVerName=test
    DefaultDirName={tmp}
    Uninstallable=no
    CreateUninstallRegKey=no
    OutputDir=.

    [Languages]
    Name: ru; MessagesFile: compiler:Languages\russian.isl

    [Files]
    Source: "giphy.gif"; Flags: dontcopy solidbreak

    [Code]
    #define A = (Defined UNICODE) ? "W" : "A"
    const
      WS_CHILD = $40000000;
      WS_VISIBLE = $10000000;
      WS_DISABLED = $08000000;

    // ATL Functions
    function AtlAxWinInit: BOOL; external 'AtlAxWinInit@atl.dll stdcall';
    function AtlAxCreateControl(lpszName: string; hWnd: HWND; pStream, ppUnkContainer: Longint): HResult; external 'AtlAxCreateControl@atl.dll stdcall';

    // Window Functions
    function GetSysColor(nIndex: Integer): DWORD; external 'GetSysColor@user32.dll stdcall';
    function CreateWindowEx(dwExStyle: DWORD; lpClassName, lpWindowName: string; dwStyle: DWORD; x, y, nWidth, nHeight: Integer; hWndParent: HWND; hMenu: HMENU; hInstance, lpParam: Longint): HWND; external 'CreateWindowEx{#A}@user32.dll stdcall';
    function DestroyWindow(hWnd: HWND): BOOL; external 'DestroyWindow@user32.dll stdcall';

    var
      GIFWndHandle: HWND;

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function ShowAnimatedGIF(AWndParent: HWND; ALeft, ATop, AWidth, AHeight: Integer; AUrl: string; AColor: TColor): HWND;
    (*
    Parameters:
      AWndParent...: A handle to the parent window
      ALeft........: The initial horizontal position of the window
      ATop.........: The initial vertical position of the window
      AWidth.......: The width of the window
      AHeight......: The height of the window
      AUrl.........: The URL or full path of the GIF file
      AColor.......: Color background
    Return value:
      A handle to ActiveX control host window
    *)

    var
      HTMLStr: string;
      ResultCode: HResult;
    begin
      if not AtlAxWinInit then Exit;
      Result := CreateWindowEx(0, 'AtlAxWin', '', WS_CHILD or WS_VISIBLE or WS_DISABLED, ALeft, ATop, AWidth, AHeight, AWndParent, 0, 0, 0);
      if Result = 0 then
        RaiseException(SysErrorMessage(DLLGetLastError));

      if AColor < 0 then
        AColor := GetSysColor(AColor and $0000FF);
      HTMLStr := Format('about:<html><body leftmargin="0" topmargin="0" scroll="no" bgcolor="#%.2x%.2x%.2x"><p align="center"><img src="%s" height="100%%"></img></p></body></html>', [AColor and $0000FF, AColor and $00FF00 shr 8, AColor and $FF0000 shr 16, AUrl]);

      ResultCode := AtlAxCreateControl(HTMLStr, Result, 0, 0);
      if ResultCode <> 0 then
        RaiseException(SysErrorMessage(ResultCode));
    end;

    ///////////////////////////
    procedure InitializeWizard;
    begin
      ExtractTemporaryFile('giphy.gif');
      GIFWndHandle := ShowAnimatedGIF(WizardForm.SelectDirPage.Handle,
        0, WizardForm.DirEdit.Top + WizardForm.DirEdit.Height + ScaleY(5), WizardForm.SelectDirPage.Width, WizardForm.DiskSpaceLabel.Top - WizardForm.DirEdit.Top - WizardForm.DirEdit.Height - ScaleY(5),
         ExpandConstant('{tmp}\giphy.gif'), WizardForm.SelectDirPage.Color);
    end;

    ////////////////////////////
    procedure DeinitializeSetup;
    begin
      if GIFWndHandle <> 0 then
        DestroyWindow(GIFWndHandle);
    end;
     
     
    Хамик и Nemko нравится это.
  4. Ветеран Модератор

    Регистрация:
    26 июн 2011
    Сообщения:
    1.049
    Симпатии:
    700
    В: Как сделать HexToStr и StrToHex?
    О: Так
    Код (Inno):
    [Setup]
    AppName=test
    AppVerName=test
    DefaultDirName={tmp}
    Uninstallable=no
    CreateUninstallRegKey=no
    OutputDir=.

    [Languages]
    Name: ru; MessagesFile: compiler:Languages\russian.isl

    [Code]
    function HexToStr(str_hex: string): string;
    var
      i: Integer;
    begin
      Result:= '';
      StringChange(str_hex, ',', '');
      for i:= 1 to Length(str_hex) div 2 do
        Result:= Result +  Chr(StrToInt('$' + Copy(str_hex, (i-1)*2+1, 2)));
    end;

    function StrToHex(str: string): string;
    var
      i: Integer;
    begin
      Result:= '';
      for i:= 1 to Length(str) do
        Result:= Result +  Format('%.2x', [Ord(str[i]), Ord(str[i])]);
    end;

    procedure InitializeWizard;
    var
      S: string;
    begin
      S := HexToStr('6D6F757365');
      MsgBox(S, mbInformation, MB_OK);
      S := StrToHex('mouse');
      MsgBox(S, mbInformation, MB_OK);
    end;
     
     
    Хамик нравится это.

Поделиться этой страницей