zenity/internal/win/shell32.go

238 lines
6.2 KiB
Go
Raw Normal View History

2022-06-17 22:45:49 -04:00
//go:build windows
package win
2022-06-21 19:58:14 -04:00
import (
"reflect"
"syscall"
"unsafe"
)
2022-06-17 22:45:49 -04:00
const (
2022-06-19 21:14:08 -04:00
BIF_RETURNONLYFSDIRS = 0x00000001
BFFM_INITIALIZED = 1
BFFM_SETSELECTION = WM_USER + 103
2022-06-17 22:45:49 -04:00
NIM_ADD = 0
NIM_DELETE = 2
)
// https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-browseinfow
type BROWSEINFO struct {
2022-06-18 07:37:39 -04:00
Owner HWND
2022-06-19 21:14:08 -04:00
Root Pointer
2022-06-17 22:45:49 -04:00
DisplayName *uint16
Title *uint16
Flags uint32
CallbackFunc uintptr
LParam *uint16
Image int32
}
// https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw
type NOTIFYICONDATA struct {
StructSize uint32
2022-06-18 07:37:39 -04:00
Wnd HWND
2022-06-17 22:45:49 -04:00
ID uint32
Flags uint32
CallbackMessage uint32
2022-06-18 07:37:39 -04:00
Icon Handle
2022-06-17 22:45:49 -04:00
Tip [128]uint16 // NOTIFYICONDATAA_V1_SIZE
State uint32
StateMask uint32
Info [256]uint16
Version uint32
InfoTitle [64]uint16
InfoFlags uint32
2022-06-18 07:37:39 -04:00
// GuidItem [16]byte // NOTIFYICONDATAA_V2_SIZE
// BalloonIcon Handle // NOTIFYICONDATAA_V3_SIZE
2022-06-17 22:45:49 -04:00
}
2022-06-21 19:58:14 -04:00
// https://github.com/wine-mirror/wine/blob/master/include/shobjidl.idl
var (
IID_IShellItem = uuid("\x1e\x6d\x82\x43\x18\xe7\xee\x42\xbc\x55\xa1\xe2\x61\xc3\x7b\xfe")
IID_IFileOpenDialog = uuid("\x88\x72\x7c\xd5\xad\xd4\x68\x47\xbe\x02\x9d\x96\x95\x32\xd9\x60")
CLSID_FileOpenDialog = uuid("\x9c\x5a\x1c\xdc\x8a\xe8\xde\x4d\xa5\xa1\x60\xf8\x2a\x20\xae\xf7")
)
type IFileOpenDialog struct {
_IFileOpenDialogBase
_ *_IFileOpenDialogVtbl
}
type _IFileOpenDialogBase struct{ _IFileDialogBase }
type _IFileOpenDialogVtbl struct {
_IFileDialogVtbl
GetResults uintptr
GetSelectedItems uintptr
}
func (c *_IFileOpenDialogBase) GetResults() (res *IShellItemArray, err error) {
vtbl := (*(**_IFileOpenDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetResults, uintptr(unsafe.Pointer(&res)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
type _IFileDialogBase struct{ _IModalWindowBase }
type _IFileDialogVtbl struct {
_IModalWindowVtbl
SetFileTypes uintptr
SetFileTypeIndex uintptr
GetFileTypeIndex uintptr
Advise uintptr
Unadvise uintptr
SetOptions uintptr
GetOptions uintptr
SetDefaultFolder uintptr
SetFolder uintptr
GetFolder uintptr
GetCurrentSelection uintptr
SetFileName uintptr
GetFileName uintptr
SetTitle uintptr
SetOkButtonLabel uintptr
SetFileNameLabel uintptr
GetResult uintptr
AddPlace uintptr
SetDefaultExtension uintptr
Close uintptr
SetClientGuid uintptr
ClearClientData uintptr
SetFilter uintptr
}
func (c *_IFileDialogBase) SetOptions(fos int) (err error) {
vtbl := (*(**_IFileDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.SetOptions, uintptr(fos))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
func (c *_IFileDialogBase) GetOptions() (fos int, err error) {
vtbl := (*(**_IFileDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetOptions, uintptr(unsafe.Pointer(&fos)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
func (c *_IFileDialogBase) SetFolder(item *IShellItem) (err error) {
vtbl := (*(**_IFileDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.SetFolder, uintptr(unsafe.Pointer(item)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
func (c *_IFileDialogBase) SetTitle(title *uint16) (err error) {
vtbl := (*(**_IFileDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.SetTitle, uintptr(unsafe.Pointer(title)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
func (c *_IFileDialogBase) GetResult() (item *IShellItem, err error) {
vtbl := (*(**_IFileDialogVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetResult, uintptr(unsafe.Pointer(&item)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
type _IModalWindowBase struct{ _IUnknownBase }
type _IModalWindowVtbl struct {
_IUnknownVtbl
Show uintptr
}
func (c *_IModalWindowBase) Show(wnd HWND) (err error) {
vtbl := (*(**_IModalWindowVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.Show, uintptr(wnd))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
2022-06-17 22:45:49 -04:00
type IShellItem struct {
2022-06-21 19:58:14 -04:00
_IShellItemBase
_ *_IShellItemVtbl
2022-06-17 22:45:49 -04:00
}
2022-06-21 19:58:14 -04:00
type _IShellItemBase struct{ _IUnknownBase }
2022-06-17 22:45:49 -04:00
type _IShellItemVtbl struct {
2022-06-21 19:58:14 -04:00
_IUnknownVtbl
2022-06-17 22:45:49 -04:00
BindToHandler uintptr
GetParent uintptr
GetDisplayName uintptr
GetAttributes uintptr
Compare uintptr
}
2022-06-21 19:58:14 -04:00
func (c *_IShellItemBase) GetDisplayName(name int) (res string, err error) {
var ptr uintptr
vtbl := (*(**_IShellItemVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetDisplayName, uintptr(name), uintptr(unsafe.Pointer(&ptr)))
if hr != 0 {
err = syscall.Errno(hr)
} else {
var buf []uint16
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf))
hdr.Data, hdr.Len, hdr.Cap = uintptr(ptr), 32768, 32768
res = syscall.UTF16ToString(buf)
}
return
}
type IShellItemArray struct {
_IShellItemArrayBase
_ *_IShellItemArrayVtbl
}
type _IShellItemArrayBase struct{ _IUnknownBase }
type _IShellItemArrayVtbl struct {
_IUnknownVtbl
BindToHandler uintptr
GetPropertyStore uintptr
GetPropertyDescriptionList uintptr
GetAttributes uintptr
GetCount uintptr
GetItemAt uintptr
EnumItems uintptr
}
func (c *_IShellItemArrayBase) GetCount() (numItems uint32, err error) {
vtbl := (*(**_IShellItemArrayVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetCount, uintptr(unsafe.Pointer(&numItems)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
func (c *_IShellItemArrayBase) GetItemAt(index uint32) (item *IShellItem, err error) {
vtbl := (*(**_IShellItemArrayVtbl)(unsafe.Pointer(c)))
hr, _, _ := c.Call(vtbl.GetItemAt, uintptr(index), uintptr(unsafe.Pointer(&item)))
if hr != 0 {
err = syscall.Errno(hr)
}
return
}
2022-06-21 09:27:19 -04:00
//sys SHBrowseForFolder(bi *BROWSEINFO) (ret Pointer) = shell32.SHBrowseForFolder
//sys SHCreateItemFromParsingName(path *uint16, bc *COMObject, iid uintptr, item **IShellItem) (res error) = shell32.SHCreateItemFromParsingName
2022-06-17 22:45:49 -04:00
//sys ShellNotifyIcon(message uint32, data *NOTIFYICONDATA) (ret int, err error) = shell32.Shell_NotifyIconW
2022-06-21 09:27:19 -04:00
//sys SHGetPathFromIDListEx(ptr Pointer, path *uint16, pathLen int, opts int) (ok bool) = shell32.SHGetPathFromIDListEx