简体   繁体   中英

Adding an icon image to context menu in Inno Setup

I'm using the script here to add some context menu to my Inno Setup pages:
Adding context menu to Inno Setup page

is there any way to add an icon image to every menu item?

Use SetMenuItemBitmaps :

[Code]
const
  IMAGE_BITMAP = 0;
  LR_LOADFROMFILE = $10;
  LR_CREATEDIBSECTION = $2000;

function LoadImage(
  hInst: Integer; ImageName: string; ImageType: UINT; X, Y: Integer;
  Flags: UINT): THandle; external 'LoadImageW@User32.dll stdcall';  
function SetMenuItemBitmaps(
  hMenu: THandle; uPosition: Cardinal; uFlags: Cardinal;
  hBitmapUnchecked: THandle; hBitmapChecked: THandle): Boolean;
  external 'SetMenuItemBitmaps@User32.dll stdcall';

procedure AddMenuItem(
  Menu: THandle; Position: Integer; ID: Integer; Caption: string;
  ImageFileName: string);
var
  Bitmap: THandle;
begin
  InsertMenu(Menu, Position, MF_BYPOSITION or MF_STRING, ID, Caption);
  ExtractTemporaryFile(ImageFileName);
  Bitmap := LoadImage(
    0, ExpandConstant('{tmp}\') + ImageFileName, IMAGE_BITMAP, 0, 0,
    LR_LOADFROMFILE or LR_CREATEDIBSECTION);
  SetMenuItemBitmaps(Menu, Position, MF_BYPOSITION, Bitmap, Bitmap);
end;

Use the AddMenuItem instead of InsertMenu calls in the code from Adding context menu to Inno Setup page :

AddMenuItem(PopupMenu, 0, ID_MUTE, 'Mute', 'mute.bmp');
AddMenuItem(PopupMenu, 1, ID_STOP, 'Stop', 'stop.bmp');

The above obviously assumes, that you have the transparent bitmap images added to the installer:

[Files]
Source: "mute.bmp"; Flags: dontcopy
Source: "stop.bmp"; Flags: dontcopy

I've used PixelFormer to create the transparent .bmp images.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM