问题描述
我在这里使用脚本在Inno Setup页面上添加一些上下文菜单:
Adding context menu to Inno Setup page
解决方法
[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,LR_LOADFROMFILE or LR_CREATEDIBSECTION);
SetMenuItemBitmaps(Menu,MF_BYPOSITION,Bitmap,Bitmap);
end;
在Adding context menu to Inno Setup page中的代码中使用AddMenuItem
而不是InsertMenu
调用:
AddMenuItem(PopupMenu,ID_MUTE,'Mute','mute.bmp');
AddMenuItem(PopupMenu,1,ID_STOP,'Stop','stop.bmp');
以上显然假定您已将透明位图图像添加到安装程序中:
[Files]
Source: "mute.bmp"; Flags: dontcopy
Source: "stop.bmp"; Flags: dontcopy
我已经使用PixelFormer来创建透明的.bmp图像。