Вопрос Как сделать отображение картинки компонента рядом с курсором, при наведении на него курсора

AmunRa

Мимокрокодил
Как сделать отображение картинки компонента рядом с курсором, при наведении на него курсора?
 

Вложения

Nemko

Дилетант
Модератор
AmunRa, как-то так c botva2:

Код:
[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={sd}\My Application

[Files]
Source: Files\*; Flags: dontcopy

[Components]
Name: comp1; Description: "Компонент 1";
Name: comp2; Description: "Компонент 2";
Name: comp3; Description: "Компонент 3";

[Modules]
#include "Modules\botva2.iss"

[Code]
var
  XY: Tpoint;
  Img: Longint;
  ComponetForm: TSetupForm;

procedure RepaintForm(FileName: String);
begin
  Img:=ImgLoad(ComponetForm.Handle, FileName, 0, 0, 0, 0, False, True);
  ComponetForm.Left:=WizardForm.Left+60+XY.X; ComponetForm.Top:=WizardForm.Top+187+XY.Y;
  ImgApplyChanges(ComponetForm.Handle);
  ComponetForm.Show;
end;

procedure ComponentsListItemMouseMove(Sender: TObject; X: Integer; Y: Integer; Index: Integer; Area: TItemArea);
begin
  XY.X:=X; XY.Y:=Y;
case Index of
  0: RepaintForm('1.jpg');
  1: RepaintForm('2.jpg');
  2: RepaintForm('3.jpg');
  else ComponetForm.Hide;
 end;
end;

procedure ComponetMouseMove(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
begin
  ComponetForm.Hide;
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\botva2.dll')) then ExtractTemporaryFile('botva2.dll');
  Result:=True;
end;

procedure InitializeWizard;
begin
 WizardForm.ComponentsList.OnItemMouseMove:=@ComponentsListItemMouseMove;
 ComponetForm:=CreateCustomForm;
 ComponetForm.BorderStyle:=bsNone;
 ComponetForm.Width:=ScaleX(326);
 ComponetForm.Height:=ScaleY(245);
 ComponetForm.OnMouseMove:=@ComponetMouseMove;
end;

procedure DeinitializeSetup;
begin
  gdipShutDown;
end;
 

Вложения

  • 80.7 KB Просмотры: 49

Nemko

Дилетант
Модератор
AmunRa, извините, не знаю ибо не интересуюсь WoT. Думаю стоит задать на форуме по моддингу WoT.
 

AmunRa

Мимокрокодил
AmunRa, как-то так c botva2:

Код:
[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={sd}\My Application

[Files]
Source: Files\*; Flags: dontcopy

[Components]
Name: comp1; Description: "Компонент 1";
Name: comp2; Description: "Компонент 2";
Name: comp3; Description: "Компонент 3";

[Modules]
#include "Modules\botva2.iss"

[Code]
var
  XY: Tpoint;
  Img: Longint;
  ComponetForm: TSetupForm;

procedure RepaintForm(FileName: String);
begin
  Img:=ImgLoad(ComponetForm.Handle, FileName, 0, 0, 0, 0, False, True);
  ComponetForm.Left:=WizardForm.Left+60+XY.X; ComponetForm.Top:=WizardForm.Top+187+XY.Y;
  ImgApplyChanges(ComponetForm.Handle);
  ComponetForm.Show;
end;

procedure ComponentsListItemMouseMove(Sender: TObject; X: Integer; Y: Integer; Index: Integer; Area: TItemArea);
begin
  XY.X:=X; XY.Y:=Y;
case Index of
  0: RepaintForm('1.jpg');
  1: RepaintForm('2.jpg');
  2: RepaintForm('3.jpg');
  else ComponetForm.Hide;
 end;
end;

procedure ComponetMouseMove(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
begin
  ComponetForm.Hide;
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\botva2.dll')) then ExtractTemporaryFile('botva2.dll');
  Result:=True;
end;

procedure InitializeWizard;
begin
 WizardForm.ComponentsList.OnItemMouseMove:=@ComponentsListItemMouseMove;
 ComponetForm:=CreateCustomForm;
 ComponetForm.BorderStyle:=bsNone;
 ComponetForm.Width:=ScaleX(326);
 ComponetForm.Height:=ScaleY(245);
 ComponetForm.OnMouseMove:=@ComponetMouseMove;
end;

procedure DeinitializeSetup;
begin
  gdipShutDown;
end;
AmunRa, как-то так c botva2:

Код:
[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={sd}\My Application

[Files]
Source: Files\*; Flags: dontcopy

[Components]
Name: comp1; Description: "Компонент 1";
Name: comp2; Description: "Компонент 2";
Name: comp3; Description: "Компонент 3";

[Modules]
#include "Modules\botva2.iss"

[Code]
var
  XY: Tpoint;
  Img: Longint;
  ComponetForm: TSetupForm;

procedure RepaintForm(FileName: String);
begin
  Img:=ImgLoad(ComponetForm.Handle, FileName, 0, 0, 0, 0, False, True);
  ComponetForm.Left:=WizardForm.Left+60+XY.X; ComponetForm.Top:=WizardForm.Top+187+XY.Y;
  ImgApplyChanges(ComponetForm.Handle);
  ComponetForm.Show;
end;

procedure ComponentsListItemMouseMove(Sender: TObject; X: Integer; Y: Integer; Index: Integer; Area: TItemArea);
begin
  XY.X:=X; XY.Y:=Y;
case Index of
  0: RepaintForm('1.jpg');
  1: RepaintForm('2.jpg');
  2: RepaintForm('3.jpg');
  else ComponetForm.Hide;
 end;
end;

procedure ComponetMouseMove(Sender: TObject; Shift: TShiftState; X: Integer; Y: Integer);
begin
  ComponetForm.Hide;
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\botva2.dll')) then ExtractTemporaryFile('botva2.dll');
  Result:=True;
end;

procedure InitializeWizard;
begin
 WizardForm.ComponentsList.OnItemMouseMove:=@ComponentsListItemMouseMove;
 ComponetForm:=CreateCustomForm;
 ComponetForm.BorderStyle:=bsNone;
 ComponetForm.Width:=ScaleX(326);
 ComponetForm.Height:=ScaleY(245);
 ComponetForm.OnMouseMove:=@ComponetMouseMove;
end;

procedure DeinitializeSetup;
begin
  gdipShutDown;
end;
Nemko, Nemko, Nemko,
Как сделать отображение картинки компонента рядом с курсором, при наведении на него курсора.



И всетаки с Botva2 картинки тормозят при наведении на них мышки и скролл не работает, пока не нажмешь на окно установщика...
 

Nemko

Дилетант
Модератор
AmunRa, я думал сами "до шлифуете". Ну вот, вроде стало быстрее (файлы те же):

Код:
[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={sd}\My Application

[Files]
Source: Files\*; Flags: dontcopy

[Components]
Name: comp1; Description: "Компонент 1";
Name: comp2; Description: "Компонент 2";
Name: comp3; Description: "Компонент 3";
Name: comp4; Description: "Компонент 3";
Name: comp5; Description: "Компонент 3";
Name: comp6; Description: "Компонент 3";
Name: comp7; Description: "Компонент 3";
Name: comp8; Description: "Компонент 3";

[Modules]
#include "Modules\botva2.iss"

[Code]
const
  GWL_EXSTYLE      =  (-20);
  WS_EX_COMPOSITED =  $2000000;

var
  Img: Longint;
  PauseInt: DWORD;
  ShortPause: TTimer;
  ComponetForm: TSetupForm;

function GetWindowLong(Wnd: HWnd; Index: Integer): Longint; external 'GetWindowLongA@user32.dll stdcall';
function SetWindowLong(Wnd: HWnd; Index: Integer; NewLong: Longint): Longint; external 'SetWindowLongA@user32.dll stdcall';
function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND; X, Y, cx, cy: Integer; uFlags: UINT): BOOL; external 'SetWindowPos@user32.dll stdcall';

procedure ProcPause(Sender: Tobject);
begin
  PauseInt:=PauseInt+1;
end;

procedure RepaintForm(FileName: String; X, Y: Integer);
var
  s: String;
begin
ShortPause.Enabled:=True;
if PauseInt <> 0 then begin
  if s <> FileName then begin
  Img:=ImgLoad(ComponetForm.Handle, FileName, 0, 0, 0, 0, False, True);
  ImgApplyChanges(ComponetForm.Handle); s:=FileName;
end;
  SetWindowPos(ComponetForm.Handle, 0, WizardForm.Left+60+X, WizardForm.Top+187+Y, 0, 0, $515);
  if not ComponetForm.Showing then ComponetForm.Show;
  if not WizardForm.ComponentsList.Focused then WizardForm.ComponentsList.SetFocus;
  ShortPause.Enabled:=False; PauseInt:=0;
 end;
end;

procedure ComponentsListItemMouseMove(Sender: TObject; X: Integer; Y: Integer; Index: Integer; Area: TItemArea);
begin
case Index of
  0: RepaintForm('1.jpg', X, Y);
  1: RepaintForm('2.jpg', X, Y);
  2: RepaintForm('3.jpg', X, Y);
  else ComponetForm.Hide;
 end;end;


procedure HideComponetForm(Sender: TObject);
begin
  ComponetForm.Hide;
  ShortPause.Enabled:=True;
end;

procedure InitializeWizard;
begin
  ComponetForm:=CreateCustomForm;
  ComponetForm.BorderStyle:=bsNone;
  ComponetForm.Width:=ScaleX(326);
  ComponetForm.Height:=ScaleY(245);
  ComponetForm.FormStyle:=fsStayOnTop;
  WizardForm.ComponentsList.OnMouseLeave:=@HideComponetForm;
  WizardForm.ComponentsList.OnItemMouseMove:=@ComponentsListItemMouseMove;
  SetWindowLong(WizardForm.ComponentsList.Handle, GWL_EXSTYLE, GetWindowLong(WizardForm.ComponentsList.Handle, GWL_EXSTYLE) or WS_EX_COMPOSITED);

ShortPause:=TTimer.Create(nil);
with ShortPause do begin
  Interval:=1;
  OnTimer:=@ProcPause;
 end;
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\botva2.dll')) then ExtractTemporaryFile('botva2.dll');
  Result:=True;
end;

procedure DeinitializeSetup;
begin
  gdipShutDown;
end;

P.S.: Была страшная утечка памяти, стало лучше, но все равно много поедает.
 
Последнее редактирование:

AmunRa

Мимокрокодил
Так наверно лучше... чем с Botva

Код:
[Setup]
AppName=My Program
AppVerName=My Program v.1.2
DefaultDirName={pf}\My Program
Compression=none
AppId=TheBestAppId
DisableWelcomePage=yes
DisableFinishedPage=yes
DisableDirPage=yes
DisableReadyPage=yes


[Components]
Name: kp1; Description: Компонент1; Flags: disablenouninstallwarning
Name: kp1\1; Description: Компонент1.1; Flags: disablenouninstallwarning exclusive
Name: kp1\2; Description: Компонент1.2; Flags: disablenouninstallwarning exclusive

Name: kp2; Description: Компонент2; Flags: disablenouninstallwarning
Name: kp2\1; Description: Компонент2.1; Flags: disablenouninstallwarning exclusive
Name: kp2\2; Description: Компонент2.2; Flags: disablenouninstallwarning exclusive

Name: kp3; Description: Компонент3; Flags: disablenouninstallwarning
Name: kp3\1; Description: Компонент3.1; Flags: disablenouninstallwarning exclusive
Name: kp3\2; Description: Компонент3.2; Flags: disablenouninstallwarning exclusive

Name: kp4; Description: Компонент4; Flags: disablenouninstallwarning
Name: kp4\1; Description: Компонент4.1; Flags: disablenouninstallwarning exclusive
Name: kp4\2; Description: Компонент4.2; Flags: disablenouninstallwarning exclusive

[Types]
Name: full; Description: Full installation; Flags: iscustom

[Files]
Source: 1.bmp; Flags: dontcopy nocompression
Source: 2.bmp; Flags: dontcopy nocompression
Source: 3.bmp; Flags: dontcopy nocompression
Source: 4.bmp; Flags: dontcopy nocompression


[code]
#ifdef UNICODE
    #define A "W"
#else
    #define A "A"
#endif

const
    UNDEF_INDEX = -777;
    ALPHA_BLEND_LEVEL = 255; // max=Byte=255

    WS_EX_LAYERED = $80000;
    WS_EX_TRANSPARENT = $20;
    LWA_COLORKEY = 1;
    LWA_ALPHA = 2;
    GWL_EXSTYLE = (-20);


var
    InfoPic: TBitmapImage;
    LastIndex: Integer;
    TempPath: String;
    PicForm: TForm;


type
    COLORREF = DWORD;


function GetCursorPos(var lpPoint: TPoint): BOOL; external 'GetCursorPos@user32.dll stdcall';
function SetLayeredWindowAttributes(Hwnd: THandle; crKey: COLORREF; bAlpha: Byte; dwFlags: DWORD): Boolean; external 'SetLayeredWindowAttributes@user32.dll stdcall';
function GetWindowLong(hWnd: HWND; nIndex: Integer): Longint; external 'GetWindowLong{#A}@user32.dll stdcall';
function SetWindowLong(hWnd: HWND; nIndex: Integer; dwNewLong: Longint): Longint; external 'SetWindowLong{#A}@user32.dll stdcall';
function SetFocus(hWnd: HWND): HWND; external 'SetFocus@user32.dll stdcall';


procedure ShowPicHint(const PicFilePath: String);
var
    pt: TPoint;
begin
    if not GetCursorPos(pt) then Exit;
    InfoPic.Bitmap.LoadFromFile(PicFilePath);
    try
        with PicForm do
        begin
            SetBounds(ScaleX(pt.x + 160), ScaleY(pt.y + 7), InfoPic.Width, InfoPic.Height);
            Show;
        end;
    finally
        SetFocus(WizardForm.Handle);
    end;
end;


procedure CompOnItemMouseMove(Sender: TObject; X, Y: Integer; Index: Integer; Area: TItemArea);
var
    UndefPic: String;
begin
    if Index = -1 then Exit;
    if Index = LastIndex then Exit;
    try
        case TNewCheckListBox(Sender).ItemCaption[Index] of
            'Компонент1.1': UndefPic := '1.bmp';
            'Компонент1.2': UndefPic := '1.bmp';
            'Компонент2.1': UndefPic := '2.bmp';
            'Компонент2.2': UndefPic := '2.bmp';
            'Компонент3.1': UndefPic := '3.bmp';
            'Компонент3.2': UndefPic := '3.bmp';
            'Компонент4.1': UndefPic := '4.bmp';
            'Компонент4.2': UndefPic := '4.bmp';
        else
            begin
                LastIndex := UNDEF_INDEX;
                PicForm.Hide;
                Exit;
            end;
        end;
        if not FileExists(TempPath + UndefPic) then ExtractTemporaryFile(UndefPic);
        ShowPicHint(TempPath + UndefPic);
    finally
        LastIndex := Index;
    end;
end;


procedure CompOnMouseLeave(Sender: TObject);
begin
    PicForm.Hide;
    LastIndex := -1;
end;


procedure InitInfo();
begin
    WizardForm.ComponentsList.OnItemMouseMove := @CompOnItemMouseMove;
    WizardForm.ComponentsList.OnMouseLeave := @CompOnMouseLeave;
    TempPath := AddBackslash(ExpandConstant('{tmp}'));
    LastIndex := UNDEF_INDEX;
    PicForm := TForm.Create(WizardForm)
    with PicForm do
    begin
        BorderStyle := bsNone;
        FormStyle := fsStayOnTop;
        InfoPic := TBitmapImage.Create(PicForm)
        with InfoPic do
        begin
            Parent := PicForm;
            AutoSize := True;
        end;
    end;
    SetWindowLong(PicForm.Handle, GWL_EXSTYLE, GetWindowLong(PicForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
    SetLayeredWindowAttributes(PicForm.Handle, 0, ALPHA_BLEND_LEVEL, LWA_ALPHA);
end;


procedure InitializeWizard();
begin
    InitInfo();
end;
 

sergy2010

Мимокрокодил
AmunRa, я думал сами "до шлифуете". Ну вот, вроде стало быстрее (файлы те же):

Код:
[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={sd}\My Application

[Files]
Source: Files\*; Flags: dontcopy

[Components]
Name: comp1; Description: "Компонент 1";
Name: comp2; Description: "Компонент 2";
Name: comp3; Description: "Компонент 3";
Name: comp4; Description: "Компонент 3";
Name: comp5; Description: "Компонент 3";
Name: comp6; Description: "Компонент 3";
Name: comp7; Description: "Компонент 3";
Name: comp8; Description: "Компонент 3";

[Modules]
#include "Modules\botva2.iss"

[Code]
const
  GWL_EXSTYLE      =  (-20);
  WS_EX_COMPOSITED =  $2000000;

var
  Img: Longint;
  PauseInt: DWORD;
  ShortPause: TTimer;
  ComponetForm: TSetupForm;

function GetWindowLong(Wnd: HWnd; Index: Integer): Longint; external 'GetWindowLongA@user32.dll stdcall';
function SetWindowLong(Wnd: HWnd; Index: Integer; NewLong: Longint): Longint; external 'SetWindowLongA@user32.dll stdcall';
function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND; X, Y, cx, cy: Integer; uFlags: UINT): BOOL; external 'SetWindowPos@user32.dll stdcall';

procedure ProcPause(Sender: Tobject);
begin
  PauseInt:=PauseInt+1;
end;

procedure RepaintForm(FileName: String; X, Y: Integer);
var
  s: String;
begin
ShortPause.Enabled:=True;
if PauseInt <> 0 then begin
  if s <> FileName then begin
  Img:=ImgLoad(ComponetForm.Handle, FileName, 0, 0, 0, 0, False, True);
  ImgApplyChanges(ComponetForm.Handle); s:=FileName;
end;
  SetWindowPos(ComponetForm.Handle, 0, WizardForm.Left+60+X, WizardForm.Top+187+Y, 0, 0, $515);
  if not ComponetForm.Showing then ComponetForm.Show;
  if not WizardForm.ComponentsList.Focused then WizardForm.ComponentsList.SetFocus;
  ShortPause.Enabled:=False; PauseInt:=0;
 end;
end;

procedure ComponentsListItemMouseMove(Sender: TObject; X: Integer; Y: Integer; Index: Integer; Area: TItemArea);
begin
case Index of
  0: RepaintForm('1.jpg', X, Y);
  1: RepaintForm('2.jpg', X, Y);
  2: RepaintForm('3.jpg', X, Y);
  else ComponetForm.Hide;
 end;end;


procedure HideComponetForm(Sender: TObject);
begin
  ComponetForm.Hide;
  ShortPause.Enabled:=True;
end;

procedure InitializeWizard;
begin
  ComponetForm:=CreateCustomForm;
  ComponetForm.BorderStyle:=bsNone;
  ComponetForm.Width:=ScaleX(326);
  ComponetForm.Height:=ScaleY(245);
  ComponetForm.FormStyle:=fsStayOnTop;
  WizardForm.ComponentsList.OnMouseLeave:=@HideComponetForm;
  WizardForm.ComponentsList.OnItemMouseMove:=@ComponentsListItemMouseMove;
  SetWindowLong(WizardForm.ComponentsList.Handle, GWL_EXSTYLE, GetWindowLong(WizardForm.ComponentsList.Handle, GWL_EXSTYLE) or WS_EX_COMPOSITED);

ShortPause:=TTimer.Create(nil);
with ShortPause do begin
  Interval:=1;
  OnTimer:=@ProcPause;
 end;
end;

function InitializeSetup:boolean;
begin
  if not FileExists(ExpandConstant('{tmp}\botva2.dll')) then ExtractTemporaryFile('botva2.dll');
  Result:=True;
end;

procedure DeinitializeSetup;
begin
  gdipShutDown;
end;

P.S.: Была страшная утечка памяти, стало лучше, но все равно много поедает.

А можно чтоб ComponetForm авторазмер под картинку сама делала типа autosize:= true;
 
Сверху