Inno Setup 没有上下文菜单 API,甚至没有用于处理鼠标点击的 API。所以你需要实现一个自定义的Windows消息处理程序并处理WM_CONTEXTMENU
.
[Code]
const
GWL_WNDPROC = -4;
WM_CONTEXTMENU = $007B;
WM_COMMAND = $0111;
type
WPARAM = UINT_PTR;
LPARAM = LongInt;
LRESULT = LongInt;
const
MF_BYPOSITION = $0400;
MF_STRING = $0000;
const
ID_MUTE = 0;
ID_STOP = 1;
function CallWindowProc(
lpPrevWndFunc: LongInt; hWnd: HWND; Msg: UINT; wParam: WPARAM;
lParam: LPARAM): LRESULT; external '[email protected] stdcall';
function SetWindowLong(hWnd: HWND; nIndex: Integer; dwNewLong: LongInt): LongInt;
external '[email protected] stdcall';
function CreatePopupMenu: THandle; external '[email protected] stdcall';
function InsertMenu(
hMenu: THandle; uPosition: Cardinal; uFlags: Cardinal; uIDNewItem: Cardinal;
lpNewItem: string): Boolean;
external '[email protected] stdcall';
function TrackPopupMenu(
hMenu: THandle; uFlags: Cardinal; x: Integer; y: Integer; nReserved: Integer;
hWnd: THandle; Rect: Integer): Boolean;
external '[email protected] stdcall';
function ClientToScreen(hWnd: HWND; var lpPoint: TPoint): Boolean;
external '[email protected] stdcall';
var
OldPageWndProc: LongInt;
Page: TWizardPage;
function GET_X_LPARAM(dw: DWORD): WORD; // aka LOWORD
begin
Result := WORD(dw);
end;
function GET_Y_LPARAM(dw: DWORD): WORD; // aka HIWORD
begin
Result := WORD((dw shr 16) and $FFFF);
end;
function PageWndProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;
var
PopupMenu: THandle;
X, Y: Integer;
begin
if uMsg = WM_CONTEXTMENU then
begin
X := GET_X_LPARAM(lParam);
Y := GET_Y_LPARAM(lParam);
PopupMenu := CreatePopupMenu();
InsertMenu(PopupMenu, -1, MF_BYPOSITION or MF_STRING, ID_MUTE, 'Mute');
InsertMenu(PopupMenu, -1, MF_BYPOSITION or MF_STRING, ID_STOP, 'Stop');
TrackPopupMenu(PopupMenu, 0, X, Y, 0, Page.Surface.Handle, 0);
end
else
if uMsg = WM_COMMAND then
begin
if wParam = ID_MUTE then
begin
MsgBox('Muting', mbInformation, MB_OK);
Result := 0;
end
else
if wParam = ID_STOP then
begin
MsgBox('Stopping', mbInformation, MB_OK);
Result := 0;
end;
end
else
begin
Result := CallWindowProc(OldPageWndProc, hwnd, uMsg, wParam, lParam);
end;
end;
procedure InitializeWizard();
begin
Page := CreateCustomPage(wpWelcome, 'Page with context menu', '');
OldPageWndProc :=
SetWindowLong(Page.Surface.Handle, GWL_WNDPROC, CreateCallback(@PageWndProc));
end;
procedure DeinitializeSetup;
begin
SetWindowLong(Page.Surface.Handle, GWL_WNDPROC, OldPageWndProc);
end;
The GWL_WNDPROC
代码基于Inno Setup - 如何编辑“关于安装”对话框文本框.
如果您想添加图标,请参阅将图标图像添加到 Inno Setup 中的上下文菜单.
For CreateCallback功能,您需要 Inno Setup 6。如果您无法使用 Inno Setup 5,您可以使用WrapCallback
函数来自InnoTools InnoCallback图书馆。