Adding an icon image to context menu in Inno Setup

Issue

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?

Solution

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 '[email protected] stdcall';  
function SetMenuItemBitmaps(
  hMenu: THandle; uPosition: Cardinal; uFlags: Cardinal;
  hBitmapUnchecked: THandle; hBitmapChecked: THandle): Boolean;
  external '[email protected] 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.

enter image description here

Answered By – Martin Prikryl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published