From 23d7ac0e58f116d472e04ab61b312b13f4785a41 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Tue, 6 Jun 2023 20:39:24 +1000 Subject: [PATCH] [v3 windows] Add MessageBoxIndirect --- v3/pkg/w32/dialogs.go | 28 ++++++++++++++++++++++++++++ v3/pkg/w32/typedef.go | 13 +++++++++++++ v3/pkg/w32/user32.go | 8 ++++++++ 3 files changed, 49 insertions(+) create mode 100644 v3/pkg/w32/dialogs.go diff --git a/v3/pkg/w32/dialogs.go b/v3/pkg/w32/dialogs.go new file mode 100644 index 000000000..b3c57b0d6 --- /dev/null +++ b/v3/pkg/w32/dialogs.go @@ -0,0 +1,28 @@ +//go:build windows + +package w32 + +import ( + "unsafe" +) + +func MessageBoxWithIcon(hwnd HWND, text *uint16, caption *uint16, iconID int, flags uint32) (int32, error) { + + params := MSGBOXPARAMS{ + cbSize: uint32(unsafe.Sizeof(MSGBOXPARAMS{})), + hwndOwner: hwnd, + hInstance: 0, + lpszText: text, + lpszCaption: caption, + dwStyle: flags, + lpszIcon: (*uint16)(unsafe.Pointer(uintptr(iconID))), + } + + r, _, err := procMessageBoxIndirect.Call( + uintptr(unsafe.Pointer(¶ms)), + ) + if r == 0 { + return 0, err + } + return int32(r), nil +} diff --git a/v3/pkg/w32/typedef.go b/v3/pkg/w32/typedef.go index 219a7885f..6f55f0a26 100644 --- a/v3/pkg/w32/typedef.go +++ b/v3/pkg/w32/typedef.go @@ -476,6 +476,19 @@ type DIBSECTION struct { DsOffset uint32 } +type MSGBOXPARAMS struct { + cbSize uint32 + hwndOwner HWND + hInstance HANDLE + lpszText *uint16 + lpszCaption *uint16 + dwStyle uint32 + lpszIcon *uint16 + dwContextHelp uintptr + lpfnMsgBoxCallback uintptr + dwLanguageId uint32 +} + // http://msdn.microsoft.com/en-us/library/windows/desktop/dd162607.aspx type ENHMETAHEADER struct { IType uint32 diff --git a/v3/pkg/w32/user32.go b/v3/pkg/w32/user32.go index 65f4058dc..029f38143 100644 --- a/v3/pkg/w32/user32.go +++ b/v3/pkg/w32/user32.go @@ -67,6 +67,7 @@ var ( procReleaseCapture = moduser32.NewProc("ReleaseCapture") procGetWindowThreadProcessId = moduser32.NewProc("GetWindowThreadProcessId") procMessageBox = moduser32.NewProc("MessageBoxW") + procMessageBoxIndirect = moduser32.NewProc("MessageBoxIndirectW") procGetSystemMetrics = moduser32.NewProc("GetSystemMetrics") procPostThreadMessageW = moduser32.NewProc("PostThreadMessageW") procRegisterWindowMessageA = moduser32.NewProc("RegisterWindowMessageA") @@ -222,6 +223,13 @@ func LoadCursorWithResourceID(instance HINSTANCE, res uint16) HCURSOR { return HCURSOR(ret) } +func MessageBoxIndirect(msgbox *MSGBOXPARAMS) int32 { + ret, _, _ := procMessageBoxIndirect.Call( + uintptr(unsafe.Pointer(msgbox))) + + return int32(ret) +} + func ShowWindow(hwnd HWND, cmdshow int) bool { ret, _, _ := procShowWindow.Call( uintptr(hwnd),