[英]Adding context menu to Inno Setup page
如何向 Inno Setup 的特定頁面添加一些上下文菜單?
例如在安裝頁面中,如果用戶在頁面上單擊鼠標右鍵,他可以看到“取消”或“暫停”菜單項,可以執行某些操作。
Inno Setup 沒有 API How 上下文菜單,甚至沒有用於處理鼠標點擊。 所以你需要實現一個自定義的 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 'CallWindowProcW@user32.dll stdcall';
function SetWindowLong(hWnd: HWND; nIndex: Integer; dwNewLong: LongInt): LongInt;
external 'SetWindowLongW@user32.dll stdcall';
function CreatePopupMenu: THandle; external 'CreatePopupMenu@User32.dll stdcall';
function InsertMenu(
hMenu: THandle; uPosition: Cardinal; uFlags: Cardinal; uIDNewItem: Cardinal;
lpNewItem: string): Boolean;
external 'InsertMenuW@User32.dll stdcall';
function TrackPopupMenu(
hMenu: THandle; uFlags: Cardinal; x: Integer; y: Integer; nReserved: Integer;
hWnd: THandle; Rect: Integer): Boolean;
external 'TrackPopupMenu@User32.dll stdcall';
function ClientToScreen(hWnd: HWND; var lpPoint: TPoint): Boolean;
external 'ClientToScreen@user32.dll 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;
GWL_WNDPROC
代碼基於Inno Setup - 如何編輯“關於設置”對話框文本框。
如果要添加圖標,請參閱將圖標圖像添加到 Inno Setup 中的上下文菜單。
對於CreateCallback
功能,你需要創新安裝6.如果你被卡住Inno Setup的5,你可以使用WrapCallback
功能從InnoTools InnoCallback庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.