使用Inno Setup中的轨迹栏控制系统音量

时间:2017-03-29 15:01:01

标签: inno-setup

如何使用Inno Setup中的轨迹栏控制系统音量?

使用bass.dll或mediaplayer.dll播放音乐,但如何使用轨迹栏控制系统音量以管理音量?

这些库可以使用转发和倒带选项吗?

1 个答案:

答案 0 :(得分:1)

Inno Setup中没有轨迹栏控件。

但您可以使用TBitmapImage绘制自己的交互式音量栏:

function GetCursorPos(var lpPoint: TPoint): BOOL;
  external 'GetCursorPos@user32.dll stdcall';
function ScreenToClient(hWnd: HWND; var lpPoint: TPoint): BOOL;
  external 'ScreenToClient@user32.dll stdcall';

procedure DrawVolume(Image: TBitmapImage; Volume: Integer);
var
  Canvas: TCanvas;
  Width: Integer;
begin
  Canvas := Image.Bitmap.Canvas;

  Canvas.Pen.Style := psClear;

  Width := Image.Bitmap.Width * Volume / 100

  Canvas.Brush.Color := clHighlight;
  Canvas.Rectangle(1, 1, Width, Image.Bitmap.Height);

  Canvas.Brush.Color := clBtnFace;
  Canvas.Rectangle(Width - 1, 1, Image.Bitmap.Width, Image.Bitmap.Height);

  Canvas.Pen.Style := psSolid;
  Canvas.Pen.Mode := pmCopy;
  Canvas.Pen.Color := clBlack;
  Canvas.Brush.Style := bsClear;
  Canvas.Rectangle(1, 1, Image.Bitmap.Width, Image.Bitmap.Height);
end;

procedure VolumeBarImageClick(Sender: TObject);
var
  P: TPoint;
  Image: TBitmapImage;
  Volume: Integer;
begin
  { Calculate where in the bar did user click to }
  GetCursorPos(P);
  Image := TBitmapImage(Sender);
  ScreenToClient(Image.Parent.Handle, P);
  Volume := ((P.X - Image.Left) * 100 / Image.Width) + 1;

  { Update volume bar }
  DrawVolume(Image, Volume);

  { Replace this with your code that sets the volume }
  MsgBox(Format('Setting volume to %d%%', [Volume]), mbInformation, MB_OK);
end;  

procedure InitializeWizard();
var
  VolumeBarImage: TBitmapImage;
begin
  VolumeBarImage := TBitmapImage.Create(WizardForm);
  VolumeBarImage.Parent := WizardForm;
  VolumeBarImage.Left := ScaleX(10);
  VolumeBarImage.Top := WizardForm.ClientHeight - ScaleY(34);
  VolumeBarImage.Width := ScaleX(200);
  VolumeBarImage.Height := ScaleY(20);
  VolumeBarImage.BackColor := clWhite;
  VolumeBarImage.Bitmap.Width := VolumeBarImage.Width;
  VolumeBarImage.Bitmap.Height := VolumeBarImage.Height;
  VolumeBarImage.OnClick := @VolumeBarImageClick;

  { Replace with setting to actual initial volume }
  DrawVolume(VolumeBarImage, 100);
end;

Volume bar

代码主要来自: