[v3 windows] Add MessageBoxIndirect

This commit is contained in:
Lea Anthony 2023-06-06 20:39:24 +10:00
commit 23d7ac0e58
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
3 changed files with 49 additions and 0 deletions

28
v3/pkg/w32/dialogs.go Normal file
View file

@ -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(&params)),
)
if r == 0 {
return 0, err
}
return int32(r), nil
}

View file

@ -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

View file

@ -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),