diff --git a/AUTHORS b/AUTHORS index 86b306ba..3b767637 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,11 +10,25 @@ # ============ Alexander Neumann +Aman Gupta Anton Lahti Benny Siegert +Brad Fitzpatrick +Bruno Bigras +Carl Kittelberger +Carlos Cobo Cary Cherng +Cory Redmond +David Porter +Dmitry Bagdanov +gonutz Hill +Jason A. Donenfeld +Joseph Watson Kevin Pors +ktye mycaosf +ryujimiya +Simon Rozman +Tiago Carvalho wsf01 - diff --git a/advapi32.go b/advapi32.go index 9853eb6a..4420ffbd 100644 --- a/advapi32.go +++ b/advapi32.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -53,30 +56,30 @@ const ( var ( // Library - libadvapi32 uintptr + libadvapi32 *windows.LazyDLL // Functions - regCloseKey uintptr - regOpenKeyEx uintptr - regQueryValueEx uintptr - regEnumValue uintptr - regSetValueEx uintptr + regCloseKey *windows.LazyProc + regOpenKeyEx *windows.LazyProc + regQueryValueEx *windows.LazyProc + regEnumValue *windows.LazyProc + regSetValueEx *windows.LazyProc ) func init() { // Library - libadvapi32 = MustLoadLibrary("advapi32.dll") + libadvapi32 = windows.NewLazySystemDLL("advapi32.dll") // Functions - regCloseKey = MustGetProcAddress(libadvapi32, "RegCloseKey") - regOpenKeyEx = MustGetProcAddress(libadvapi32, "RegOpenKeyExW") - regQueryValueEx = MustGetProcAddress(libadvapi32, "RegQueryValueExW") - regEnumValue = MustGetProcAddress(libadvapi32, "RegEnumValueW") - regSetValueEx = MustGetProcAddress(libadvapi32, "RegSetValueExW") + regCloseKey = libadvapi32.NewProc("RegCloseKey") + regOpenKeyEx = libadvapi32.NewProc("RegOpenKeyExW") + regQueryValueEx = libadvapi32.NewProc("RegQueryValueExW") + regEnumValue = libadvapi32.NewProc("RegEnumValueW") + regSetValueEx = libadvapi32.NewProc("RegSetValueExW") } func RegCloseKey(hKey HKEY) int32 { - ret, _, _ := syscall.Syscall(regCloseKey, 1, + ret, _, _ := syscall.Syscall(regCloseKey.Addr(), 1, uintptr(hKey), 0, 0) @@ -85,7 +88,7 @@ func RegCloseKey(hKey HKEY) int32 { } func RegOpenKeyEx(hKey HKEY, lpSubKey *uint16, ulOptions uint32, samDesired REGSAM, phkResult *HKEY) int32 { - ret, _, _ := syscall.Syscall6(regOpenKeyEx, 5, + ret, _, _ := syscall.Syscall6(regOpenKeyEx.Addr(), 5, uintptr(hKey), uintptr(unsafe.Pointer(lpSubKey)), uintptr(ulOptions), @@ -97,7 +100,7 @@ func RegOpenKeyEx(hKey HKEY, lpSubKey *uint16, ulOptions uint32, samDesired REGS } func RegQueryValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 { - ret, _, _ := syscall.Syscall6(regQueryValueEx, 6, + ret, _, _ := syscall.Syscall6(regQueryValueEx.Addr(), 6, uintptr(hKey), uintptr(unsafe.Pointer(lpValueName)), uintptr(unsafe.Pointer(lpReserved)), @@ -109,7 +112,7 @@ func RegQueryValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpType *uint32, } func RegEnumValue(hKey HKEY, index uint32, lpValueName *uint16, lpcchValueName *uint32, lpReserved, lpType *uint32, lpData *byte, lpcbData *uint32) int32 { - ret, _, _ := syscall.Syscall9(regEnumValue, 8, + ret, _, _ := syscall.Syscall9(regEnumValue.Addr(), 8, uintptr(hKey), uintptr(index), uintptr(unsafe.Pointer(lpValueName)), @@ -123,7 +126,7 @@ func RegEnumValue(hKey HKEY, index uint32, lpValueName *uint16, lpcchValueName * } func RegSetValueEx(hKey HKEY, lpValueName *uint16, lpReserved, lpDataType uint64, lpData *byte, cbData uint32) int32 { - ret, _, _ := syscall.Syscall6(regSetValueEx, 6, + ret, _, _ := syscall.Syscall6(regSetValueEx.Addr(), 6, uintptr(hKey), uintptr(unsafe.Pointer(lpValueName)), uintptr(lpReserved), diff --git a/combobox.go b/combobox.go index 8a3fdb0b..3fdc782c 100644 --- a/combobox.go +++ b/combobox.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // ComboBox return values diff --git a/comctl32.go b/comctl32.go index f25fb936..144affa7 100644 --- a/comctl32.go +++ b/comctl32.go @@ -1,12 +1,16 @@ -// Copyright 2010 The win Authors. All rights reserved. +// Copyright 2016 The win Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( "syscall" "unsafe" + + "golang.org/x/sys/windows" ) // Button control messages @@ -23,6 +27,7 @@ const ( BCM_SETNOTE = BCM_FIRST + 0x0009 BCM_GETNOTE = BCM_FIRST + 0x000A BCM_GETNOTELENGTH = BCM_FIRST + 0x000B + BCM_SETSHIELD = BCM_FIRST + 0x000C ) const ( @@ -80,24 +85,25 @@ const ( // WM_NOTITY messages const ( - NM_FIRST = 0 - NM_OUTOFMEMORY = NM_FIRST - 1 - NM_CLICK = NM_FIRST - 2 - NM_DBLCLK = NM_FIRST - 3 - NM_RETURN = NM_FIRST - 4 - NM_RCLICK = NM_FIRST - 5 - NM_RDBLCLK = NM_FIRST - 6 - NM_SETFOCUS = NM_FIRST - 7 - NM_KILLFOCUS = NM_FIRST - 8 - NM_CUSTOMDRAW = NM_FIRST - 12 - NM_HOVER = NM_FIRST - 13 - NM_NCHITTEST = NM_FIRST - 14 - NM_KEYDOWN = NM_FIRST - 15 - NM_RELEASEDCAPTURE = NM_FIRST - 16 - NM_SETCURSOR = NM_FIRST - 17 - NM_CHAR = NM_FIRST - 18 - NM_TOOLTIPSCREATED = NM_FIRST - 19 - NM_LAST = NM_FIRST - 99 + NM_FIRST = 0 + NM_OUTOFMEMORY = ^uint32(0) // NM_FIRST - 1 + NM_CLICK = ^uint32(1) // NM_FIRST - 2 + NM_DBLCLK = ^uint32(2) // NM_FIRST - 3 + NM_RETURN = ^uint32(3) // NM_FIRST - 4 + NM_RCLICK = ^uint32(4) // NM_FIRST - 5 + NM_RDBLCLK = ^uint32(5) // NM_FIRST - 6 + NM_SETFOCUS = ^uint32(6) // NM_FIRST - 7 + NM_KILLFOCUS = ^uint32(7) // NM_FIRST - 8 + NM_CUSTOMDRAW = ^uint32(11) // NM_FIRST - 12 + NM_HOVER = ^uint32(12) // NM_FIRST - 13 + NM_NCHITTEST = ^uint32(13) // NM_FIRST - 14 + NM_KEYDOWN = ^uint32(14) // NM_FIRST - 15 + NM_RELEASEDCAPTURE = ^uint32(15) // NM_FIRST - 16 + NM_SETCURSOR = ^uint32(16) // NM_FIRST - 17 + NM_CHAR = ^uint32(17) // NM_FIRST - 18 + NM_TOOLTIPSCREATED = ^uint32(18) // NM_FIRST - 19 + NM_LAST = ^uint32(98) // NM_FIRST - 99 + TRBN_THUMBPOSCHANGING = 0xfffffa22 // TRBN_FIRST - 1 ) // ProgressBar messages @@ -106,13 +112,39 @@ const ( PBM_DELTAPOS = WM_USER + 3 PBM_SETSTEP = WM_USER + 4 PBM_STEPIT = WM_USER + 5 + PBM_SETMARQUEE = WM_USER + 10 PBM_SETRANGE32 = 1030 PBM_GETRANGE = 1031 PBM_GETPOS = 1032 PBM_SETBARCOLOR = 1033 PBM_SETBKCOLOR = CCM_SETBKCOLOR - PBS_SMOOTH = 1 - PBS_VERTICAL = 4 +) + +// ProgressBar styles +const ( + PBS_SMOOTH = 0x01 + PBS_VERTICAL = 0x04 + PBS_MARQUEE = 0x08 +) + +// TrackBar (Slider) messages +const ( + TBM_GETPOS = WM_USER + TBM_GETRANGEMIN = WM_USER + 1 + TBM_GETRANGEMAX = WM_USER + 2 + TBM_SETPOS = WM_USER + 5 + TBM_SETRANGEMIN = WM_USER + 7 + TBM_SETRANGEMAX = WM_USER + 8 + TBM_SETPAGESIZE = WM_USER + 21 + TBM_GETPAGESIZE = WM_USER + 22 + TBM_SETLINESIZE = WM_USER + 23 + TBM_GETLINESIZE = WM_USER + 24 +) + +// TrackBar (Slider) styles +const ( + TBS_VERT = 0x002 + TBS_TOOLTIPS = 0x100 ) // ImageList creation flags @@ -130,25 +162,78 @@ const ( ILC_PERITEMMIRROR = 0x00008000 ) +// ImageList_Draw[Ex] flags +const ( + ILD_NORMAL = 0x00000000 + ILD_TRANSPARENT = 0x00000001 + ILD_BLEND25 = 0x00000002 + ILD_BLEND50 = 0x00000004 + ILD_MASK = 0x00000010 + ILD_IMAGE = 0x00000020 + ILD_SELECTED = ILD_BLEND50 + ILD_FOCUS = ILD_BLEND25 + ILD_BLEND = ILD_BLEND50 +) + +// LoadIconMetric flags +const ( + LIM_SMALL = 0 + LIM_LARGE = 1 +) + +const ( + CDDS_PREPAINT = 0x00000001 + CDDS_POSTPAINT = 0x00000002 + CDDS_PREERASE = 0x00000003 + CDDS_POSTERASE = 0x00000004 + CDDS_ITEM = 0x00010000 + CDDS_ITEMPREPAINT = CDDS_ITEM | CDDS_PREPAINT + CDDS_ITEMPOSTPAINT = CDDS_ITEM | CDDS_POSTPAINT + CDDS_ITEMPREERASE = CDDS_ITEM | CDDS_PREERASE + CDDS_ITEMPOSTERASE = CDDS_ITEM | CDDS_POSTERASE + CDDS_SUBITEM = 0x00020000 +) + const ( - CDDS_PREPAINT = 0x00000001 - CDDS_ITEM = 0x00010000 - CDDS_ITEMPREPAINT = CDDS_ITEM | CDDS_PREPAINT + CDIS_SELECTED = 0x0001 + CDIS_GRAYED = 0x0002 + CDIS_DISABLED = 0x0004 + CDIS_CHECKED = 0x0008 + CDIS_FOCUS = 0x0010 + CDIS_DEFAULT = 0x0020 + CDIS_HOT = 0x0040 + CDIS_MARKED = 0x0080 + CDIS_INDETERMINATE = 0x0100 + CDIS_SHOWKEYBOARDCUES = 0x0200 + CDIS_NEARHOT = 0x0400 + CDIS_OTHERSIDEHOT = 0x0800 + CDIS_DROPHILITED = 0x1000 ) const ( CDRF_DODEFAULT = 0x00000000 CDRF_NEWFONT = 0x00000002 CDRF_SKIPDEFAULT = 0x00000004 + CDRF_DOERASE = 0x00000008 CDRF_NOTIFYPOSTPAINT = 0x00000010 CDRF_NOTIFYITEMDRAW = 0x00000020 CDRF_NOTIFYSUBITEMDRAW = 0x00000020 CDRF_NOTIFYPOSTERASE = 0x00000040 + CDRF_SKIPPOSTPAINT = 0x00000100 +) + +const ( + LVIR_BOUNDS = 0 + LVIR_ICON = 1 + LVIR_LABEL = 2 + LVIR_SELECTBOUNDS = 3 ) const ( LPSTR_TEXTCALLBACK = ^uintptr(0) I_CHILDRENCALLBACK = -1 + I_IMAGECALLBACK = -1 + I_IMAGENONE = -2 ) type HIMAGELIST HANDLE @@ -169,39 +254,38 @@ type NMCUSTOMDRAW struct { var ( // Library - libcomctl32 uintptr + libcomctl32 *windows.LazyDLL // Functions - imageList_Add uintptr - imageList_AddMasked uintptr - imageList_Create uintptr - imageList_Destroy uintptr - imageList_ReplaceIcon uintptr - initCommonControlsEx uintptr + imageList_Add *windows.LazyProc + imageList_AddMasked *windows.LazyProc + imageList_Create *windows.LazyProc + imageList_Destroy *windows.LazyProc + imageList_DrawEx *windows.LazyProc + imageList_ReplaceIcon *windows.LazyProc + initCommonControlsEx *windows.LazyProc + loadIconMetric *windows.LazyProc + loadIconWithScaleDown *windows.LazyProc ) func init() { // Library - libcomctl32 = MustLoadLibrary("comctl32.dll") + libcomctl32 = windows.NewLazySystemDLL("comctl32.dll") // Functions - imageList_Add = MustGetProcAddress(libcomctl32, "ImageList_Add") - imageList_AddMasked = MustGetProcAddress(libcomctl32, "ImageList_AddMasked") - imageList_Create = MustGetProcAddress(libcomctl32, "ImageList_Create") - imageList_Destroy = MustGetProcAddress(libcomctl32, "ImageList_Destroy") - imageList_ReplaceIcon = MustGetProcAddress(libcomctl32, "ImageList_ReplaceIcon") - initCommonControlsEx = MustGetProcAddress(libcomctl32, "InitCommonControlsEx") - - // Initialize the common controls we support - var initCtrls INITCOMMONCONTROLSEX - initCtrls.DwSize = uint32(unsafe.Sizeof(initCtrls)) - initCtrls.DwICC = ICC_LISTVIEW_CLASSES | ICC_PROGRESS_CLASS | ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES - - InitCommonControlsEx(&initCtrls) + imageList_Add = libcomctl32.NewProc("ImageList_Add") + imageList_AddMasked = libcomctl32.NewProc("ImageList_AddMasked") + imageList_Create = libcomctl32.NewProc("ImageList_Create") + imageList_Destroy = libcomctl32.NewProc("ImageList_Destroy") + imageList_DrawEx = libcomctl32.NewProc("ImageList_DrawEx") + imageList_ReplaceIcon = libcomctl32.NewProc("ImageList_ReplaceIcon") + initCommonControlsEx = libcomctl32.NewProc("InitCommonControlsEx") + loadIconMetric = libcomctl32.NewProc("LoadIconMetric") + loadIconWithScaleDown = libcomctl32.NewProc("LoadIconWithScaleDown") } func ImageList_Add(himl HIMAGELIST, hbmImage, hbmMask HBITMAP) int32 { - ret, _, _ := syscall.Syscall(imageList_Add, 3, + ret, _, _ := syscall.Syscall(imageList_Add.Addr(), 3, uintptr(himl), uintptr(hbmImage), uintptr(hbmMask)) @@ -210,7 +294,7 @@ func ImageList_Add(himl HIMAGELIST, hbmImage, hbmMask HBITMAP) int32 { } func ImageList_AddMasked(himl HIMAGELIST, hbmImage HBITMAP, crMask COLORREF) int32 { - ret, _, _ := syscall.Syscall(imageList_AddMasked, 3, + ret, _, _ := syscall.Syscall(imageList_AddMasked.Addr(), 3, uintptr(himl), uintptr(hbmImage), uintptr(crMask)) @@ -219,7 +303,7 @@ func ImageList_AddMasked(himl HIMAGELIST, hbmImage HBITMAP, crMask COLORREF) int } func ImageList_Create(cx, cy int32, flags uint32, cInitial, cGrow int32) HIMAGELIST { - ret, _, _ := syscall.Syscall6(imageList_Create, 5, + ret, _, _ := syscall.Syscall6(imageList_Create.Addr(), 5, uintptr(cx), uintptr(cy), uintptr(flags), @@ -231,7 +315,7 @@ func ImageList_Create(cx, cy int32, flags uint32, cInitial, cGrow int32) HIMAGEL } func ImageList_Destroy(hIml HIMAGELIST) bool { - ret, _, _ := syscall.Syscall(imageList_Destroy, 1, + ret, _, _ := syscall.Syscall(imageList_Destroy.Addr(), 1, uintptr(hIml), 0, 0) @@ -239,8 +323,26 @@ func ImageList_Destroy(hIml HIMAGELIST) bool { return ret != 0 } +func ImageList_DrawEx(himl HIMAGELIST, i int32, hdcDst HDC, x, y, dx, dy int32, rgbBk COLORREF, rgbFg COLORREF, fStyle uint32) bool { + ret, _, _ := syscall.Syscall12(imageList_DrawEx.Addr(), 10, + uintptr(himl), + uintptr(i), + uintptr(hdcDst), + uintptr(x), + uintptr(y), + uintptr(dx), + uintptr(dy), + uintptr(rgbBk), + uintptr(rgbFg), + uintptr(fStyle), + 0, + 0) + + return ret != 0 +} + func ImageList_ReplaceIcon(himl HIMAGELIST, i int32, hicon HICON) int32 { - ret, _, _ := syscall.Syscall(imageList_ReplaceIcon, 3, + ret, _, _ := syscall.Syscall(imageList_ReplaceIcon.Addr(), 3, uintptr(himl), uintptr(i), uintptr(hicon)) @@ -249,10 +351,40 @@ func ImageList_ReplaceIcon(himl HIMAGELIST, i int32, hicon HICON) int32 { } func InitCommonControlsEx(lpInitCtrls *INITCOMMONCONTROLSEX) bool { - ret, _, _ := syscall.Syscall(initCommonControlsEx, 1, + ret, _, _ := syscall.Syscall(initCommonControlsEx.Addr(), 1, uintptr(unsafe.Pointer(lpInitCtrls)), 0, 0) return ret != 0 } + +func LoadIconMetric(hInstance HINSTANCE, lpIconName *uint16, lims int32, hicon *HICON) HRESULT { + if loadIconMetric.Find() != nil { + return HRESULT(0) + } + ret, _, _ := syscall.Syscall6(loadIconMetric.Addr(), 4, + uintptr(hInstance), + uintptr(unsafe.Pointer(lpIconName)), + uintptr(lims), + uintptr(unsafe.Pointer(hicon)), + 0, + 0) + + return HRESULT(ret) +} + +func LoadIconWithScaleDown(hInstance HINSTANCE, lpIconName *uint16, w int32, h int32, hicon *HICON) HRESULT { + if loadIconWithScaleDown.Find() != nil { + return HRESULT(0) + } + ret, _, _ := syscall.Syscall6(loadIconWithScaleDown.Addr(), 5, + uintptr(hInstance), + uintptr(unsafe.Pointer(lpIconName)), + uintptr(w), + uintptr(h), + uintptr(unsafe.Pointer(hicon)), + 0) + + return HRESULT(ret) +} diff --git a/comdlg32.go b/comdlg32.go index f7334d16..e8611181 100644 --- a/comdlg32.go +++ b/comdlg32.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -26,6 +29,31 @@ const ( CDERR_STRUCTSIZE = 0x0001 ) +// CHOOSECOLOR flags +const ( + CC_ANYCOLOR = 0x00000100 + CC_ENABLEHOOK = 0x00000010 + CC_ENABLETEMPLATE = 0x00000020 + CC_ENABLETEMPLATEHANDLE = 0x00000040 + CC_FULLOPEN = 0x00000002 + CC_PREVENTFULLOPEN = 0x00000004 + CC_RGBINIT = 0x00000001 + CC_SHOWHELP = 0x00000008 + CC_SOLIDCOLOR = 0x00000080 +) + +type CHOOSECOLOR struct { + LStructSize uint32 + HwndOwner HWND + HInstance HWND + RgbResult COLORREF + LpCustColors *[16]COLORREF + Flags uint32 + LCustData uintptr + LpfnHook uintptr + LpTemplateName *uint16 +} + // PrintDlg specific error codes const ( PDERR_CREATEICFAILURE = 0x100A @@ -204,28 +232,39 @@ type PRINTDLGEX struct { var ( // Library - libcomdlg32 uintptr + libcomdlg32 *windows.LazyDLL // Functions - commDlgExtendedError uintptr - getOpenFileName uintptr - getSaveFileName uintptr - printDlgEx uintptr + chooseColor *windows.LazyProc + commDlgExtendedError *windows.LazyProc + getOpenFileName *windows.LazyProc + getSaveFileName *windows.LazyProc + printDlgEx *windows.LazyProc ) func init() { // Library - libcomdlg32 = MustLoadLibrary("comdlg32.dll") + libcomdlg32 = windows.NewLazySystemDLL("comdlg32.dll") // Functions - commDlgExtendedError = MustGetProcAddress(libcomdlg32, "CommDlgExtendedError") - getOpenFileName = MustGetProcAddress(libcomdlg32, "GetOpenFileNameW") - getSaveFileName = MustGetProcAddress(libcomdlg32, "GetSaveFileNameW") - printDlgEx = MustGetProcAddress(libcomdlg32, "PrintDlgExW") + chooseColor = libcomdlg32.NewProc("ChooseColorW") + commDlgExtendedError = libcomdlg32.NewProc("CommDlgExtendedError") + getOpenFileName = libcomdlg32.NewProc("GetOpenFileNameW") + getSaveFileName = libcomdlg32.NewProc("GetSaveFileNameW") + printDlgEx = libcomdlg32.NewProc("PrintDlgExW") +} + +func ChooseColor(lpcc *CHOOSECOLOR) bool { + ret, _, _ := syscall.Syscall(chooseColor.Addr(), 1, + uintptr(unsafe.Pointer(lpcc)), + 0, + 0) + + return ret != 0 } func CommDlgExtendedError() uint32 { - ret, _, _ := syscall.Syscall(commDlgExtendedError, 0, + ret, _, _ := syscall.Syscall(commDlgExtendedError.Addr(), 0, 0, 0, 0) @@ -234,7 +273,7 @@ func CommDlgExtendedError() uint32 { } func GetOpenFileName(lpofn *OPENFILENAME) bool { - ret, _, _ := syscall.Syscall(getOpenFileName, 1, + ret, _, _ := syscall.Syscall(getOpenFileName.Addr(), 1, uintptr(unsafe.Pointer(lpofn)), 0, 0) @@ -243,7 +282,7 @@ func GetOpenFileName(lpofn *OPENFILENAME) bool { } func GetSaveFileName(lpofn *OPENFILENAME) bool { - ret, _, _ := syscall.Syscall(getSaveFileName, 1, + ret, _, _ := syscall.Syscall(getSaveFileName.Addr(), 1, uintptr(unsafe.Pointer(lpofn)), 0, 0) @@ -252,7 +291,7 @@ func GetSaveFileName(lpofn *OPENFILENAME) bool { } func PrintDlgEx(lppd *PRINTDLGEX) HRESULT { - ret, _, _ := syscall.Syscall(printDlgEx, 1, + ret, _, _ := syscall.Syscall(printDlgEx.Addr(), 1, uintptr(unsafe.Pointer(lppd)), 0, 0) diff --git a/datetimepicker.go b/datetimepicker.go index 0699d251..07a65324 100644 --- a/datetimepicker.go +++ b/datetimepicker.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win const DTM_FIRST = 0x1000 diff --git a/edit.go b/edit.go index 45594959..a7b3b125 100644 --- a/edit.go +++ b/edit.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // Edit styles @@ -79,4 +81,6 @@ const ( EM_GETIMESTATUS = 0x00D9 EM_SETCUEBANNER = 0x1501 EM_GETCUEBANNER = 0x1502 + EM_SETCARETINDEX = 0x1511 + EM_GETCARETINDEX = 0x1512 ) diff --git a/gdi32.go b/gdi32.go index 5798b8ca..1842b9e5 100644 --- a/gdi32.go +++ b/gdi32.go @@ -2,11 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( "syscall" "unsafe" + + "golang.org/x/sys/windows" ) // GetDeviceCaps index constants @@ -224,6 +228,15 @@ const ( PS_JOIN_MASK = 0x0000F000 ) +// Print constants +const ( + PRF_NONCLIENT = 0x00000002 + PRF_CLIENT = 0x00000004 + PRF_ERASEBKGND = 0x00000008 + PRF_CHILDREN = 0x00000010 + PRF_OWNED = 0x00000020 +) + // Stock logical objects const ( WHITE_BRUSH = 0 @@ -679,7 +692,11 @@ const ( const CBM_INIT = 4 -const CLR_INVALID = 0xFFFFFFFF +const ( + CLR_INVALID = 0xFFFFFFFF + CLR_NONE = CLR_INVALID + CLR_DEFAULT = 0xFF000000 +) const ( /* pixel types */ @@ -713,6 +730,45 @@ const ( PFD_STEREO_DONTCARE = 0x80000000 ) +// GradientFill constants +const ( + GRADIENT_FILL_RECT_H = 0x00 + GRADIENT_FILL_RECT_V = 0x01 + GRADIENT_FILL_TRIANGLE = 0x02 +) + +// Region Combine Modes +const ( + RGN_AND = 1 + RGN_OR = 2 + RGN_XOR = 3 + RGN_DIFF = 4 + RGN_COPY = 5 +) + +// Region Types +const ( + REGIONERROR = 0 + NULLREGION = 1 + SIMPLEREGION = 2 + COMPLEXREGION = 3 +) + +// AlphaBlend operations +const ( + AC_SRC_ALPHA = 0x1 +) + +// AddFontResourceEx flags +const ( + FR_PRIVATE = 0x10 + FR_NOT_ENUM = 0x20 +) + +func RGB(r, g, b byte) COLORREF { + return COLORREF(r) | (COLORREF(g) << 8) | (COLORREF(b) << 16) +} + type ( COLORREF uint32 HBITMAP HGDIOBJ @@ -723,7 +779,8 @@ type ( HENHMETAFILE HANDLE HPALETTE HGDIOBJ HPEN HGDIOBJ - HREGION HGDIOBJ + HRGN HGDIOBJ + CLIPFORMAT uint16 ) type PIXELFORMATDESCRIPTOR struct { @@ -953,119 +1010,198 @@ type ENHMETAHEADER struct { SzlMicrometers SIZE } +type TRIVERTEX struct { + X int32 + Y int32 + Red uint16 + Green uint16 + Blue uint16 + Alpha uint16 +} + +type GRADIENT_RECT struct { + UpperLeft uint32 + LowerRight uint32 +} + +type GRADIENT_TRIANGLE struct { + Vertex1 uint32 + Vertex2 uint32 + Vertex3 uint32 +} + +type BLENDFUNCTION struct { + BlendOp byte + BlendFlags byte + SourceConstantAlpha byte + AlphaFormat byte +} + var ( // Library - libgdi32 uintptr + libgdi32 *windows.LazyDLL + libmsimg32 *windows.LazyDLL // Functions - abortDoc uintptr - bitBlt uintptr - choosePixelFormat uintptr - closeEnhMetaFile uintptr - copyEnhMetaFile uintptr - createBitmap uintptr - createBrushIndirect uintptr - createCompatibleDC uintptr - createDC uintptr - createDIBSection uintptr - createFontIndirect uintptr - createEnhMetaFile uintptr - createIC uintptr - deleteDC uintptr - deleteEnhMetaFile uintptr - deleteObject uintptr - ellipse uintptr - endDoc uintptr - endPage uintptr - extCreatePen uintptr - getDeviceCaps uintptr - getEnhMetaFile uintptr - getEnhMetaFileHeader uintptr - getObject uintptr - getPixel uintptr - getStockObject uintptr - getTextExtentExPoint uintptr - getTextExtentPoint32 uintptr - getTextMetrics uintptr - lineTo uintptr - moveToEx uintptr - playEnhMetaFile uintptr - rectangle uintptr - resetDC uintptr - restoreDC uintptr - selectObject uintptr - setBkMode uintptr - setBrushOrgEx uintptr - setPixel uintptr - setPixelFormat uintptr - setStretchBltMode uintptr - setTextColor uintptr - saveDC uintptr - startDoc uintptr - startPage uintptr - stretchBlt uintptr - swapBuffers uintptr - textOut uintptr + abortDoc *windows.LazyProc + addFontResourceEx *windows.LazyProc + addFontMemResourceEx *windows.LazyProc + alphaBlend *windows.LazyProc + bitBlt *windows.LazyProc + choosePixelFormat *windows.LazyProc + closeEnhMetaFile *windows.LazyProc + combineRgn *windows.LazyProc + copyEnhMetaFile *windows.LazyProc + createBitmap *windows.LazyProc + createCompatibleBitmap *windows.LazyProc + createBrushIndirect *windows.LazyProc + createCompatibleDC *windows.LazyProc + createDC *windows.LazyProc + createDIBSection *windows.LazyProc + createFontIndirect *windows.LazyProc + createEnhMetaFile *windows.LazyProc + createIC *windows.LazyProc + createPatternBrush *windows.LazyProc + createRectRgn *windows.LazyProc + deleteDC *windows.LazyProc + deleteEnhMetaFile *windows.LazyProc + deleteObject *windows.LazyProc + ellipse *windows.LazyProc + endDoc *windows.LazyProc + endPage *windows.LazyProc + excludeClipRect *windows.LazyProc + extCreatePen *windows.LazyProc + fillRgn *windows.LazyProc + gdiFlush *windows.LazyProc + getBkColor *windows.LazyProc + getDeviceCaps *windows.LazyProc + getDIBits *windows.LazyProc + getEnhMetaFile *windows.LazyProc + getEnhMetaFileHeader *windows.LazyProc + getObject *windows.LazyProc + getPixel *windows.LazyProc + getRgnBox *windows.LazyProc + getStockObject *windows.LazyProc + getTextColor *windows.LazyProc + getTextExtentExPoint *windows.LazyProc + getTextExtentPoint32 *windows.LazyProc + getTextMetrics *windows.LazyProc + getViewportOrgEx *windows.LazyProc + gradientFill *windows.LazyProc + intersectClipRect *windows.LazyProc + lineTo *windows.LazyProc + moveToEx *windows.LazyProc + playEnhMetaFile *windows.LazyProc + polyline *windows.LazyProc + rectangle *windows.LazyProc + removeFontResourceEx *windows.LazyProc + removeFontMemResourceEx *windows.LazyProc + resetDC *windows.LazyProc + restoreDC *windows.LazyProc + roundRect *windows.LazyProc + selectObject *windows.LazyProc + setBkColor *windows.LazyProc + setBkMode *windows.LazyProc + setBrushOrgEx *windows.LazyProc + setDIBits *windows.LazyProc + setPixel *windows.LazyProc + setPixelFormat *windows.LazyProc + setStretchBltMode *windows.LazyProc + setTextColor *windows.LazyProc + setViewportOrgEx *windows.LazyProc + saveDC *windows.LazyProc + startDoc *windows.LazyProc + startPage *windows.LazyProc + stretchBlt *windows.LazyProc + swapBuffers *windows.LazyProc + textOut *windows.LazyProc + transparentBlt *windows.LazyProc ) func init() { // Library - libgdi32 = MustLoadLibrary("gdi32.dll") + libgdi32 = windows.NewLazySystemDLL("gdi32.dll") + libmsimg32 = windows.NewLazySystemDLL("msimg32.dll") // Functions - abortDoc = MustGetProcAddress(libgdi32, "AbortDoc") - bitBlt = MustGetProcAddress(libgdi32, "BitBlt") - choosePixelFormat = MustGetProcAddress(libgdi32, "ChoosePixelFormat") - closeEnhMetaFile = MustGetProcAddress(libgdi32, "CloseEnhMetaFile") - copyEnhMetaFile = MustGetProcAddress(libgdi32, "CopyEnhMetaFileW") - createBitmap = MustGetProcAddress(libgdi32, "CreateBitmap") - createBrushIndirect = MustGetProcAddress(libgdi32, "CreateBrushIndirect") - createCompatibleDC = MustGetProcAddress(libgdi32, "CreateCompatibleDC") - createDC = MustGetProcAddress(libgdi32, "CreateDCW") - createDIBSection = MustGetProcAddress(libgdi32, "CreateDIBSection") - createEnhMetaFile = MustGetProcAddress(libgdi32, "CreateEnhMetaFileW") - createFontIndirect = MustGetProcAddress(libgdi32, "CreateFontIndirectW") - createIC = MustGetProcAddress(libgdi32, "CreateICW") - deleteDC = MustGetProcAddress(libgdi32, "DeleteDC") - deleteEnhMetaFile = MustGetProcAddress(libgdi32, "DeleteEnhMetaFile") - deleteObject = MustGetProcAddress(libgdi32, "DeleteObject") - ellipse = MustGetProcAddress(libgdi32, "Ellipse") - endDoc = MustGetProcAddress(libgdi32, "EndDoc") - endPage = MustGetProcAddress(libgdi32, "EndPage") - extCreatePen = MustGetProcAddress(libgdi32, "ExtCreatePen") - getDeviceCaps = MustGetProcAddress(libgdi32, "GetDeviceCaps") - getEnhMetaFile = MustGetProcAddress(libgdi32, "GetEnhMetaFileW") - getEnhMetaFileHeader = MustGetProcAddress(libgdi32, "GetEnhMetaFileHeader") - getObject = MustGetProcAddress(libgdi32, "GetObjectW") - getPixel = MustGetProcAddress(libgdi32, "GetPixel") - getStockObject = MustGetProcAddress(libgdi32, "GetStockObject") - getTextExtentExPoint = MustGetProcAddress(libgdi32, "GetTextExtentExPointW") - getTextExtentPoint32 = MustGetProcAddress(libgdi32, "GetTextExtentPoint32W") - getTextMetrics = MustGetProcAddress(libgdi32, "GetTextMetricsW") - lineTo = MustGetProcAddress(libgdi32, "LineTo") - moveToEx = MustGetProcAddress(libgdi32, "MoveToEx") - playEnhMetaFile = MustGetProcAddress(libgdi32, "PlayEnhMetaFile") - rectangle = MustGetProcAddress(libgdi32, "Rectangle") - resetDC = MustGetProcAddress(libgdi32, "ResetDCW") - restoreDC = MustGetProcAddress(libgdi32, "RestoreDC") - saveDC = MustGetProcAddress(libgdi32, "SaveDC") - selectObject = MustGetProcAddress(libgdi32, "SelectObject") - setBkMode = MustGetProcAddress(libgdi32, "SetBkMode") - setBrushOrgEx = MustGetProcAddress(libgdi32, "SetBrushOrgEx") - setPixel = MustGetProcAddress(libgdi32, "SetPixel") - setPixelFormat = MustGetProcAddress(libgdi32, "SetPixelFormat") - setStretchBltMode = MustGetProcAddress(libgdi32, "SetStretchBltMode") - setTextColor = MustGetProcAddress(libgdi32, "SetTextColor") - startDoc = MustGetProcAddress(libgdi32, "StartDocW") - startPage = MustGetProcAddress(libgdi32, "StartPage") - stretchBlt = MustGetProcAddress(libgdi32, "StretchBlt") - swapBuffers = MustGetProcAddress(libgdi32, "SwapBuffers") - textOut = MustGetProcAddress(libgdi32, "TextOutW") - + abortDoc = libgdi32.NewProc("AbortDoc") + addFontResourceEx = libgdi32.NewProc("AddFontResourceExW") + addFontMemResourceEx = libgdi32.NewProc("AddFontMemResourceEx") + bitBlt = libgdi32.NewProc("BitBlt") + choosePixelFormat = libgdi32.NewProc("ChoosePixelFormat") + closeEnhMetaFile = libgdi32.NewProc("CloseEnhMetaFile") + combineRgn = libgdi32.NewProc("CombineRgn") + copyEnhMetaFile = libgdi32.NewProc("CopyEnhMetaFileW") + createBitmap = libgdi32.NewProc("CreateBitmap") + createCompatibleBitmap = libgdi32.NewProc("CreateCompatibleBitmap") + createBrushIndirect = libgdi32.NewProc("CreateBrushIndirect") + createCompatibleDC = libgdi32.NewProc("CreateCompatibleDC") + createDC = libgdi32.NewProc("CreateDCW") + createDIBSection = libgdi32.NewProc("CreateDIBSection") + createEnhMetaFile = libgdi32.NewProc("CreateEnhMetaFileW") + createFontIndirect = libgdi32.NewProc("CreateFontIndirectW") + createIC = libgdi32.NewProc("CreateICW") + createPatternBrush = libgdi32.NewProc("CreatePatternBrush") + createRectRgn = libgdi32.NewProc("CreateRectRgn") + deleteDC = libgdi32.NewProc("DeleteDC") + deleteEnhMetaFile = libgdi32.NewProc("DeleteEnhMetaFile") + deleteObject = libgdi32.NewProc("DeleteObject") + ellipse = libgdi32.NewProc("Ellipse") + endDoc = libgdi32.NewProc("EndDoc") + endPage = libgdi32.NewProc("EndPage") + excludeClipRect = libgdi32.NewProc("ExcludeClipRect") + extCreatePen = libgdi32.NewProc("ExtCreatePen") + fillRgn = libgdi32.NewProc("FillRgn") + gdiFlush = libgdi32.NewProc("GdiFlush") + getBkColor = libgdi32.NewProc("GetBkColor") + getDeviceCaps = libgdi32.NewProc("GetDeviceCaps") + getDIBits = libgdi32.NewProc("GetDIBits") + getEnhMetaFile = libgdi32.NewProc("GetEnhMetaFileW") + getEnhMetaFileHeader = libgdi32.NewProc("GetEnhMetaFileHeader") + getObject = libgdi32.NewProc("GetObjectW") + getPixel = libgdi32.NewProc("GetPixel") + getRgnBox = libgdi32.NewProc("GetRgnBox") + getStockObject = libgdi32.NewProc("GetStockObject") + getTextColor = libgdi32.NewProc("GetTextColor") + getTextExtentExPoint = libgdi32.NewProc("GetTextExtentExPointW") + getTextExtentPoint32 = libgdi32.NewProc("GetTextExtentPoint32W") + getTextMetrics = libgdi32.NewProc("GetTextMetricsW") + getViewportOrgEx = libgdi32.NewProc("GetViewportOrgEx") + intersectClipRect = libgdi32.NewProc("IntersectClipRect") + lineTo = libgdi32.NewProc("LineTo") + moveToEx = libgdi32.NewProc("MoveToEx") + playEnhMetaFile = libgdi32.NewProc("PlayEnhMetaFile") + polyline = libgdi32.NewProc("Polyline") + rectangle = libgdi32.NewProc("Rectangle") + removeFontResourceEx = libgdi32.NewProc("RemoveFontResourceExW") + removeFontMemResourceEx = libgdi32.NewProc("RemoveFontMemResourceEx") + resetDC = libgdi32.NewProc("ResetDCW") + restoreDC = libgdi32.NewProc("RestoreDC") + roundRect = libgdi32.NewProc("RoundRect") + saveDC = libgdi32.NewProc("SaveDC") + selectObject = libgdi32.NewProc("SelectObject") + setBkColor = libgdi32.NewProc("SetBkColor") + setBkMode = libgdi32.NewProc("SetBkMode") + setBrushOrgEx = libgdi32.NewProc("SetBrushOrgEx") + setDIBits = libgdi32.NewProc("SetDIBits") + setPixel = libgdi32.NewProc("SetPixel") + setPixelFormat = libgdi32.NewProc("SetPixelFormat") + setStretchBltMode = libgdi32.NewProc("SetStretchBltMode") + setTextColor = libgdi32.NewProc("SetTextColor") + setViewportOrgEx = libgdi32.NewProc("SetViewportOrgEx") + startDoc = libgdi32.NewProc("StartDocW") + startPage = libgdi32.NewProc("StartPage") + stretchBlt = libgdi32.NewProc("StretchBlt") + swapBuffers = libgdi32.NewProc("SwapBuffers") + textOut = libgdi32.NewProc("TextOutW") + + alphaBlend = libmsimg32.NewProc("AlphaBlend") + gradientFill = libmsimg32.NewProc("GradientFill") + transparentBlt = libmsimg32.NewProc("TransparentBlt") } func AbortDoc(hdc HDC) int32 { - ret, _, _ := syscall.Syscall(abortDoc, 1, + ret, _, _ := syscall.Syscall(abortDoc.Addr(), 1, uintptr(hdc), 0, 0) @@ -1073,8 +1209,47 @@ func AbortDoc(hdc HDC) int32 { return int32(ret) } +func AddFontResourceEx(lpszFilename *uint16, fl uint32, pdv unsafe.Pointer) int32 { + ret, _, _ := syscall.Syscall(addFontResourceEx.Addr(), 3, + uintptr(unsafe.Pointer(lpszFilename)), + uintptr(fl), + uintptr(pdv)) + + return int32(ret) +} + +func AddFontMemResourceEx(pFileView uintptr, cjSize uint32, pvReserved unsafe.Pointer, pNumFonts *uint32) HANDLE { + ret, _, _ := syscall.Syscall6(addFontMemResourceEx.Addr(), 4, + pFileView, + uintptr(cjSize), + uintptr(pvReserved), + uintptr(unsafe.Pointer(pNumFonts)), + 0, + 0) + + return HANDLE(ret) +} + +func AlphaBlend(hdcDest HDC, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest int32, hdcSrc HDC, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc int32, ftn BLENDFUNCTION) bool { + ret, _, _ := syscall.Syscall12(alphaBlend.Addr(), 11, + uintptr(hdcDest), + uintptr(nXOriginDest), + uintptr(nYOriginDest), + uintptr(nWidthDest), + uintptr(nHeightDest), + uintptr(hdcSrc), + uintptr(nXOriginSrc), + uintptr(nYOriginSrc), + uintptr(nWidthSrc), + uintptr(nHeightSrc), + uintptr(*(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&ftn))))), + 0) + + return ret != 0 +} + func BitBlt(hdcDest HDC, nXDest, nYDest, nWidth, nHeight int32, hdcSrc HDC, nXSrc, nYSrc int32, dwRop uint32) bool { - ret, _, _ := syscall.Syscall9(bitBlt, 9, + ret, _, _ := syscall.Syscall9(bitBlt.Addr(), 9, uintptr(hdcDest), uintptr(nXDest), uintptr(nYDest), @@ -1089,7 +1264,7 @@ func BitBlt(hdcDest HDC, nXDest, nYDest, nWidth, nHeight int32, hdcSrc HDC, nXSr } func ChoosePixelFormat(hdc HDC, ppfd *PIXELFORMATDESCRIPTOR) int32 { - ret, _, _ := syscall.Syscall(choosePixelFormat, 2, + ret, _, _ := syscall.Syscall(choosePixelFormat.Addr(), 2, uintptr(hdc), uintptr(unsafe.Pointer(ppfd)), 0) @@ -1098,7 +1273,7 @@ func ChoosePixelFormat(hdc HDC, ppfd *PIXELFORMATDESCRIPTOR) int32 { } func CloseEnhMetaFile(hdc HDC) HENHMETAFILE { - ret, _, _ := syscall.Syscall(closeEnhMetaFile, 1, + ret, _, _ := syscall.Syscall(closeEnhMetaFile.Addr(), 1, uintptr(hdc), 0, 0) @@ -1106,8 +1281,20 @@ func CloseEnhMetaFile(hdc HDC) HENHMETAFILE { return HENHMETAFILE(ret) } +func CombineRgn(hrgnDest, hrgnSrc1, hrgnSrc2 HRGN, fnCombineMode int32) int32 { + ret, _, _ := syscall.Syscall6(combineRgn.Addr(), 4, + uintptr(hrgnDest), + uintptr(hrgnSrc1), + uintptr(hrgnSrc2), + uintptr(fnCombineMode), + 0, + 0) + + return int32(ret) +} + func CopyEnhMetaFile(hemfSrc HENHMETAFILE, lpszFile *uint16) HENHMETAFILE { - ret, _, _ := syscall.Syscall(copyEnhMetaFile, 2, + ret, _, _ := syscall.Syscall(copyEnhMetaFile.Addr(), 2, uintptr(hemfSrc), uintptr(unsafe.Pointer(lpszFile)), 0) @@ -1116,7 +1303,7 @@ func CopyEnhMetaFile(hemfSrc HENHMETAFILE, lpszFile *uint16) HENHMETAFILE { } func CreateBitmap(nWidth, nHeight int32, cPlanes, cBitsPerPel uint32, lpvBits unsafe.Pointer) HBITMAP { - ret, _, _ := syscall.Syscall6(createBitmap, 5, + ret, _, _ := syscall.Syscall6(createBitmap.Addr(), 5, uintptr(nWidth), uintptr(nHeight), uintptr(cPlanes), @@ -1127,8 +1314,17 @@ func CreateBitmap(nWidth, nHeight int32, cPlanes, cBitsPerPel uint32, lpvBits un return HBITMAP(ret) } +func CreateCompatibleBitmap(hdc HDC, nWidth, nHeight int32) HBITMAP { + ret, _, _ := syscall.Syscall(createCompatibleBitmap.Addr(), 3, + uintptr(hdc), + uintptr(nWidth), + uintptr(nHeight)) + + return HBITMAP(ret) +} + func CreateBrushIndirect(lplb *LOGBRUSH) HBRUSH { - ret, _, _ := syscall.Syscall(createBrushIndirect, 1, + ret, _, _ := syscall.Syscall(createBrushIndirect.Addr(), 1, uintptr(unsafe.Pointer(lplb)), 0, 0) @@ -1137,7 +1333,7 @@ func CreateBrushIndirect(lplb *LOGBRUSH) HBRUSH { } func CreateCompatibleDC(hdc HDC) HDC { - ret, _, _ := syscall.Syscall(createCompatibleDC, 1, + ret, _, _ := syscall.Syscall(createCompatibleDC.Addr(), 1, uintptr(hdc), 0, 0) @@ -1146,7 +1342,7 @@ func CreateCompatibleDC(hdc HDC) HDC { } func CreateDC(lpszDriver, lpszDevice, lpszOutput *uint16, lpInitData *DEVMODE) HDC { - ret, _, _ := syscall.Syscall6(createDC, 4, + ret, _, _ := syscall.Syscall6(createDC.Addr(), 4, uintptr(unsafe.Pointer(lpszDriver)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(lpszOutput)), @@ -1158,7 +1354,7 @@ func CreateDC(lpszDriver, lpszDevice, lpszOutput *uint16, lpInitData *DEVMODE) H } func CreateDIBSection(hdc HDC, pbmih *BITMAPINFOHEADER, iUsage uint32, ppvBits *unsafe.Pointer, hSection HANDLE, dwOffset uint32) HBITMAP { - ret, _, _ := syscall.Syscall6(createDIBSection, 6, + ret, _, _ := syscall.Syscall6(createDIBSection.Addr(), 6, uintptr(hdc), uintptr(unsafe.Pointer(pbmih)), uintptr(iUsage), @@ -1170,7 +1366,7 @@ func CreateDIBSection(hdc HDC, pbmih *BITMAPINFOHEADER, iUsage uint32, ppvBits * } func CreateEnhMetaFile(hdcRef HDC, lpFilename *uint16, lpRect *RECT, lpDescription *uint16) HDC { - ret, _, _ := syscall.Syscall6(createEnhMetaFile, 4, + ret, _, _ := syscall.Syscall6(createEnhMetaFile.Addr(), 4, uintptr(hdcRef), uintptr(unsafe.Pointer(lpFilename)), uintptr(unsafe.Pointer(lpRect)), @@ -1182,7 +1378,7 @@ func CreateEnhMetaFile(hdcRef HDC, lpFilename *uint16, lpRect *RECT, lpDescripti } func CreateFontIndirect(lplf *LOGFONT) HFONT { - ret, _, _ := syscall.Syscall(createFontIndirect, 1, + ret, _, _ := syscall.Syscall(createFontIndirect.Addr(), 1, uintptr(unsafe.Pointer(lplf)), 0, 0) @@ -1191,7 +1387,7 @@ func CreateFontIndirect(lplf *LOGFONT) HFONT { } func CreateIC(lpszDriver, lpszDevice, lpszOutput *uint16, lpdvmInit *DEVMODE) HDC { - ret, _, _ := syscall.Syscall6(createIC, 4, + ret, _, _ := syscall.Syscall6(createIC.Addr(), 4, uintptr(unsafe.Pointer(lpszDriver)), uintptr(unsafe.Pointer(lpszDevice)), uintptr(unsafe.Pointer(lpszOutput)), @@ -1202,8 +1398,29 @@ func CreateIC(lpszDriver, lpszDevice, lpszOutput *uint16, lpdvmInit *DEVMODE) HD return HDC(ret) } +func CreatePatternBrush(hbmp HBITMAP) HBRUSH { + ret, _, _ := syscall.Syscall(createPatternBrush.Addr(), 1, + uintptr(hbmp), + 0, + 0) + + return HBRUSH(ret) +} + +func CreateRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect int32) HRGN { + ret, _, _ := syscall.Syscall6(createRectRgn.Addr(), 4, + uintptr(nLeftRect), + uintptr(nTopRect), + uintptr(nRightRect), + uintptr(nBottomRect), + 0, + 0) + + return HRGN(ret) +} + func DeleteDC(hdc HDC) bool { - ret, _, _ := syscall.Syscall(deleteDC, 1, + ret, _, _ := syscall.Syscall(deleteDC.Addr(), 1, uintptr(hdc), 0, 0) @@ -1212,7 +1429,7 @@ func DeleteDC(hdc HDC) bool { } func DeleteEnhMetaFile(hemf HENHMETAFILE) bool { - ret, _, _ := syscall.Syscall(deleteEnhMetaFile, 1, + ret, _, _ := syscall.Syscall(deleteEnhMetaFile.Addr(), 1, uintptr(hemf), 0, 0) @@ -1221,7 +1438,7 @@ func DeleteEnhMetaFile(hemf HENHMETAFILE) bool { } func DeleteObject(hObject HGDIOBJ) bool { - ret, _, _ := syscall.Syscall(deleteObject, 1, + ret, _, _ := syscall.Syscall(deleteObject.Addr(), 1, uintptr(hObject), 0, 0) @@ -1230,7 +1447,7 @@ func DeleteObject(hObject HGDIOBJ) bool { } func Ellipse(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) bool { - ret, _, _ := syscall.Syscall6(ellipse, 5, + ret, _, _ := syscall.Syscall6(ellipse.Addr(), 5, uintptr(hdc), uintptr(nLeftRect), uintptr(nTopRect), @@ -1242,7 +1459,7 @@ func Ellipse(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) bool { } func EndDoc(hdc HDC) int32 { - ret, _, _ := syscall.Syscall(endDoc, 1, + ret, _, _ := syscall.Syscall(endDoc.Addr(), 1, uintptr(hdc), 0, 0) @@ -1251,7 +1468,7 @@ func EndDoc(hdc HDC) int32 { } func EndPage(hdc HDC) int32 { - ret, _, _ := syscall.Syscall(endPage, 1, + ret, _, _ := syscall.Syscall(endPage.Addr(), 1, uintptr(hdc), 0, 0) @@ -1259,8 +1476,20 @@ func EndPage(hdc HDC) int32 { return int32(ret) } +func ExcludeClipRect(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) int32 { + ret, _, _ := syscall.Syscall6(excludeClipRect.Addr(), 5, + uintptr(hdc), + uintptr(nLeftRect), + uintptr(nTopRect), + uintptr(nRightRect), + uintptr(nBottomRect), + 0) + + return int32(ret) +} + func ExtCreatePen(dwPenStyle, dwWidth uint32, lplb *LOGBRUSH, dwStyleCount uint32, lpStyle *uint32) HPEN { - ret, _, _ := syscall.Syscall6(extCreatePen, 5, + ret, _, _ := syscall.Syscall6(extCreatePen.Addr(), 5, uintptr(dwPenStyle), uintptr(dwWidth), uintptr(unsafe.Pointer(lplb)), @@ -1271,8 +1500,35 @@ func ExtCreatePen(dwPenStyle, dwWidth uint32, lplb *LOGBRUSH, dwStyleCount uint3 return HPEN(ret) } +func FillRgn(hdc HDC, hrgn HRGN, hbr HBRUSH) bool { + ret, _, _ := syscall.Syscall(fillRgn.Addr(), 3, + uintptr(hdc), + uintptr(hrgn), + uintptr(hbr)) + + return ret != 0 +} + +func GdiFlush() bool { + ret, _, _ := syscall.Syscall(gdiFlush.Addr(), 0, + 0, + 0, + 0) + + return ret != 0 +} + +func GetBkColor(hdc HDC) COLORREF { + ret, _, _ := syscall.Syscall(getBkColor.Addr(), 1, + uintptr(hdc), + 0, + 0) + + return COLORREF(ret) +} + func GetDeviceCaps(hdc HDC, nIndex int32) int32 { - ret, _, _ := syscall.Syscall(getDeviceCaps, 2, + ret, _, _ := syscall.Syscall(getDeviceCaps.Addr(), 2, uintptr(hdc), uintptr(nIndex), 0) @@ -1280,8 +1536,22 @@ func GetDeviceCaps(hdc HDC, nIndex int32) int32 { return int32(ret) } +func GetDIBits(hdc HDC, hbmp HBITMAP, uStartScan uint32, cScanLines uint32, lpvBits *byte, lpbi *BITMAPINFO, uUsage uint32) int32 { + ret, _, _ := syscall.Syscall9(getDIBits.Addr(), 7, + uintptr(hdc), + uintptr(hbmp), + uintptr(uStartScan), + uintptr(cScanLines), + uintptr(unsafe.Pointer(lpvBits)), + uintptr(unsafe.Pointer(lpbi)), + uintptr(uUsage), + 0, + 0) + return int32(ret) +} + func GetEnhMetaFile(lpszMetaFile *uint16) HENHMETAFILE { - ret, _, _ := syscall.Syscall(getEnhMetaFile, 1, + ret, _, _ := syscall.Syscall(getEnhMetaFile.Addr(), 1, uintptr(unsafe.Pointer(lpszMetaFile)), 0, 0) @@ -1290,7 +1560,7 @@ func GetEnhMetaFile(lpszMetaFile *uint16) HENHMETAFILE { } func GetEnhMetaFileHeader(hemf HENHMETAFILE, cbBuffer uint32, lpemh *ENHMETAHEADER) uint32 { - ret, _, _ := syscall.Syscall(getEnhMetaFileHeader, 3, + ret, _, _ := syscall.Syscall(getEnhMetaFileHeader.Addr(), 3, uintptr(hemf), uintptr(cbBuffer), uintptr(unsafe.Pointer(lpemh))) @@ -1299,7 +1569,7 @@ func GetEnhMetaFileHeader(hemf HENHMETAFILE, cbBuffer uint32, lpemh *ENHMETAHEAD } func GetObject(hgdiobj HGDIOBJ, cbBuffer uintptr, lpvObject unsafe.Pointer) int32 { - ret, _, _ := syscall.Syscall(getObject, 3, + ret, _, _ := syscall.Syscall(getObject.Addr(), 3, uintptr(hgdiobj), uintptr(cbBuffer), uintptr(lpvObject)) @@ -1308,7 +1578,7 @@ func GetObject(hgdiobj HGDIOBJ, cbBuffer uintptr, lpvObject unsafe.Pointer) int3 } func GetPixel(hdc HDC, nXPos, nYPos int32) COLORREF { - ret, _, _ := syscall.Syscall(getPixel, 3, + ret, _, _ := syscall.Syscall(getPixel.Addr(), 3, uintptr(hdc), uintptr(nXPos), uintptr(nYPos)) @@ -1316,8 +1586,17 @@ func GetPixel(hdc HDC, nXPos, nYPos int32) COLORREF { return COLORREF(ret) } +func GetRgnBox(hrgn HRGN, lprc *RECT) int32 { + ret, _, _ := syscall.Syscall(getRgnBox.Addr(), 2, + uintptr(hrgn), + uintptr(unsafe.Pointer(lprc)), + 0) + + return int32(ret) +} + func GetStockObject(fnObject int32) HGDIOBJ { - ret, _, _ := syscall.Syscall(getDeviceCaps, 1, + ret, _, _ := syscall.Syscall(getStockObject.Addr(), 1, uintptr(fnObject), 0, 0) @@ -1325,8 +1604,17 @@ func GetStockObject(fnObject int32) HGDIOBJ { return HGDIOBJ(ret) } +func GetTextColor(hdc HDC) COLORREF { + ret, _, _ := syscall.Syscall(getTextColor.Addr(), 1, + uintptr(hdc), + 0, + 0) + + return COLORREF(ret) +} + func GetTextExtentExPoint(hdc HDC, lpszStr *uint16, cchString, nMaxExtent int32, lpnFit, alpDx *int32, lpSize *SIZE) bool { - ret, _, _ := syscall.Syscall9(getTextExtentExPoint, 7, + ret, _, _ := syscall.Syscall9(getTextExtentExPoint.Addr(), 7, uintptr(hdc), uintptr(unsafe.Pointer(lpszStr)), uintptr(cchString), @@ -1341,7 +1629,7 @@ func GetTextExtentExPoint(hdc HDC, lpszStr *uint16, cchString, nMaxExtent int32, } func GetTextExtentPoint32(hdc HDC, lpString *uint16, c int32, lpSize *SIZE) bool { - ret, _, _ := syscall.Syscall6(getTextExtentPoint32, 4, + ret, _, _ := syscall.Syscall6(getTextExtentPoint32.Addr(), 4, uintptr(hdc), uintptr(unsafe.Pointer(lpString)), uintptr(c), @@ -1353,7 +1641,7 @@ func GetTextExtentPoint32(hdc HDC, lpString *uint16, c int32, lpSize *SIZE) bool } func GetTextMetrics(hdc HDC, lptm *TEXTMETRIC) bool { - ret, _, _ := syscall.Syscall(getTextMetrics, 2, + ret, _, _ := syscall.Syscall(getTextMetrics.Addr(), 2, uintptr(hdc), uintptr(unsafe.Pointer(lptm)), 0) @@ -1361,8 +1649,41 @@ func GetTextMetrics(hdc HDC, lptm *TEXTMETRIC) bool { return ret != 0 } +func GetViewportOrgEx(hdc HDC, lpPoint *POINT) bool { + ret, _, _ := syscall.Syscall(getViewportOrgEx.Addr(), 2, + uintptr(hdc), + uintptr(unsafe.Pointer(lpPoint)), + 0) + + return ret != 0 +} + +func GradientFill(hdc HDC, pVertex *TRIVERTEX, nVertex uint32, pMesh unsafe.Pointer, nMesh, ulMode uint32) bool { + ret, _, _ := syscall.Syscall6(gradientFill.Addr(), 6, + uintptr(hdc), + uintptr(unsafe.Pointer(pVertex)), + uintptr(nVertex), + uintptr(pMesh), + uintptr(nMesh), + uintptr(ulMode)) + + return ret != 0 +} + +func IntersectClipRect(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) int32 { + ret, _, _ := syscall.Syscall6(intersectClipRect.Addr(), 5, + uintptr(hdc), + uintptr(nLeftRect), + uintptr(nTopRect), + uintptr(nRightRect), + uintptr(nBottomRect), + 0) + + return int32(ret) +} + func LineTo(hdc HDC, nXEnd, nYEnd int32) bool { - ret, _, _ := syscall.Syscall(lineTo, 3, + ret, _, _ := syscall.Syscall(lineTo.Addr(), 3, uintptr(hdc), uintptr(nXEnd), uintptr(nYEnd)) @@ -1371,7 +1692,7 @@ func LineTo(hdc HDC, nXEnd, nYEnd int32) bool { } func MoveToEx(hdc HDC, x, y int, lpPoint *POINT) bool { - ret, _, _ := syscall.Syscall6(moveToEx, 4, + ret, _, _ := syscall.Syscall6(moveToEx.Addr(), 4, uintptr(hdc), uintptr(x), uintptr(y), @@ -1383,7 +1704,7 @@ func MoveToEx(hdc HDC, x, y int, lpPoint *POINT) bool { } func PlayEnhMetaFile(hdc HDC, hemf HENHMETAFILE, lpRect *RECT) bool { - ret, _, _ := syscall.Syscall(playEnhMetaFile, 3, + ret, _, _ := syscall.Syscall(playEnhMetaFile.Addr(), 3, uintptr(hdc), uintptr(hemf), uintptr(unsafe.Pointer(lpRect))) @@ -1391,8 +1712,17 @@ func PlayEnhMetaFile(hdc HDC, hemf HENHMETAFILE, lpRect *RECT) bool { return ret != 0 } +func Polyline(hdc HDC, lppt unsafe.Pointer, cPoints int32) bool { + ret, _, _ := syscall.Syscall(polyline.Addr(), 3, + uintptr(hdc), + uintptr(lppt), + uintptr(cPoints)) + + return ret != 0 +} + func Rectangle_(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) bool { - ret, _, _ := syscall.Syscall6(rectangle, 5, + ret, _, _ := syscall.Syscall6(rectangle.Addr(), 5, uintptr(hdc), uintptr(nLeftRect), uintptr(nTopRect), @@ -1403,8 +1733,26 @@ func Rectangle_(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) boo return ret != 0 } +func RemoveFontResourceEx(lpszFilename *uint16, fl uint32, pdv unsafe.Pointer) bool { + ret, _, _ := syscall.Syscall(removeFontResourceEx.Addr(), 3, + uintptr(unsafe.Pointer(lpszFilename)), + uintptr(fl), + uintptr(pdv)) + + return ret != 0 +} + +func RemoveFontMemResourceEx(h HANDLE) bool { + ret, _, _ := syscall.Syscall(removeFontMemResourceEx.Addr(), 1, + uintptr(h), + 0, + 0) + + return ret != 0 +} + func ResetDC(hdc HDC, lpInitData *DEVMODE) HDC { - ret, _, _ := syscall.Syscall(resetDC, 2, + ret, _, _ := syscall.Syscall(resetDC.Addr(), 2, uintptr(hdc), uintptr(unsafe.Pointer(lpInitData)), 0) @@ -1413,15 +1761,30 @@ func ResetDC(hdc HDC, lpInitData *DEVMODE) HDC { } func RestoreDC(hdc HDC, nSaveDC int32) bool { - ret, _, _ := syscall.Syscall(restoreDC, 2, + ret, _, _ := syscall.Syscall(restoreDC.Addr(), 2, uintptr(hdc), uintptr(nSaveDC), 0) return ret != 0 } +func RoundRect(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect, nWidth, nHeight int32) bool { + ret, _, _ := syscall.Syscall9(roundRect.Addr(), 7, + uintptr(hdc), + uintptr(nLeftRect), + uintptr(nTopRect), + uintptr(nRightRect), + uintptr(nBottomRect), + uintptr(nWidth), + uintptr(nHeight), + 0, + 0) + + return ret != 0 +} + func SaveDC(hdc HDC) int32 { - ret, _, _ := syscall.Syscall(saveDC, 1, + ret, _, _ := syscall.Syscall(saveDC.Addr(), 1, uintptr(hdc), 0, 0) @@ -1429,7 +1792,7 @@ func SaveDC(hdc HDC) int32 { } func SelectObject(hdc HDC, hgdiobj HGDIOBJ) HGDIOBJ { - ret, _, _ := syscall.Syscall(selectObject, 2, + ret, _, _ := syscall.Syscall(selectObject.Addr(), 2, uintptr(hdc), uintptr(hgdiobj), 0) @@ -1437,8 +1800,17 @@ func SelectObject(hdc HDC, hgdiobj HGDIOBJ) HGDIOBJ { return HGDIOBJ(ret) } +func SetBkColor(hdc HDC, crColor COLORREF) COLORREF { + ret, _, _ := syscall.Syscall(setBkColor.Addr(), 2, + uintptr(hdc), + uintptr(crColor), + 0) + + return COLORREF(ret) +} + func SetBkMode(hdc HDC, iBkMode int32) int32 { - ret, _, _ := syscall.Syscall(setBkMode, 2, + ret, _, _ := syscall.Syscall(setBkMode.Addr(), 2, uintptr(hdc), uintptr(iBkMode), 0) @@ -1447,7 +1819,7 @@ func SetBkMode(hdc HDC, iBkMode int32) int32 { } func SetBrushOrgEx(hdc HDC, nXOrg, nYOrg int32, lppt *POINT) bool { - ret, _, _ := syscall.Syscall6(setBrushOrgEx, 4, + ret, _, _ := syscall.Syscall6(setBrushOrgEx.Addr(), 4, uintptr(hdc), uintptr(nXOrg), uintptr(nYOrg), @@ -1458,8 +1830,23 @@ func SetBrushOrgEx(hdc HDC, nXOrg, nYOrg int32, lppt *POINT) bool { return ret != 0 } +func SetDIBits(hdc HDC, hbmp HBITMAP, uStartScan, cScanLines uint32, lpvBits *byte, lpbmi *BITMAPINFO, fuColorUse uint32) int32 { + ret, _, _ := syscall.Syscall9(setDIBits.Addr(), 7, + uintptr(hdc), + uintptr(hbmp), + uintptr(uStartScan), + uintptr(cScanLines), + uintptr(unsafe.Pointer(lpvBits)), + uintptr(unsafe.Pointer(lpbmi)), + uintptr(fuColorUse), + 0, + 0) + + return int32(ret) +} + func SetPixel(hdc HDC, X, Y int32, crColor COLORREF) COLORREF { - ret, _, _ := syscall.Syscall6(setPixel, 4, + ret, _, _ := syscall.Syscall6(setPixel.Addr(), 4, uintptr(hdc), uintptr(X), uintptr(Y), @@ -1471,7 +1858,7 @@ func SetPixel(hdc HDC, X, Y int32, crColor COLORREF) COLORREF { } func SetPixelFormat(hdc HDC, iPixelFormat int32, ppfd *PIXELFORMATDESCRIPTOR) bool { - ret, _, _ := syscall.Syscall(setPixelFormat, 3, + ret, _, _ := syscall.Syscall(setPixelFormat.Addr(), 3, uintptr(hdc), uintptr(iPixelFormat), uintptr(unsafe.Pointer(ppfd))) @@ -1480,7 +1867,7 @@ func SetPixelFormat(hdc HDC, iPixelFormat int32, ppfd *PIXELFORMATDESCRIPTOR) bo } func SetStretchBltMode(hdc HDC, iStretchMode int32) int32 { - ret, _, _ := syscall.Syscall(setStretchBltMode, 2, + ret, _, _ := syscall.Syscall(setStretchBltMode.Addr(), 2, uintptr(hdc), uintptr(iStretchMode), 0) @@ -1489,7 +1876,7 @@ func SetStretchBltMode(hdc HDC, iStretchMode int32) int32 { } func SetTextColor(hdc HDC, crColor COLORREF) COLORREF { - ret, _, _ := syscall.Syscall(setTextColor, 2, + ret, _, _ := syscall.Syscall(setTextColor.Addr(), 2, uintptr(hdc), uintptr(crColor), 0) @@ -1497,8 +1884,20 @@ func SetTextColor(hdc HDC, crColor COLORREF) COLORREF { return COLORREF(ret) } +func SetViewportOrgEx(hdc HDC, x, y int32, lpPoint *POINT) COLORREF { + ret, _, _ := syscall.Syscall6(setViewportOrgEx.Addr(), 4, + uintptr(hdc), + uintptr(x), + uintptr(y), + uintptr(unsafe.Pointer(lpPoint)), + 0, + 0) + + return COLORREF(ret) +} + func StartDoc(hdc HDC, lpdi *DOCINFO) int32 { - ret, _, _ := syscall.Syscall(startDoc, 2, + ret, _, _ := syscall.Syscall(startDoc.Addr(), 2, uintptr(hdc), uintptr(unsafe.Pointer(lpdi)), 0) @@ -1507,7 +1906,7 @@ func StartDoc(hdc HDC, lpdi *DOCINFO) int32 { } func StartPage(hdc HDC) int32 { - ret, _, _ := syscall.Syscall(startPage, 1, + ret, _, _ := syscall.Syscall(startPage.Addr(), 1, uintptr(hdc), 0, 0) @@ -1516,7 +1915,7 @@ func StartPage(hdc HDC) int32 { } func StretchBlt(hdcDest HDC, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest int32, hdcSrc HDC, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc int32, dwRop uint32) bool { - ret, _, _ := syscall.Syscall12(stretchBlt, 11, + ret, _, _ := syscall.Syscall12(stretchBlt.Addr(), 11, uintptr(hdcDest), uintptr(nXOriginDest), uintptr(nYOriginDest), @@ -1534,7 +1933,7 @@ func StretchBlt(hdcDest HDC, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest } func SwapBuffers(hdc HDC) bool { - ret, _, _ := syscall.Syscall(swapBuffers, 1, + ret, _, _ := syscall.Syscall(swapBuffers.Addr(), 1, uintptr(hdc), 0, 0) @@ -1543,7 +1942,7 @@ func SwapBuffers(hdc HDC) bool { } func TextOut(hdc HDC, nXStart, nYStart int32, lpString *uint16, cchString int32) bool { - ret, _, _ := syscall.Syscall6(textOut, 5, + ret, _, _ := syscall.Syscall6(textOut.Addr(), 5, uintptr(hdc), uintptr(nXStart), uintptr(nYStart), @@ -1552,3 +1951,21 @@ func TextOut(hdc HDC, nXStart, nYStart int32, lpString *uint16, cchString int32) 0) return ret != 0 } + +func TransparentBlt(hdcDest HDC, xoriginDest, yoriginDest, wDest, hDest int32, hdcSrc HDC, xoriginSrc, yoriginSrc, wSrc, hSrc int32, crTransparent uint32) bool { + ret, _, _ := syscall.Syscall12(transparentBlt.Addr(), 11, + uintptr(hdcDest), + uintptr(xoriginDest), + uintptr(yoriginDest), + uintptr(wDest), + uintptr(hDest), + uintptr(hdcSrc), + uintptr(xoriginSrc), + uintptr(yoriginSrc), + uintptr(wSrc), + uintptr(hSrc), + uintptr(crTransparent), + 0) + + return ret != 0 +} diff --git a/gdiplus.go b/gdiplus.go index ed6774d8..ac2654b2 100644 --- a/gdiplus.go +++ b/gdiplus.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -128,15 +131,15 @@ type ARGB uint32 var ( // Library - libgdiplus uintptr + libgdiplus *windows.LazyDLL // Functions - gdipCreateBitmapFromFile uintptr - gdipCreateBitmapFromHBITMAP uintptr - gdipCreateHBITMAPFromBitmap uintptr - gdipDisposeImage uintptr - gdiplusShutdown uintptr - gdiplusStartup uintptr + gdipCreateBitmapFromFile *windows.LazyProc + gdipCreateBitmapFromHBITMAP *windows.LazyProc + gdipCreateHBITMAPFromBitmap *windows.LazyProc + gdipDisposeImage *windows.LazyProc + gdiplusShutdown *windows.LazyProc + gdiplusStartup *windows.LazyProc ) var ( @@ -145,19 +148,19 @@ var ( func init() { // Library - libgdiplus = MustLoadLibrary("gdiplus.dll") + libgdiplus = windows.NewLazySystemDLL("gdiplus.dll") // Functions - gdipCreateBitmapFromFile = MustGetProcAddress(libgdiplus, "GdipCreateBitmapFromFile") - gdipCreateBitmapFromHBITMAP = MustGetProcAddress(libgdiplus, "GdipCreateBitmapFromHBITMAP") - gdipCreateHBITMAPFromBitmap = MustGetProcAddress(libgdiplus, "GdipCreateHBITMAPFromBitmap") - gdipDisposeImage = MustGetProcAddress(libgdiplus, "GdipDisposeImage") - gdiplusShutdown = MustGetProcAddress(libgdiplus, "GdiplusShutdown") - gdiplusStartup = MustGetProcAddress(libgdiplus, "GdiplusStartup") + gdipCreateBitmapFromFile = libgdiplus.NewProc("GdipCreateBitmapFromFile") + gdipCreateBitmapFromHBITMAP = libgdiplus.NewProc("GdipCreateBitmapFromHBITMAP") + gdipCreateHBITMAPFromBitmap = libgdiplus.NewProc("GdipCreateHBITMAPFromBitmap") + gdipDisposeImage = libgdiplus.NewProc("GdipDisposeImage") + gdiplusShutdown = libgdiplus.NewProc("GdiplusShutdown") + gdiplusStartup = libgdiplus.NewProc("GdiplusStartup") } func GdipCreateBitmapFromFile(filename *uint16, bitmap **GpBitmap) GpStatus { - ret, _, _ := syscall.Syscall(gdipCreateBitmapFromFile, 2, + ret, _, _ := syscall.Syscall(gdipCreateBitmapFromFile.Addr(), 2, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(bitmap)), 0) @@ -166,7 +169,7 @@ func GdipCreateBitmapFromFile(filename *uint16, bitmap **GpBitmap) GpStatus { } func GdipCreateBitmapFromHBITMAP(hbm HBITMAP, hpal HPALETTE, bitmap **GpBitmap) GpStatus { - ret, _, _ := syscall.Syscall(gdipCreateBitmapFromHBITMAP, 3, + ret, _, _ := syscall.Syscall(gdipCreateBitmapFromHBITMAP.Addr(), 3, uintptr(hbm), uintptr(hpal), uintptr(unsafe.Pointer(bitmap))) @@ -175,7 +178,7 @@ func GdipCreateBitmapFromHBITMAP(hbm HBITMAP, hpal HPALETTE, bitmap **GpBitmap) } func GdipCreateHBITMAPFromBitmap(bitmap *GpBitmap, hbmReturn *HBITMAP, background ARGB) GpStatus { - ret, _, _ := syscall.Syscall(gdipCreateHBITMAPFromBitmap, 3, + ret, _, _ := syscall.Syscall(gdipCreateHBITMAPFromBitmap.Addr(), 3, uintptr(unsafe.Pointer(bitmap)), uintptr(unsafe.Pointer(hbmReturn)), uintptr(background)) @@ -184,7 +187,7 @@ func GdipCreateHBITMAPFromBitmap(bitmap *GpBitmap, hbmReturn *HBITMAP, backgroun } func GdipDisposeImage(image *GpImage) GpStatus { - ret, _, _ := syscall.Syscall(gdipDisposeImage, 1, + ret, _, _ := syscall.Syscall(gdipDisposeImage.Addr(), 1, uintptr(unsafe.Pointer(image)), 0, 0) @@ -193,14 +196,14 @@ func GdipDisposeImage(image *GpImage) GpStatus { } func GdiplusShutdown() { - syscall.Syscall(gdiplusShutdown, 1, + syscall.Syscall(gdiplusShutdown.Addr(), 1, token, 0, 0) } func GdiplusStartup(input *GdiplusStartupInput, output *GdiplusStartupOutput) GpStatus { - ret, _, _ := syscall.Syscall(gdiplusStartup, 3, + ret, _, _ := syscall.Syscall(gdiplusStartup.Addr(), 3, uintptr(unsafe.Pointer(&token)), uintptr(unsafe.Pointer(input)), uintptr(unsafe.Pointer(output))) @@ -209,7 +212,7 @@ func GdiplusStartup(input *GdiplusStartupInput, output *GdiplusStartupOutput) Gp } /*GdipSaveImageToFile(image *GpImage, filename *uint16, clsidEncoder *CLSID, encoderParams *EncoderParameters) GpStatus { - ret, _, _ := syscall.Syscall6(gdipSaveImageToFile, 4, + ret, _, _ := syscall.Syscall6(gdipSaveImageToFile.Addr(), 4, uintptr(unsafe.Pointer(image)), uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(clsidEncoder)), diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..c765df89 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/lxn/win + +go 1.12 + +require golang.org/x/sys v0.0.0-20201018230417-eeed37f84f13 diff --git a/header.go b/header.go index d3674f98..4edff2b1 100644 --- a/header.go +++ b/header.go @@ -2,22 +2,9 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package win - -const ( - HDF_SORTDOWN = 0x200 - HDF_SORTUP = 0x400 -) +// +build windows -const ( - HDI_FORMAT = 4 -) - -const ( - HDM_FIRST = 0x1200 - HDM_GETITEM = HDM_FIRST + 11 - HDM_SETITEM = HDM_FIRST + 12 -) +package win const ( HDS_NOSIZING = 0x0800 @@ -36,3 +23,120 @@ type HDITEM struct { Type uint32 PvFilter uintptr } + +type HDLAYOUT struct { + Prc *RECT + Pwpos *WINDOWPOS +} + +type HDHITTESTINFO struct { + Pt POINT + Flags uint32 + IItem int32 +} + +const ( + HDI_WIDTH = 0x0001 + HDI_HEIGHT = HDI_WIDTH + HDI_TEXT = 0x0002 + HDI_FORMAT = 0x0004 + HDI_LPARAM = 0x0008 + HDI_BITMAP = 0x0010 + HDI_IMAGE = 0x0020 + HDI_DI_SETITEM = 0x0040 + HDI_ORDER = 0x0080 + HDI_FILTER = 0x0100 + HDI_STATE = 0x0200 +) + +const ( + HDF_LEFT = 0x0000 + HDF_RIGHT = 0x0001 + HDF_CENTER = 0x0002 + HDF_JUSTIFYMASK = 0x0003 + HDF_RTLREADING = 0x0004 + HDF_CHECKBOX = 0x0040 + HDF_CHECKED = 0x0080 + HDF_FIXEDWIDTH = 0x0100 + HDF_SORTDOWN = 0x0200 + HDF_SORTUP = 0x0400 + HDF_IMAGE = 0x0800 + HDF_BITMAP_ON_RIGHT = 0x1000 + HDF_BITMAP = 0x2000 + HDF_STRING = 0x4000 + HDF_OWNERDRAW = 0x8000 + HDF_SPLITBUTTON = 0x1000000 +) + +const ( + HDIS_FOCUSED = 0x00000001 +) + +const ( + HDM_FIRST = 0x1200 + HDM_GETITEMCOUNT = HDM_FIRST + 0 + HDM_DELETEITEM = HDM_FIRST + 2 + HDM_LAYOUT = HDM_FIRST + 5 + HDM_HITTEST = HDM_FIRST + 6 + HDM_GETITEMRECT = HDM_FIRST + 7 + HDM_SETIMAGELIST = HDM_FIRST + 8 + HDM_GETIMAGELIST = HDM_FIRST + 9 + HDM_INSERTITEM = HDM_FIRST + 10 + HDM_GETITEM = HDM_FIRST + 11 + HDM_SETITEM = HDM_FIRST + 12 + HDM_ORDERTOINDEX = HDM_FIRST + 15 + HDM_CREATEDRAGIMAGE = HDM_FIRST + 16 + HDM_GETORDERARRAY = HDM_FIRST + 17 + HDM_SETORDERARRAY = HDM_FIRST + 18 + HDM_SETHOTDIVIDER = HDM_FIRST + 19 + HDM_SETBITMAPMARGIN = HDM_FIRST + 20 + HDM_GETBITMAPMARGIN = HDM_FIRST + 21 + HDM_SETFILTERCHANGETIMEOUT = HDM_FIRST + 22 + HDM_EDITFILTER = HDM_FIRST + 23 + HDM_CLEARFILTER = HDM_FIRST + 24 + HDM_GETITEMDROPDOWNRECT = HDM_FIRST + 25 + HDM_GETOVERFLOWRECT = HDM_FIRST + 26 + HDM_GETFOCUSEDITEM = HDM_FIRST + 27 + HDM_SETFOCUSEDITEM = HDM_FIRST + 28 + HDM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT + HDM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT +) + +const ( + HHT_NOWHERE = 0x0001 + HHT_ONHEADER = 0x0002 + HHT_ONDIVIDER = 0x0004 + HHT_ONDIVOPEN = 0x0008 + HHT_ONFILTER = 0x0010 + HHT_ONFILTERBUTTON = 0x0020 + HHT_ABOVE = 0x0100 + HHT_BELOW = 0x0200 + HHT_TORIGHT = 0x0400 + HHT_TOLEFT = 0x0800 + HHT_ONITEMSTATEICON = 0x1000 + HHT_ONDROPDOWN = 0x2000 + HHT_ONOVERFLOW = 0x4000 +) + +const ( + HDN_FIRST = ^uint32(300) + HDN_BEGINDRAG = HDN_FIRST - 10 + HDN_ENDDRAG = HDN_FIRST - 11 + HDN_FILTERCHANGE = HDN_FIRST - 12 + HDN_FILTERBTNCLICK = HDN_FIRST - 13 + HDN_BEGINFILTEREDIT = HDN_FIRST - 14 + HDN_ENDFILTEREDIT = HDN_FIRST - 15 + HDN_ITEMSTATEICONCLICK = HDN_FIRST - 16 + HDN_ITEMKEYDOWN = HDN_FIRST - 17 + HDN_DROPDOWN = HDN_FIRST - 18 + HDN_OVERFLOWCLICK = HDN_FIRST - 19 + HDN_ITEMCHANGING = HDN_FIRST - 20 + HDN_ITEMCHANGED = HDN_FIRST - 21 + HDN_ITEMCLICK = HDN_FIRST - 22 + HDN_ITEMDBLCLICK = HDN_FIRST - 23 + HDN_DIVIDERDBLCLICK = HDN_FIRST - 25 + HDN_BEGINTRACK = HDN_FIRST - 26 + HDN_ENDTRACK = HDN_FIRST - 27 + HDN_TRACK = HDN_FIRST - 28 + HDN_GETDISPINFO = HDN_FIRST - 29 +) diff --git a/kernel32.go b/kernel32.go index ce1bfcec..4c9e512d 100644 --- a/kernel32.go +++ b/kernel32.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -14,6 +17,7 @@ const MAX_PATH = 260 // Error codes const ( ERROR_SUCCESS = 0 + ERROR_INVALID_FUNCTION = 1 ERROR_FILE_NOT_FOUND = 2 ERROR_INVALID_PARAMETER = 87 ERROR_INSUFFICIENT_BUFFER = 122 @@ -26,7 +30,7 @@ const ( GMEM_FIXED = 0x0000 GMEM_MOVEABLE = 0x0002 GMEM_ZEROINIT = 0x0040 - GPTR = 0x004 + GPTR = GMEM_FIXED | GMEM_ZEROINIT ) // Predefined locale ids @@ -51,36 +55,51 @@ const ( var ( // Library - libkernel32 uintptr + libkernel32 *windows.LazyDLL // Functions - closeHandle uintptr - fileTimeToSystemTime uintptr - getLastError uintptr - getLocaleInfo uintptr - getLogicalDriveStrings uintptr - getModuleHandle uintptr - getNumberFormat uintptr - getThreadLocale uintptr - getVersion uintptr - globalAlloc uintptr - globalFree uintptr - globalLock uintptr - globalUnlock uintptr - moveMemory uintptr - mulDiv uintptr - setLastError uintptr - systemTimeToFileTime uintptr - getProfileString uintptr + activateActCtx *windows.LazyProc + closeHandle *windows.LazyProc + createActCtx *windows.LazyProc + fileTimeToSystemTime *windows.LazyProc + findResource *windows.LazyProc + getConsoleTitle *windows.LazyProc + getConsoleWindow *windows.LazyProc + getCurrentThreadId *windows.LazyProc + getLastError *windows.LazyProc + getLocaleInfo *windows.LazyProc + getLogicalDriveStrings *windows.LazyProc + getModuleHandle *windows.LazyProc + getNumberFormat *windows.LazyProc + getPhysicallyInstalledSystemMemory *windows.LazyProc + getProfileString *windows.LazyProc + getThreadLocale *windows.LazyProc + getThreadUILanguage *windows.LazyProc + getVersion *windows.LazyProc + globalAlloc *windows.LazyProc + globalFree *windows.LazyProc + globalLock *windows.LazyProc + globalUnlock *windows.LazyProc + moveMemory *windows.LazyProc + mulDiv *windows.LazyProc + loadResource *windows.LazyProc + lockResource *windows.LazyProc + setLastError *windows.LazyProc + sizeofResource *windows.LazyProc + systemTimeToFileTime *windows.LazyProc ) type ( - ATOM uint16 - HANDLE uintptr - HGLOBAL HANDLE - HINSTANCE HANDLE - LCID uint32 - LCTYPE uint32 + ATOM uint16 + HANDLE uintptr + HGLOBAL HANDLE + HINSTANCE HANDLE + LCID uint32 + LCTYPE uint32 + LANGID uint16 + HMODULE uintptr + HWINEVENTHOOK HANDLE + HRSRC uintptr ) type FILETIME struct { @@ -108,34 +127,65 @@ type SYSTEMTIME struct { WMilliseconds uint16 } +type ACTCTX struct { + size uint32 + Flags uint32 + Source *uint16 // UTF-16 string + ProcessorArchitecture uint16 + LangID uint16 + AssemblyDirectory *uint16 // UTF-16 string + ResourceName *uint16 // UTF-16 string + ApplicationName *uint16 // UTF-16 string + Module HMODULE +} + func init() { // Library - libkernel32 = MustLoadLibrary("kernel32.dll") + libkernel32 = windows.NewLazySystemDLL("kernel32.dll") // Functions - closeHandle = MustGetProcAddress(libkernel32, "CloseHandle") - fileTimeToSystemTime = MustGetProcAddress(libkernel32, "FileTimeToSystemTime") - getLastError = MustGetProcAddress(libkernel32, "GetLastError") - getLocaleInfo = MustGetProcAddress(libkernel32, "GetLocaleInfoW") - getLogicalDriveStrings = MustGetProcAddress(libkernel32, "GetLogicalDriveStringsW") - getModuleHandle = MustGetProcAddress(libkernel32, "GetModuleHandleW") - getNumberFormat = MustGetProcAddress(libkernel32, "GetNumberFormatW") - getProfileString = MustGetProcAddress(libkernel32, "GetProfileStringW") - getThreadLocale = MustGetProcAddress(libkernel32, "GetThreadLocale") - getVersion = MustGetProcAddress(libkernel32, "GetVersion") - globalAlloc = MustGetProcAddress(libkernel32, "GlobalAlloc") - globalFree = MustGetProcAddress(libkernel32, "GlobalFree") - globalLock = MustGetProcAddress(libkernel32, "GlobalLock") - globalUnlock = MustGetProcAddress(libkernel32, "GlobalUnlock") - moveMemory = MustGetProcAddress(libkernel32, "RtlMoveMemory") - mulDiv = MustGetProcAddress(libkernel32, "MulDiv") - setLastError = MustGetProcAddress(libkernel32, "SetLastError") - systemTimeToFileTime = MustGetProcAddress(libkernel32, "SystemTimeToFileTime") + activateActCtx = libkernel32.NewProc("ActivateActCtx") + closeHandle = libkernel32.NewProc("CloseHandle") + createActCtx = libkernel32.NewProc("CreateActCtxW") + fileTimeToSystemTime = libkernel32.NewProc("FileTimeToSystemTime") + findResource = libkernel32.NewProc("FindResourceW") + getConsoleTitle = libkernel32.NewProc("GetConsoleTitleW") + getConsoleWindow = libkernel32.NewProc("GetConsoleWindow") + getCurrentThreadId = libkernel32.NewProc("GetCurrentThreadId") + getLastError = libkernel32.NewProc("GetLastError") + getLocaleInfo = libkernel32.NewProc("GetLocaleInfoW") + getLogicalDriveStrings = libkernel32.NewProc("GetLogicalDriveStringsW") + getModuleHandle = libkernel32.NewProc("GetModuleHandleW") + getNumberFormat = libkernel32.NewProc("GetNumberFormatW") + getPhysicallyInstalledSystemMemory = libkernel32.NewProc("GetPhysicallyInstalledSystemMemory") + getProfileString = libkernel32.NewProc("GetProfileStringW") + getThreadLocale = libkernel32.NewProc("GetThreadLocale") + getThreadUILanguage = libkernel32.NewProc("GetThreadUILanguage") + getVersion = libkernel32.NewProc("GetVersion") + globalAlloc = libkernel32.NewProc("GlobalAlloc") + globalFree = libkernel32.NewProc("GlobalFree") + globalLock = libkernel32.NewProc("GlobalLock") + globalUnlock = libkernel32.NewProc("GlobalUnlock") + moveMemory = libkernel32.NewProc("RtlMoveMemory") + mulDiv = libkernel32.NewProc("MulDiv") + loadResource = libkernel32.NewProc("LoadResource") + lockResource = libkernel32.NewProc("LockResource") + setLastError = libkernel32.NewProc("SetLastError") + sizeofResource = libkernel32.NewProc("SizeofResource") + systemTimeToFileTime = libkernel32.NewProc("SystemTimeToFileTime") +} +func ActivateActCtx(ctx HANDLE) (uintptr, bool) { + var cookie uintptr + ret, _, _ := syscall.Syscall(activateActCtx.Addr(), 2, + uintptr(ctx), + uintptr(unsafe.Pointer(&cookie)), + 0) + return cookie, ret != 0 } func CloseHandle(hObject HANDLE) bool { - ret, _, _ := syscall.Syscall(closeHandle, 1, + ret, _, _ := syscall.Syscall(closeHandle.Addr(), 1, uintptr(hObject), 0, 0) @@ -143,8 +193,21 @@ func CloseHandle(hObject HANDLE) bool { return ret != 0 } +func CreateActCtx(ctx *ACTCTX) HANDLE { + if ctx != nil { + ctx.size = uint32(unsafe.Sizeof(*ctx)) + } + ret, _, _ := syscall.Syscall( + createActCtx.Addr(), + 1, + uintptr(unsafe.Pointer(ctx)), + 0, + 0) + return HANDLE(ret) +} + func FileTimeToSystemTime(lpFileTime *FILETIME, lpSystemTime *SYSTEMTIME) bool { - ret, _, _ := syscall.Syscall(fileTimeToSystemTime, 2, + ret, _, _ := syscall.Syscall(fileTimeToSystemTime.Addr(), 2, uintptr(unsafe.Pointer(lpFileTime)), uintptr(unsafe.Pointer(lpSystemTime)), 0) @@ -152,8 +215,44 @@ func FileTimeToSystemTime(lpFileTime *FILETIME, lpSystemTime *SYSTEMTIME) bool { return ret != 0 } +func FindResource(hModule HMODULE, lpName, lpType *uint16) HRSRC { + ret, _, _ := syscall.Syscall(findResource.Addr(), 3, + uintptr(hModule), + uintptr(unsafe.Pointer(lpName)), + uintptr(unsafe.Pointer(lpType))) + + return HRSRC(ret) +} + +func GetConsoleTitle(lpConsoleTitle *uint16, nSize uint32) uint32 { + ret, _, _ := syscall.Syscall(getConsoleTitle.Addr(), 2, + uintptr(unsafe.Pointer(lpConsoleTitle)), + uintptr(nSize), + 0) + + return uint32(ret) +} + +func GetConsoleWindow() HWND { + ret, _, _ := syscall.Syscall(getConsoleWindow.Addr(), 0, + 0, + 0, + 0) + + return HWND(ret) +} + +func GetCurrentThreadId() uint32 { + ret, _, _ := syscall.Syscall(getCurrentThreadId.Addr(), 0, + 0, + 0, + 0) + + return uint32(ret) +} + func GetLastError() uint32 { - ret, _, _ := syscall.Syscall(getLastError, 0, + ret, _, _ := syscall.Syscall(getLastError.Addr(), 0, 0, 0, 0) @@ -162,7 +261,7 @@ func GetLastError() uint32 { } func GetLocaleInfo(Locale LCID, LCType LCTYPE, lpLCData *uint16, cchData int32) int32 { - ret, _, _ := syscall.Syscall6(getLocaleInfo, 4, + ret, _, _ := syscall.Syscall6(getLocaleInfo.Addr(), 4, uintptr(Locale), uintptr(LCType), uintptr(unsafe.Pointer(lpLCData)), @@ -174,7 +273,7 @@ func GetLocaleInfo(Locale LCID, LCType LCTYPE, lpLCData *uint16, cchData int32) } func GetLogicalDriveStrings(nBufferLength uint32, lpBuffer *uint16) uint32 { - ret, _, _ := syscall.Syscall(getLogicalDriveStrings, 2, + ret, _, _ := syscall.Syscall(getLogicalDriveStrings.Addr(), 2, uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer)), 0) @@ -183,7 +282,7 @@ func GetLogicalDriveStrings(nBufferLength uint32, lpBuffer *uint16) uint32 { } func GetModuleHandle(lpModuleName *uint16) HINSTANCE { - ret, _, _ := syscall.Syscall(getModuleHandle, 1, + ret, _, _ := syscall.Syscall(getModuleHandle.Addr(), 1, uintptr(unsafe.Pointer(lpModuleName)), 0, 0) @@ -192,7 +291,7 @@ func GetModuleHandle(lpModuleName *uint16) HINSTANCE { } func GetNumberFormat(Locale LCID, dwFlags uint32, lpValue *uint16, lpFormat *NUMBERFMT, lpNumberStr *uint16, cchNumber int32) int32 { - ret, _, _ := syscall.Syscall6(getNumberFormat, 6, + ret, _, _ := syscall.Syscall6(getNumberFormat.Addr(), 6, uintptr(Locale), uintptr(dwFlags), uintptr(unsafe.Pointer(lpValue)), @@ -203,8 +302,20 @@ func GetNumberFormat(Locale LCID, dwFlags uint32, lpValue *uint16, lpFormat *NUM return int32(ret) } +func GetPhysicallyInstalledSystemMemory(totalMemoryInKilobytes *uint64) bool { + if getPhysicallyInstalledSystemMemory.Find() != nil { + return false + } + ret, _, _ := syscall.Syscall(getPhysicallyInstalledSystemMemory.Addr(), 1, + uintptr(unsafe.Pointer(totalMemoryInKilobytes)), + 0, + 0) + + return ret != 0 +} + func GetProfileString(lpAppName, lpKeyName, lpDefault *uint16, lpReturnedString uintptr, nSize uint32) bool { - ret, _, _ := syscall.Syscall6(getProfileString, 5, + ret, _, _ := syscall.Syscall6(getProfileString.Addr(), 5, uintptr(unsafe.Pointer(lpAppName)), uintptr(unsafe.Pointer(lpKeyName)), uintptr(unsafe.Pointer(lpDefault)), @@ -215,7 +326,7 @@ func GetProfileString(lpAppName, lpKeyName, lpDefault *uint16, lpReturnedString } func GetThreadLocale() LCID { - ret, _, _ := syscall.Syscall(getThreadLocale, 0, + ret, _, _ := syscall.Syscall(getThreadLocale.Addr(), 0, 0, 0, 0) @@ -223,16 +334,29 @@ func GetThreadLocale() LCID { return LCID(ret) } -func GetVersion() int64 { - ret, _, _ := syscall.Syscall(getVersion, 0, +func GetThreadUILanguage() LANGID { + if getThreadUILanguage.Find() != nil { + return 0 + } + + ret, _, _ := syscall.Syscall(getThreadUILanguage.Addr(), 0, 0, 0, 0) - return int64(ret) + + return LANGID(ret) +} + +func GetVersion() uint32 { + ret, _, _ := syscall.Syscall(getVersion.Addr(), 0, + 0, + 0, + 0) + return uint32(ret) } func GlobalAlloc(uFlags uint32, dwBytes uintptr) HGLOBAL { - ret, _, _ := syscall.Syscall(globalAlloc, 2, + ret, _, _ := syscall.Syscall(globalAlloc.Addr(), 2, uintptr(uFlags), dwBytes, 0) @@ -241,7 +365,7 @@ func GlobalAlloc(uFlags uint32, dwBytes uintptr) HGLOBAL { } func GlobalFree(hMem HGLOBAL) HGLOBAL { - ret, _, _ := syscall.Syscall(globalFree, 1, + ret, _, _ := syscall.Syscall(globalFree.Addr(), 1, uintptr(hMem), 0, 0) @@ -250,7 +374,7 @@ func GlobalFree(hMem HGLOBAL) HGLOBAL { } func GlobalLock(hMem HGLOBAL) unsafe.Pointer { - ret, _, _ := syscall.Syscall(globalLock, 1, + ret, _, _ := syscall.Syscall(globalLock.Addr(), 1, uintptr(hMem), 0, 0) @@ -259,7 +383,7 @@ func GlobalLock(hMem HGLOBAL) unsafe.Pointer { } func GlobalUnlock(hMem HGLOBAL) bool { - ret, _, _ := syscall.Syscall(globalUnlock, 1, + ret, _, _ := syscall.Syscall(globalUnlock.Addr(), 1, uintptr(hMem), 0, 0) @@ -268,14 +392,14 @@ func GlobalUnlock(hMem HGLOBAL) bool { } func MoveMemory(destination, source unsafe.Pointer, length uintptr) { - syscall.Syscall(moveMemory, 3, + syscall.Syscall(moveMemory.Addr(), 3, uintptr(unsafe.Pointer(destination)), uintptr(source), uintptr(length)) } func MulDiv(nNumber, nNumerator, nDenominator int32) int32 { - ret, _, _ := syscall.Syscall(mulDiv, 3, + ret, _, _ := syscall.Syscall(mulDiv.Addr(), 3, uintptr(nNumber), uintptr(nNumerator), uintptr(nDenominator)) @@ -283,15 +407,42 @@ func MulDiv(nNumber, nNumerator, nDenominator int32) int32 { return int32(ret) } +func LoadResource(hModule HMODULE, hResInfo HRSRC) HGLOBAL { + ret, _, _ := syscall.Syscall(loadResource.Addr(), 2, + uintptr(hModule), + uintptr(hResInfo), + 0) + + return HGLOBAL(ret) +} + +func LockResource(hResData HGLOBAL) uintptr { + ret, _, _ := syscall.Syscall(lockResource.Addr(), 1, + uintptr(hResData), + 0, + 0) + + return ret +} + func SetLastError(dwErrorCode uint32) { - syscall.Syscall(setLastError, 1, + syscall.Syscall(setLastError.Addr(), 1, uintptr(dwErrorCode), 0, 0) } +func SizeofResource(hModule HMODULE, hResInfo HRSRC) uint32 { + ret, _, _ := syscall.Syscall(sizeofResource.Addr(), 2, + uintptr(hModule), + uintptr(hResInfo), + 0) + + return uint32(ret) +} + func SystemTimeToFileTime(lpSystemTime *SYSTEMTIME, lpFileTime *FILETIME) bool { - ret, _, _ := syscall.Syscall(systemTimeToFileTime, 2, + ret, _, _ := syscall.Syscall(systemTimeToFileTime.Addr(), 2, uintptr(unsafe.Pointer(lpSystemTime)), uintptr(unsafe.Pointer(lpFileTime)), 0) diff --git a/listbox.go b/listbox.go index 99ef3ab3..abb872bb 100644 --- a/listbox.go +++ b/listbox.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // ListBox style diff --git a/listview.go b/listview.go index b48df5fc..31893a00 100644 --- a/listview.go +++ b/listview.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win const ( @@ -18,6 +20,7 @@ const ( // ListView messages const ( LVM_FIRST = 0x1000 + LVM_SETBKCOLOR = LVM_FIRST + 1 LVM_SETIMAGELIST = LVM_FIRST + 3 LVM_GETITEM = LVM_FIRST + 75 LVM_SETITEM = LVM_FIRST + 76 @@ -133,7 +136,7 @@ const ( // ListView notifications const ( - LVN_FIRST = -100 + LVN_FIRST = ^uint32(99) // -100 LVN_ITEMCHANGING = LVN_FIRST - 0 LVN_ITEMCHANGED = LVN_FIRST - 1 @@ -366,3 +369,9 @@ type NMLVDISPINFO struct { Hdr NMHDR Item LVITEM } + +type NMLVSCROLL struct { + Hdr NMHDR + Dx int32 + Dy int32 +} diff --git a/menu.go b/menu.go index 69fc3738..c9dad192 100644 --- a/menu.go +++ b/menu.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // Constants for MENUITEMINFO.fMask @@ -19,27 +21,27 @@ const ( // Constants for MENUITEMINFO.fType const ( - MFT_BITMAP = 4 - MFT_MENUBARBREAK = 32 - MFT_MENUBREAK = 64 - MFT_OWNERDRAW = 256 - MFT_RADIOCHECK = 512 - MFT_RIGHTJUSTIFY = 0x4000 - MFT_SEPARATOR = 0x800 - MFT_RIGHTORDER = 0x2000 - MFT_STRING = 0 + MFT_STRING = MF_STRING + MFT_BITMAP = MF_BITMAP + MFT_MENUBARBREAK = MF_MENUBARBREAK + MFT_MENUBREAK = MF_MENUBREAK + MFT_OWNERDRAW = MF_OWNERDRAW + MFT_RADIOCHECK = 0x00000200 + MFT_SEPARATOR = MF_SEPARATOR + MFT_RIGHTORDER = 0x00002000 + MFT_RIGHTJUSTIFY = MF_RIGHTJUSTIFY ) // Constants for MENUITEMINFO.fState const ( - MFS_CHECKED = 8 - MFS_DEFAULT = 4096 - MFS_DISABLED = 3 - MFS_ENABLED = 0 - MFS_GRAYED = 3 - MFS_HILITE = 128 - MFS_UNCHECKED = 0 - MFS_UNHILITE = 0 + MFS_GRAYED = 0x00000003 + MFS_DISABLED = MFS_GRAYED + MFS_CHECKED = MF_CHECKED + MFS_HILITE = MF_HILITE + MFS_ENABLED = MF_ENABLED + MFS_UNCHECKED = MF_UNCHECKED + MFS_UNHILITE = MF_UNHILITE + MFS_DEFAULT = MF_DEFAULT ) // Constants for MENUITEMINFO.hbmp* @@ -78,8 +80,43 @@ const ( ) const ( + // Menu flags for Add/Check/EnableMenuItem() + MF_INSERT = 0x00000000 + MF_CHANGE = 0x00000080 + MF_APPEND = 0x00000100 + MF_DELETE = 0x00000200 + MF_REMOVE = 0x00001000 + MF_BYCOMMAND = 0x00000000 MF_BYPOSITION = 0x00000400 + + MF_SEPARATOR = 0x00000800 + + MF_ENABLED = 0x00000000 + MF_GRAYED = 0x00000001 + MF_DISABLED = 0x00000002 + + MF_UNCHECKED = 0x00000000 + MF_CHECKED = 0x00000008 + MF_USECHECKBITMAPS = 0x00000200 + + MF_STRING = 0x00000000 + MF_BITMAP = 0x00000004 + MF_OWNERDRAW = 0x00000100 + + MF_POPUP = 0x00000010 + MF_MENUBARBREAK = 0x00000020 + MF_MENUBREAK = 0x00000040 + + MF_UNHILITE = 0x00000000 + MF_HILITE = 0x00000080 + + MF_DEFAULT = 0x00001000 + MF_SYSMENU = 0x00002000 + MF_HELP = 0x00004000 + MF_RIGHTJUSTIFY = 0x00004000 + + MF_MOUSESELECT = 0x00008000 ) type MENUITEMINFO struct { diff --git a/oaidl.go b/oaidl.go new file mode 100644 index 00000000..c209866a --- /dev/null +++ b/oaidl.go @@ -0,0 +1,81 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +import ( + "syscall" + "unsafe" +) + +type SCODE int32 + +type EXCEPINFO struct { + wCode uint16 + wReserved uint16 + bstrSource *uint16 /*BSTR*/ + bstrDescription *uint16 /*BSTR*/ + bstrHelpFile *uint16 /*BSTR*/ + dwHelpContext uint32 + pvReserved uintptr + pfnDeferredFillIn uintptr + scode SCODE +} + +var ( + IID_ITypeInfo = IID{0x00020401, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} +) + +type ITypeInfoVtbl struct { + IUnknownVtbl + GetTypeAttr uintptr + GetTypeComp uintptr + GetFuncDesc uintptr + GetVarDesc uintptr + GetNames uintptr + GetRefTypeOfImplType uintptr + GetImplTypeFlags uintptr + GetIDsOfNames uintptr + Invoke uintptr + GetDocumentation uintptr + GetDllEntry uintptr + GetRefTypeInfo uintptr + AddressOfMember uintptr + CreateInstance uintptr + GetMops uintptr + GetContainingTypeLib uintptr + ReleaseTypeAttr uintptr + ReleaseFuncDesc uintptr + ReleaseVarDesc uintptr +} + +type ITypeInfo struct { + LpVtbl *ITypeInfoVtbl +} + +func (obj *ITypeInfo) QueryInterface(riid REFIID, ppvObject *unsafe.Pointer) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.QueryInterface, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(ppvObject))) + return HRESULT(ret) +} + +func (obj *ITypeInfo) AddRef() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.AddRef, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *ITypeInfo) Release() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Release, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} diff --git a/objidl.go b/objidl.go new file mode 100644 index 00000000..12f1ceb3 --- /dev/null +++ b/objidl.go @@ -0,0 +1,47 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +type IDataObjectVtbl struct { + IUnknownVtbl + GetData uintptr + GetDataHere uintptr + QueryGetData uintptr + GetCanonicalFormatEtc uintptr + SetData uintptr + EnumFormatEtc uintptr + DAdvise uintptr + DUnadvise uintptr + EnumDAdvise uintptr +} + +type IDataObject struct { + LpVtbl *IDataObjectVtbl +} + +type IStorageVtbl struct { + IUnknownVtbl + CreateStream uintptr + OpenStream uintptr + CreateStorage uintptr + OpenStorage uintptr + CopyTo uintptr + MoveElementTo uintptr + Commit uintptr + Revert uintptr + EnumElements uintptr + DestroyElement uintptr + RenameElement uintptr + SetElementTimes uintptr + SetClass uintptr + SetStateBits uintptr + Stat uintptr +} + +type IStorage struct { + LpVtbl *IStorageVtbl +} diff --git a/ole32.go b/ole32.go index 7e733cf7..e257a69a 100644 --- a/ole32.go +++ b/ole32.go @@ -2,11 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( "syscall" "unsafe" + + "golang.org/x/sys/windows" ) const ( @@ -32,7 +36,16 @@ const ( CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000 CLSCTX_ENABLE_CLOAKING = 0x100000 CLSCTX_PS_DLL = 0x80000000 + CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER + CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER +) + +const ( + COINIT_APARTMENTTHREADED = 0x2 // Apartment model + COINIT_MULTITHREADED = 0x0 // OLE calls objects on any thread. + COINIT_DISABLE_OLE1DDE = 0x4 // Don't use DDE for Ole1 support. + COINIT_SPEED_OVER_MEMORY = 0x8 // Trade memory for speed. ) // Verbs for IOleObject.DoVerb @@ -53,8 +66,8 @@ const ( OLECLOSE_PROMPTSAVE = 2 ) -type IID GUID -type CLSID GUID +type IID syscall.GUID +type CLSID syscall.GUID type REFIID *IID type REFCLSID *CLSID @@ -417,32 +430,36 @@ type COSERVERINFO struct { var ( // Library - libole32 uintptr + libole32 *windows.LazyDLL // Functions - coCreateInstance uintptr - coGetClassObject uintptr - coTaskMemFree uintptr - oleInitialize uintptr - oleSetContainedObject uintptr - oleUninitialize uintptr + coCreateInstance *windows.LazyProc + coGetClassObject *windows.LazyProc + coInitializeEx *windows.LazyProc + coTaskMemFree *windows.LazyProc + coUninitialize *windows.LazyProc + oleInitialize *windows.LazyProc + oleSetContainedObject *windows.LazyProc + oleUninitialize *windows.LazyProc ) func init() { // Library - libole32 = MustLoadLibrary("ole32.dll") + libole32 = windows.NewLazySystemDLL("ole32.dll") // Functions - coCreateInstance = MustGetProcAddress(libole32, "CoCreateInstance") - coGetClassObject = MustGetProcAddress(libole32, "CoGetClassObject") - coTaskMemFree = MustGetProcAddress(libole32, "CoTaskMemFree") - oleInitialize = MustGetProcAddress(libole32, "OleInitialize") - oleSetContainedObject = MustGetProcAddress(libole32, "OleSetContainedObject") - oleUninitialize = MustGetProcAddress(libole32, "OleUninitialize") + coCreateInstance = libole32.NewProc("CoCreateInstance") + coGetClassObject = libole32.NewProc("CoGetClassObject") + coInitializeEx = libole32.NewProc("CoInitializeEx") + coTaskMemFree = libole32.NewProc("CoTaskMemFree") + coUninitialize = libole32.NewProc("CoUninitialize") + oleInitialize = libole32.NewProc("OleInitialize") + oleSetContainedObject = libole32.NewProc("OleSetContainedObject") + oleUninitialize = libole32.NewProc("OleUninitialize") } func CoCreateInstance(rclsid REFCLSID, pUnkOuter *IUnknown, dwClsContext uint32, riid REFIID, ppv *unsafe.Pointer) HRESULT { - ret, _, _ := syscall.Syscall6(coCreateInstance, 5, + ret, _, _ := syscall.Syscall6(coCreateInstance.Addr(), 5, uintptr(unsafe.Pointer(rclsid)), uintptr(unsafe.Pointer(pUnkOuter)), uintptr(dwClsContext), @@ -454,7 +471,7 @@ func CoCreateInstance(rclsid REFCLSID, pUnkOuter *IUnknown, dwClsContext uint32, } func CoGetClassObject(rclsid REFCLSID, dwClsContext uint32, pServerInfo *COSERVERINFO, riid REFIID, ppv *unsafe.Pointer) HRESULT { - ret, _, _ := syscall.Syscall6(coGetClassObject, 5, + ret, _, _ := syscall.Syscall6(coGetClassObject.Addr(), 5, uintptr(unsafe.Pointer(rclsid)), uintptr(dwClsContext), uintptr(unsafe.Pointer(pServerInfo)), @@ -465,15 +482,31 @@ func CoGetClassObject(rclsid REFCLSID, dwClsContext uint32, pServerInfo *COSERVE return HRESULT(ret) } +func CoInitializeEx(reserved unsafe.Pointer, coInit uint32) HRESULT { + ret, _, _ := syscall.Syscall(coInitializeEx.Addr(), 2, + uintptr(reserved), + uintptr(coInit), + 0) + + return HRESULT(ret) +} + +func CoUninitialize() { + syscall.Syscall(coUninitialize.Addr(), 0, + 0, + 0, + 0) +} + func CoTaskMemFree(pv uintptr) { - syscall.Syscall(coTaskMemFree, 1, + syscall.Syscall(coTaskMemFree.Addr(), 1, pv, 0, 0) } func OleInitialize() HRESULT { - ret, _, _ := syscall.Syscall(oleInitialize, 1, // WTF, why does 0 not work here? + ret, _, _ := syscall.Syscall(oleInitialize.Addr(), 1, // WTF, why does 0 not work here? 0, 0, 0) @@ -482,7 +515,7 @@ func OleInitialize() HRESULT { } func OleSetContainedObject(pUnknown *IUnknown, fContained bool) HRESULT { - ret, _, _ := syscall.Syscall(oleSetContainedObject, 2, + ret, _, _ := syscall.Syscall(oleSetContainedObject.Addr(), 2, uintptr(unsafe.Pointer(pUnknown)), uintptr(BoolToBOOL(fContained)), 0) @@ -491,7 +524,7 @@ func OleSetContainedObject(pUnknown *IUnknown, fContained bool) HRESULT { } func OleUninitialize() { - syscall.Syscall(oleUninitialize, 0, + syscall.Syscall(oleUninitialize.Addr(), 0, 0, 0, 0) diff --git a/oleacc.go b/oleacc.go new file mode 100644 index 00000000..4891cc16 --- /dev/null +++ b/oleacc.go @@ -0,0 +1,420 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +import ( + "syscall" + "unsafe" +) + +type AnnoScope int + +const ( + ANNO_THIS = AnnoScope(0) + ANNO_CONTAINER = AnnoScope(1) +) + +type MSAAPROPID syscall.GUID + +var ( + PROPID_ACC_NAME = MSAAPROPID{0x608d3df8, 0x8128, 0x4aa7, [8]byte{0xa4, 0x28, 0xf5, 0x5e, 0x49, 0x26, 0x72, 0x91}} + PROPID_ACC_VALUE = MSAAPROPID{0x123fe443, 0x211a, 0x4615, [8]byte{0x95, 0x27, 0xc4, 0x5a, 0x7e, 0x93, 0x71, 0x7a}} + PROPID_ACC_DESCRIPTION = MSAAPROPID{0x4d48dfe4, 0xbd3f, 0x491f, [8]byte{0xa6, 0x48, 0x49, 0x2d, 0x6f, 0x20, 0xc5, 0x88}} + PROPID_ACC_ROLE = MSAAPROPID{0xcb905ff2, 0x7bd1, 0x4c05, [8]byte{0xb3, 0xc8, 0xe6, 0xc2, 0x41, 0x36, 0x4d, 0x70}} + PROPID_ACC_STATE = MSAAPROPID{0xa8d4d5b0, 0x0a21, 0x42d0, [8]byte{0xa5, 0xc0, 0x51, 0x4e, 0x98, 0x4f, 0x45, 0x7b}} + PROPID_ACC_HELP = MSAAPROPID{0xc831e11f, 0x44db, 0x4a99, [8]byte{0x97, 0x68, 0xcb, 0x8f, 0x97, 0x8b, 0x72, 0x31}} + PROPID_ACC_KEYBOARDSHORTCUT = MSAAPROPID{0x7d9bceee, 0x7d1e, 0x4979, [8]byte{0x93, 0x82, 0x51, 0x80, 0xf4, 0x17, 0x2c, 0x34}} + PROPID_ACC_DEFAULTACTION = MSAAPROPID{0x180c072b, 0xc27f, 0x43c7, [8]byte{0x99, 0x22, 0xf6, 0x35, 0x62, 0xa4, 0x63, 0x2b}} + PROPID_ACC_HELPTOPIC = MSAAPROPID{0x787d1379, 0x8ede, 0x440b, [8]byte{0x8a, 0xec, 0x11, 0xf7, 0xbf, 0x90, 0x30, 0xb3}} + PROPID_ACC_FOCUS = MSAAPROPID{0x6eb335df, 0x1c29, 0x4127, [8]byte{0xb1, 0x2c, 0xde, 0xe9, 0xfd, 0x15, 0x7f, 0x2b}} + PROPID_ACC_SELECTION = MSAAPROPID{0xb99d073c, 0xd731, 0x405b, [8]byte{0x90, 0x61, 0xd9, 0x5e, 0x8f, 0x84, 0x29, 0x84}} + PROPID_ACC_PARENT = MSAAPROPID{0x474c22b6, 0xffc2, 0x467a, [8]byte{0xb1, 0xb5, 0xe9, 0x58, 0xb4, 0x65, 0x73, 0x30}} + PROPID_ACC_NAV_UP = MSAAPROPID{0x016e1a2b, 0x1a4e, 0x4767, [8]byte{0x86, 0x12, 0x33, 0x86, 0xf6, 0x69, 0x35, 0xec}} + PROPID_ACC_NAV_DOWN = MSAAPROPID{0x031670ed, 0x3cdf, 0x48d2, [8]byte{0x96, 0x13, 0x13, 0x8f, 0x2d, 0xd8, 0xa6, 0x68}} + PROPID_ACC_NAV_LEFT = MSAAPROPID{0x228086cb, 0x82f1, 0x4a39, [8]byte{0x87, 0x05, 0xdc, 0xdc, 0x0f, 0xff, 0x92, 0xf5}} + PROPID_ACC_NAV_RIGHT = MSAAPROPID{0xcd211d9f, 0xe1cb, 0x4fe5, [8]byte{0xa7, 0x7c, 0x92, 0x0b, 0x88, 0x4d, 0x09, 0x5b}} + PROPID_ACC_NAV_PREV = MSAAPROPID{0x776d3891, 0xc73b, 0x4480, [8]byte{0xb3, 0xf6, 0x07, 0x6a, 0x16, 0xa1, 0x5a, 0xf6}} + PROPID_ACC_NAV_NEXT = MSAAPROPID{0x1cdc5455, 0x8cd9, 0x4c92, [8]byte{0xa3, 0x71, 0x39, 0x39, 0xa2, 0xfe, 0x3e, 0xee}} + PROPID_ACC_NAV_FIRSTCHILD = MSAAPROPID{0xcfd02558, 0x557b, 0x4c67, [8]byte{0x84, 0xf9, 0x2a, 0x09, 0xfc, 0xe4, 0x07, 0x49}} + PROPID_ACC_NAV_LASTCHILD = MSAAPROPID{0x302ecaa5, 0x48d5, 0x4f8d, [8]byte{0xb6, 0x71, 0x1a, 0x8d, 0x20, 0xa7, 0x78, 0x32}} + PROPID_ACC_ROLEMAP = MSAAPROPID{0xf79acda2, 0x140d, 0x4fe6, [8]byte{0x89, 0x14, 0x20, 0x84, 0x76, 0x32, 0x82, 0x69}} + PROPID_ACC_VALUEMAP = MSAAPROPID{0xda1c3d79, 0xfc5c, 0x420e, [8]byte{0xb3, 0x99, 0x9d, 0x15, 0x33, 0x54, 0x9e, 0x75}} + PROPID_ACC_STATEMAP = MSAAPROPID{0x43946c5e, 0x0ac0, 0x4042, [8]byte{0xb5, 0x25, 0x07, 0xbb, 0xdb, 0xe1, 0x7f, 0xa7}} + PROPID_ACC_DESCRIPTIONMAP = MSAAPROPID{0x1ff1435f, 0x8a14, 0x477b, [8]byte{0xb2, 0x26, 0xa0, 0xab, 0xe2, 0x79, 0x97, 0x5d}} + PROPID_ACC_DODEFAULTACTION = MSAAPROPID{0x1ba09523, 0x2e3b, 0x49a6, [8]byte{0xa0, 0x59, 0x59, 0x68, 0x2a, 0x3c, 0x48, 0xfd}} +) + +const ( + STATE_SYSTEM_NORMAL = 0 + STATE_SYSTEM_UNAVAILABLE = 0x1 + STATE_SYSTEM_SELECTED = 0x2 + STATE_SYSTEM_FOCUSED = 0x4 + STATE_SYSTEM_PRESSED = 0x8 + STATE_SYSTEM_CHECKED = 0x10 + STATE_SYSTEM_MIXED = 0x20 + STATE_SYSTEM_INDETERMINATE = STATE_SYSTEM_MIXED + STATE_SYSTEM_READONLY = 0x40 + STATE_SYSTEM_HOTTRACKED = 0x80 + STATE_SYSTEM_DEFAULT = 0x100 + STATE_SYSTEM_EXPANDED = 0x200 + STATE_SYSTEM_COLLAPSED = 0x400 + STATE_SYSTEM_BUSY = 0x800 + STATE_SYSTEM_FLOATING = 0x1000 + STATE_SYSTEM_MARQUEED = 0x2000 + STATE_SYSTEM_ANIMATED = 0x4000 + STATE_SYSTEM_INVISIBLE = 0x8000 + STATE_SYSTEM_OFFSCREEN = 0x10000 + STATE_SYSTEM_SIZEABLE = 0x20000 + STATE_SYSTEM_MOVEABLE = 0x40000 + STATE_SYSTEM_SELFVOICING = 0x80000 + STATE_SYSTEM_FOCUSABLE = 0x100000 + STATE_SYSTEM_SELECTABLE = 0x200000 + STATE_SYSTEM_LINKED = 0x400000 + STATE_SYSTEM_TRAVERSED = 0x800000 + STATE_SYSTEM_MULTISELECTABLE = 0x1000000 + STATE_SYSTEM_EXTSELECTABLE = 0x2000000 + STATE_SYSTEM_ALERT_LOW = 0x4000000 + STATE_SYSTEM_ALERT_MEDIUM = 0x8000000 + STATE_SYSTEM_ALERT_HIGH = 0x10000000 + STATE_SYSTEM_PROTECTED = 0x20000000 + STATE_SYSTEM_HASPOPUP = 0x40000000 + STATE_SYSTEM_VALID = 0x7fffffff +) + +const ( + ROLE_SYSTEM_TITLEBAR = 0x1 + ROLE_SYSTEM_MENUBAR = 0x2 + ROLE_SYSTEM_SCROLLBAR = 0x3 + ROLE_SYSTEM_GRIP = 0x4 + ROLE_SYSTEM_SOUND = 0x5 + ROLE_SYSTEM_CURSOR = 0x6 + ROLE_SYSTEM_CARET = 0x7 + ROLE_SYSTEM_ALERT = 0x8 + ROLE_SYSTEM_WINDOW = 0x9 + ROLE_SYSTEM_CLIENT = 0xa + ROLE_SYSTEM_MENUPOPUP = 0xb + ROLE_SYSTEM_MENUITEM = 0xc + ROLE_SYSTEM_TOOLTIP = 0xd + ROLE_SYSTEM_APPLICATION = 0xe + ROLE_SYSTEM_DOCUMENT = 0xf + ROLE_SYSTEM_PANE = 0x10 + ROLE_SYSTEM_CHART = 0x11 + ROLE_SYSTEM_DIALOG = 0x12 + ROLE_SYSTEM_BORDER = 0x13 + ROLE_SYSTEM_GROUPING = 0x14 + ROLE_SYSTEM_SEPARATOR = 0x15 + ROLE_SYSTEM_TOOLBAR = 0x16 + ROLE_SYSTEM_STATUSBAR = 0x17 + ROLE_SYSTEM_TABLE = 0x18 + ROLE_SYSTEM_COLUMNHEADER = 0x19 + ROLE_SYSTEM_ROWHEADER = 0x1a + ROLE_SYSTEM_COLUMN = 0x1b + ROLE_SYSTEM_ROW = 0x1c + ROLE_SYSTEM_CELL = 0x1d + ROLE_SYSTEM_LINK = 0x1e + ROLE_SYSTEM_HELPBALLOON = 0x1f + ROLE_SYSTEM_CHARACTER = 0x20 + ROLE_SYSTEM_LIST = 0x21 + ROLE_SYSTEM_LISTITEM = 0x22 + ROLE_SYSTEM_OUTLINE = 0x23 + ROLE_SYSTEM_OUTLINEITEM = 0x24 + ROLE_SYSTEM_PAGETAB = 0x25 + ROLE_SYSTEM_PROPERTYPAGE = 0x26 + ROLE_SYSTEM_INDICATOR = 0x27 + ROLE_SYSTEM_GRAPHIC = 0x28 + ROLE_SYSTEM_STATICTEXT = 0x29 + ROLE_SYSTEM_TEXT = 0x2a + ROLE_SYSTEM_PUSHBUTTON = 0x2b + ROLE_SYSTEM_CHECKBUTTON = 0x2c + ROLE_SYSTEM_RADIOBUTTON = 0x2d + ROLE_SYSTEM_COMBOBOX = 0x2e + ROLE_SYSTEM_DROPLIST = 0x2f + ROLE_SYSTEM_PROGRESSBAR = 0x30 + ROLE_SYSTEM_DIAL = 0x31 + ROLE_SYSTEM_HOTKEYFIELD = 0x32 + ROLE_SYSTEM_SLIDER = 0x33 + ROLE_SYSTEM_SPINBUTTON = 0x34 + ROLE_SYSTEM_DIAGRAM = 0x35 + ROLE_SYSTEM_ANIMATION = 0x36 + ROLE_SYSTEM_EQUATION = 0x37 + ROLE_SYSTEM_BUTTONDROPDOWN = 0x38 + ROLE_SYSTEM_BUTTONMENU = 0x39 + ROLE_SYSTEM_BUTTONDROPDOWNGRID = 0x3a + ROLE_SYSTEM_WHITESPACE = 0x3b + ROLE_SYSTEM_PAGETABLIST = 0x3c + ROLE_SYSTEM_CLOCK = 0x3d + ROLE_SYSTEM_SPLITBUTTON = 0x3e + ROLE_SYSTEM_IPADDRESS = 0x3f + ROLE_SYSTEM_OUTLINEBUTTON = 0x40 +) + +var ( + IID_IAccPropServer = IID{0x76c0dbbb, 0x15e0, 0x4e7b, [8]byte{0xb6, 0x1b, 0x20, 0xee, 0xea, 0x20, 0x01, 0xe0}} + IID_IAccPropServices = IID{0x6e26e776, 0x04f0, 0x495d, [8]byte{0x80, 0xe4, 0x33, 0x30, 0x35, 0x2e, 0x31, 0x69}} + CLSID_AccPropServices = CLSID{0xb5f8350b, 0x0548, 0x48b1, [8]byte{0xa6, 0xee, 0x88, 0xbd, 0x00, 0xb4, 0xa5, 0xe7}} +) + +type IAccPropServerVtbl struct { + QueryInterface uintptr + AddRef uintptr + Release uintptr + GetPropValue uintptr +} + +type IAccPropServer struct { + LpVtbl *IAccPropServerVtbl +} + +type IAccPropServicesVtbl struct { + QueryInterface uintptr + AddRef uintptr + Release uintptr + SetPropValue uintptr + SetPropServer uintptr + ClearProps uintptr + SetHwndProp uintptr + SetHwndPropStr uintptr + SetHwndPropServer uintptr + ClearHwndProps uintptr + ComposeHwndIdentityString uintptr + DecomposeHwndIdentityString uintptr + SetHmenuProp uintptr + SetHmenuPropStr uintptr + SetHmenuPropServer uintptr + ClearHmenuProps uintptr + ComposeHmenuIdentityString uintptr + DecomposeHmenuIdentityString uintptr +} + +type IAccPropServices struct { + LpVtbl *IAccPropServicesVtbl +} + +func (obj *IAccPropServices) QueryInterface(riid REFIID, ppvObject *unsafe.Pointer) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.QueryInterface, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(ppvObject))) + return HRESULT(ret) +} + +func (obj *IAccPropServices) AddRef() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.AddRef, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *IAccPropServices) Release() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Release, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +// SetPropServer specifies a callback object to be used to annotate an array of properties for the accessible element. You can also specify whether the annotation is to be applied to this accessible element or to the element and its children. This method is used for server annotation. +// If server developers know the HWND of the accessible element they want to annotate, they can use SetHwndPropServer. +func (obj *IAccPropServices) SetPropServer(idString []byte, idProps []MSAAPROPID, server *IAccPropServer, annoScope AnnoScope) HRESULT { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetPropServer, 7, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + uintptr(idPropsPtr), + uintptr(idPropsLen), + uintptr(unsafe.Pointer(server)), + uintptr(annoScope), + 0, + 0) + return HRESULT(ret) +} + +// ClearProps restores default values to properties of accessible elements that they had previously annotated. +// If servers know the HWND of the object they want to clear, they can use ClearHwndProps. +func (obj *IAccPropServices) ClearProps(idString []byte, idProps []MSAAPROPID) HRESULT { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ClearProps, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + uintptr(idPropsPtr), + uintptr(idPropsLen), + 0) + return HRESULT(ret) +} + +// SetHwndPropServer wraps SetPropServer, providing a convenient entry point for callers who are annotating HWND-based accessible elements. +func (obj *IAccPropServices) SetHwndPropServer(hwnd HWND, idObject int32, idChild uint32, idProps []MSAAPROPID, server *IAccPropServer, annoScope AnnoScope) HRESULT { + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHwndPropServer, 8, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + uintptr(idPropsPtr), + uintptr(idPropsLen), + uintptr(unsafe.Pointer(server)), + uintptr(annoScope), + 0) + return HRESULT(ret) +} + +// ClearHwndProps wraps SetPropValue, SetPropServer, and ClearProps, and provides a convenient entry point for callers who are annotating HWND-based accessible elements. +func (obj *IAccPropServices) ClearHwndProps(hwnd HWND, idObject int32, idChild uint32, idProps []MSAAPROPID) HRESULT { + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ClearHwndProps, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + uintptr(idPropsPtr), + uintptr(idPropsLen)) + return HRESULT(ret) +} + +// ComposeHwndIdentityString retrievs an identity string. +func (obj *IAccPropServices) ComposeHwndIdentityString(hwnd HWND, idObject int32, idChild uint32) (hr HRESULT, idString []byte) { + var data *[1<<31 - 1]byte + var len uint32 + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ComposeHwndIdentityString, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + uintptr(unsafe.Pointer(&data)), + uintptr(unsafe.Pointer(&len))) + hr = HRESULT(ret) + if FAILED(hr) { + return + } + defer CoTaskMemFree(uintptr(unsafe.Pointer(data))) + idString = make([]byte, len) + copy(idString, data[:len]) + return +} + +// DecomposeHwndIdentityString determines the HWND, object ID, and child ID for the accessible element identified by the identity string. +func (obj *IAccPropServices) DecomposeHwndIdentityString(idString []byte) (hr HRESULT, hwnd HWND, idObject int32, idChild uint32) { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.DecomposeHwndIdentityString, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + uintptr(unsafe.Pointer(&hwnd)), + uintptr(unsafe.Pointer(&idObject)), + uintptr(unsafe.Pointer(&idChild))) + hr = HRESULT(ret) + return +} + +// SetHmenuPropServer wraps SetPropServer, providing a convenient entry point for callers who are annotating HMENU-based accessible elements. +func (obj *IAccPropServices) SetHmenuPropServer(hmenu HMENU, idChild uint32, idProps []MSAAPROPID, server *IAccPropServer, annoScope AnnoScope) HRESULT { + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHmenuPropServer, 7, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + uintptr(idPropsPtr), + uintptr(idPropsLen), + uintptr(unsafe.Pointer(server)), + uintptr(annoScope), + 0, + 0) + return HRESULT(ret) +} + +// ClearHmenuProps wraps ClearProps, and provides a convenient entry point for callers who are annotating HMENU-based accessible elements. +func (obj *IAccPropServices) ClearHmenuProps(hmenu HMENU, idChild uint32, idProps []MSAAPROPID) HRESULT { + var idPropsPtr unsafe.Pointer + idPropsLen := len(idProps) + if idPropsLen != 0 { + idPropsPtr = unsafe.Pointer(&idProps[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ClearHmenuProps, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + uintptr(idPropsPtr), + uintptr(idPropsLen), + 0) + return HRESULT(ret) +} + +// ComposeHmenuIdentityString retrieves an identity string for an HMENU-based accessible element. +func (obj *IAccPropServices) ComposeHmenuIdentityString(hmenu HMENU, idChild uint32) (hr HRESULT, idString []byte) { + var data *[1<<31 - 1]byte + var len uint32 + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ComposeHmenuIdentityString, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + uintptr(unsafe.Pointer(&data)), + uintptr(unsafe.Pointer(&len)), + 0) + hr = HRESULT(ret) + if FAILED(hr) { + return + } + defer CoTaskMemFree(uintptr(unsafe.Pointer(data))) + idString = make([]byte, len) + copy(idString, data[:len]) + return +} + +// DecomposeHmenuIdentityString determines the HMENU, object ID, and child ID for the accessible element identified by the identity string. +func (obj *IAccPropServices) DecomposeHmenuIdentityString(idString []byte) (hr HRESULT, hmenu HMENU, idChild uint32) { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.DecomposeHmenuIdentityString, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + uintptr(unsafe.Pointer(&hmenu)), + uintptr(unsafe.Pointer(&idChild)), + 0) + hr = HRESULT(ret) + return +} diff --git a/oleacc_32.go b/oleacc_32.go new file mode 100644 index 00000000..be12e107 --- /dev/null +++ b/oleacc_32.go @@ -0,0 +1,99 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows,386 windows,arm + +package win + +import ( + "syscall" + "unsafe" +) + +func (idProp *MSAAPROPID) split() (uintptr, uintptr, uintptr, uintptr) { + if idProp == nil { + return 0, 0, 0, 0 + } + x := (*struct { a, b, c, d uintptr })(unsafe.Pointer(idProp)) + return x.a, x.b, x.c, x.d +} + +// SetPropValue identifies the accessible element to be annotated, specify the property to be annotated, and provide a new value for that property. +// If server developers know the HWND of the accessible element they want to annotate, they can use one of the following methods: SetHwndPropStr, SetHwndProp, or SetHwndPropServer +func (obj *IAccPropServices) SetPropValue(idString []byte, idProp *MSAAPROPID, v *VARIANT) HRESULT { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + propA, propB, propC, propD := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetPropValue, 8, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + propA, propB, propC, propD, + uintptr(unsafe.Pointer(v)), + 0) + return HRESULT(ret) +} + +// SetHwndProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HWND-based accessible elements. If the new value is a string, you can use SetHwndPropStr instead. +func (obj *IAccPropServices) SetHwndProp(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + propA, propB, propC, propD := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHwndProp, 9, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + propA, propB, propC, propD, + uintptr(unsafe.Pointer(v))) + return HRESULT(ret) +} + +// SetHwndPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HWND-based accessible elements. +func (obj *IAccPropServices) SetHwndPropStr(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + propA, propB, propC, propD := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHwndPropStr, 9, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + propA, propB, propC, propD, + uintptr(unsafe.Pointer(str16))) + return HRESULT(ret) +} + +// SetHmenuProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HMENU-based accessible elements. If the new value is a string, you can use IAccPropServices::SetHmenuPropStr instead. +func (obj *IAccPropServices) SetHmenuProp(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + propA, propB, propC, propD := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHmenuProp, 8, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + propA, propB, propC, propD, + uintptr(unsafe.Pointer(v)), + 0) + return HRESULT(ret) +} + +// SetHmenuPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HMENU-based accessible elements. +func (obj *IAccPropServices) SetHmenuPropStr(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + propA, propB, propC, propD := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHmenuPropStr, 8, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + propA, propB, propC, propD, + uintptr(unsafe.Pointer(str16)), + 0) + return HRESULT(ret) +} diff --git a/oleacc_amd64.go b/oleacc_amd64.go new file mode 100644 index 00000000..1a210b01 --- /dev/null +++ b/oleacc_amd64.go @@ -0,0 +1,86 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows,amd64 + +package win + +import ( + "syscall" + "unsafe" +) + +// SetPropValue identifies the accessible element to be annotated, specify the property to be annotated, and provide a new value for that property. +// If server developers know the HWND of the accessible element they want to annotate, they can use one of the following methods: SetHwndPropStr, SetHwndProp, or SetHwndPropServer +func (obj *IAccPropServices) SetPropValue(idString []byte, idProp *MSAAPROPID, v *VARIANT) HRESULT { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetPropValue, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + uintptr(unsafe.Pointer(idProp)), + uintptr(unsafe.Pointer(v)), + 0) + return HRESULT(ret) +} + +// SetHwndProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HWND-based accessible elements. If the new value is a string, you can use SetHwndPropStr instead. +func (obj *IAccPropServices) SetHwndProp(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHwndProp, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + uintptr(unsafe.Pointer(idProp)), + uintptr(unsafe.Pointer(v))) + return HRESULT(ret) +} + +// SetHwndPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HWND-based accessible elements. +func (obj *IAccPropServices) SetHwndPropStr(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHwndPropStr, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + uintptr(unsafe.Pointer(idProp)), + uintptr(unsafe.Pointer(str16))) + return HRESULT(ret) +} + +// SetHmenuProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HMENU-based accessible elements. If the new value is a string, you can use IAccPropServices::SetHmenuPropStr instead. +func (obj *IAccPropServices) SetHmenuProp(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHmenuProp, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + uintptr(unsafe.Pointer(idProp)), + uintptr(unsafe.Pointer(v)), + 0) + return HRESULT(ret) +} + +// SetHmenuPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HMENU-based accessible elements. +func (obj *IAccPropServices) SetHmenuPropStr(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHmenuPropStr, 5, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + uintptr(unsafe.Pointer(idProp)), + uintptr(unsafe.Pointer(str16)), + 0) + return HRESULT(ret) +} diff --git a/oleacc_arm64.go b/oleacc_arm64.go new file mode 100644 index 00000000..0b029e5a --- /dev/null +++ b/oleacc_arm64.go @@ -0,0 +1,98 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows,arm64 + +package win + +import ( + "syscall" + "unsafe" +) + +func (idProp *MSAAPROPID) split() (uintptr, uintptr) { + if idProp == nil { + return 0, 0 + } + x := (*struct { a, b uintptr })(unsafe.Pointer(idProp)) + return x.a, x.b +} + +// SetPropValue identifies the accessible element to be annotated, specify the property to be annotated, and provide a new value for that property. +// If server developers know the HWND of the accessible element they want to annotate, they can use one of the following methods: SetHwndPropStr, SetHwndProp, or SetHwndPropServer +func (obj *IAccPropServices) SetPropValue(idString []byte, idProp *MSAAPROPID, v *VARIANT) HRESULT { + var idStringPtr unsafe.Pointer + idStringLen := len(idString) + if idStringLen != 0 { + idStringPtr = unsafe.Pointer(&idString[0]) + } + propA, propB := idProp.split() + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetPropValue, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(idStringPtr), + uintptr(idStringLen), + propA, propB, + uintptr(unsafe.Pointer(v))) + return HRESULT(ret) +} + +// SetHwndProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HWND-based accessible elements. If the new value is a string, you can use SetHwndPropStr instead. +func (obj *IAccPropServices) SetHwndProp(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + propA, propB := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHwndProp, 7, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + propA, propB, + uintptr(unsafe.Pointer(v)), + 0, 0) + return HRESULT(ret) +} + +// SetHwndPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HWND-based accessible elements. +func (obj *IAccPropServices) SetHwndPropStr(hwnd HWND, idObject int32, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + propA, propB := idProp.split() + ret, _, _ := syscall.Syscall9(obj.LpVtbl.SetHwndPropStr, 7, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + propA, propB, + uintptr(unsafe.Pointer(str16)), + 0, 0) + return HRESULT(ret) +} + +// SetHmenuProp wraps SetPropValue, providing a convenient entry point for callers who are annotating HMENU-based accessible elements. If the new value is a string, you can use IAccPropServices::SetHmenuPropStr instead. +func (obj *IAccPropServices) SetHmenuProp(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, v *VARIANT) HRESULT { + propA, propB := idProp.split() + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHmenuProp, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + propA, propB, + uintptr(unsafe.Pointer(v))) + return HRESULT(ret) +} + +// SetHmenuPropStr wraps SetPropValue, providing a more convenient entry point for callers who are annotating HMENU-based accessible elements. +func (obj *IAccPropServices) SetHmenuPropStr(hmenu HMENU, idChild uint32, idProp *MSAAPROPID, str string) HRESULT { + str16, err := syscall.UTF16PtrFromString(str) + if err != nil { + return -((E_INVALIDARG ^ 0xFFFFFFFF) + 1) + } + propA, propB := idProp.split() + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetHmenuPropStr, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(hmenu), + uintptr(idChild), + propA, propB, + uintptr(unsafe.Pointer(str16))) + return HRESULT(ret) +} diff --git a/oleaut32.go b/oleaut32.go index 36bd2c2d..e693fffc 100644 --- a/oleaut32.go +++ b/oleaut32.go @@ -2,9 +2,13 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "fmt" + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -53,6 +57,7 @@ const ( DISPID_FILEDOWNLOAD DISPID = 270 DISPID_NAVIGATEERROR DISPID = 271 DISPID_PRIVACYIMPACTEDSTATECHANGE DISPID = 272 + DISPID_NEWWINDOW3 DISPID = 273 ) var ( @@ -63,6 +68,26 @@ const ( DISP_E_MEMBERNOTFOUND = 0x80020003 ) +const ( + CSC_UPDATECOMMANDS = ^0x0 + CSC_NAVIGATEFORWARD = 0x1 + CSC_NAVIGATEBACK = 0x2 +) + +type IDispatchVtbl struct { + QueryInterface uintptr + AddRef uintptr + Release uintptr + GetTypeInfoCount uintptr + GetTypeInfo uintptr + GetIDsOfNames uintptr + Invoke uintptr +} + +type IDispatch struct { + LpVtbl *IDispatchVtbl +} + type VARTYPE uint16 const ( @@ -120,15 +145,31 @@ const ( VT_TYPEMASK VARTYPE = 0xfff ) -type VARIANT struct { - Vt VARTYPE - reserved [14]byte +type VARIANTARG struct { + VARIANT } -type VARIANTARG VARIANT - type VARIANT_BOOL int16 +const ( + VARIANT_TRUE VARIANT_BOOL = -1 + VARIANT_FALSE VARIANT_BOOL = 0 +) + +type SAFEARRAYBOUND struct { + CElements uint32 + LLbound int32 +} + +type SAFEARRAY struct { + CDims uint16 + FFeatures uint16 + CbElements uint32 + CLocks uint32 + PvData uintptr + Rgsabound [1]SAFEARRAYBOUND +} + //type BSTR *uint16 func StringToBSTR(value string) *uint16 /*BSTR*/ { @@ -146,13 +187,6 @@ func BSTRToString(value *uint16 /*BSTR*/) string { return syscall.UTF16ToString(bstrSlice) } -type VAR_I4 struct { - vt VARTYPE - reserved1 [6]byte - lVal int32 - reserved2 [4]byte -} - func IntToVariantI4(value int32) *VAR_I4 { return &VAR_I4{vt: VT_I4, lVal: value} } @@ -161,13 +195,6 @@ func VariantI4ToInt(value *VAR_I4) int32 { return value.lVal } -type VAR_BOOL struct { - vt VARTYPE - reserved1 [6]byte - boolVal VARIANT_BOOL - reserved2 [6]byte -} - func BoolToVariantBool(value bool) *VAR_BOOL { return &VAR_BOOL{vt: VT_BOOL, boolVal: VARIANT_BOOL(BoolToBOOL(value))} } @@ -185,6 +212,204 @@ func VariantBSTRToString(value *VAR_BSTR) string { return BSTRToString(value.bstrVal) } +func (v *VARIANT) MustLong() int32 { + value, err := v.Long() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) Long() (int32, error) { + if v.Vt != VT_I4 { + return 0, fmt.Errorf("Error: Long() v.Vt != VT_I4, ptr=%p, value=%+v", v, v) + } + p := (*VAR_I4)(unsafe.Pointer(v)) + return p.lVal, nil +} + +func (v *VARIANT) SetLong(value int32) { + v.Vt = VT_I4 + p := (*VAR_I4)(unsafe.Pointer(v)) + p.lVal = value +} + +func (v *VARIANT) MustULong() uint32 { + value, err := v.ULong() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) ULong() (uint32, error) { + if v.Vt != VT_UI4 { + return 0, fmt.Errorf("Error: ULong() v.Vt != VT_UI4, ptr=%p, value=%+v", v, v) + } + p := (*VAR_UI4)(unsafe.Pointer(v)) + return p.ulVal, nil +} + +func (v *VARIANT) SetULong(value uint32) { + v.Vt = VT_UI4 + p := (*VAR_UI4)(unsafe.Pointer(v)) + p.ulVal = value +} + +func (v *VARIANT) MustBool() VARIANT_BOOL { + value, err := v.Bool() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) Bool() (VARIANT_BOOL, error) { + if v.Vt != VT_BOOL { + return VARIANT_FALSE, fmt.Errorf("Error: Bool() v.Vt != VT_BOOL, ptr=%p, value=%+v", v, v) + } + p := (*VAR_BOOL)(unsafe.Pointer(v)) + return p.boolVal, nil +} + +func (v *VARIANT) SetBool(value VARIANT_BOOL) { + v.Vt = VT_BOOL + p := (*VAR_BOOL)(unsafe.Pointer(v)) + p.boolVal = value +} + +func (v *VARIANT) MustBSTR() *uint16 { + value, err := v.BSTR() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) BSTR() (*uint16, error) { + if v.Vt != VT_BSTR { + return nil, fmt.Errorf("Error: BSTR() v.Vt != VT_BSTR, ptr=%p, value=%+v", v, v) + } + p := (*VAR_BSTR)(unsafe.Pointer(v)) + return p.bstrVal, nil +} + +func (v *VARIANT) SetBSTR(value *uint16) { + v.Vt = VT_BSTR + p := (*VAR_BSTR)(unsafe.Pointer(v)) + p.bstrVal = value +} + +func (v *VARIANT) MustPDispatch() *IDispatch { + value, err := v.PDispatch() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) PDispatch() (*IDispatch, error) { + if v.Vt != VT_DISPATCH { + return nil, fmt.Errorf("Error: PDispatch() v.Vt != VT_DISPATCH, ptr=%p, value=%+v", v, v) + } + p := (*VAR_PDISP)(unsafe.Pointer(v)) + return p.pdispVal, nil +} + +func (v *VARIANT) SetPDispatch(value *IDispatch) { + v.Vt = VT_DISPATCH + p := (*VAR_PDISP)(unsafe.Pointer(v)) + p.pdispVal = value +} + +func (v *VARIANT) MustPVariant() *VARIANT { + value, err := v.PVariant() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) PVariant() (*VARIANT, error) { + if v.Vt != VT_BYREF|VT_VARIANT { + return nil, fmt.Errorf("Error: PVariant() v.Vt != VT_BYREF|VT_VARIANT, ptr=%p, value=%+v", v, v) + } + p := (*VAR_PVAR)(unsafe.Pointer(v)) + return p.pvarVal, nil +} + +func (v *VARIANT) SetPVariant(value *VARIANT) { + v.Vt = VT_BYREF | VT_VARIANT + p := (*VAR_PVAR)(unsafe.Pointer(v)) + p.pvarVal = value +} + +func (v *VARIANT) MustPBool() *VARIANT_BOOL { + value, err := v.PBool() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) PBool() (*VARIANT_BOOL, error) { + if v.Vt != VT_BYREF|VT_BOOL { + return nil, fmt.Errorf("Error: PBool() v.Vt != VT_BYREF|VT_BOOL, ptr=%p, value=%+v", v, v) + } + p := (*VAR_PBOOL)(unsafe.Pointer(v)) + return p.pboolVal, nil +} + +func (v *VARIANT) SetPBool(value *VARIANT_BOOL) { + v.Vt = VT_BYREF | VT_BOOL + p := (*VAR_PBOOL)(unsafe.Pointer(v)) + p.pboolVal = value +} + +func (v *VARIANT) MustPPDispatch() **IDispatch { + value, err := v.PPDispatch() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) PPDispatch() (**IDispatch, error) { + if v.Vt != VT_BYREF|VT_DISPATCH { + return nil, fmt.Errorf("PPDispatch() v.Vt != VT_BYREF|VT_DISPATCH, ptr=%p, value=%+v", v, v) + } + p := (*VAR_PPDISP)(unsafe.Pointer(v)) + return p.ppdispVal, nil +} + +func (v *VARIANT) SetPPDispatch(value **IDispatch) { + v.Vt = VT_BYREF | VT_DISPATCH + p := (*VAR_PPDISP)(unsafe.Pointer(v)) + p.ppdispVal = value +} + +func (v *VARIANT) MustPSafeArray() *SAFEARRAY { + value, err := v.PSafeArray() + if err != nil { + panic(err) + } + return value +} + +func (v *VARIANT) PSafeArray() (*SAFEARRAY, error) { + if (v.Vt & VT_ARRAY) != VT_ARRAY { + return nil, fmt.Errorf("Error: PSafeArray() (v.Vt & VT_ARRAY) != VT_ARRAY, ptr=%p, value=%+v", v, v) + } + p := (*VAR_PSAFEARRAY)(unsafe.Pointer(v)) + return p.parray, nil +} + +func (v *VARIANT) SetPSafeArray(value *SAFEARRAY, elementVt VARTYPE) { + v.Vt = VT_ARRAY | elementVt + p := (*VAR_PSAFEARRAY)(unsafe.Pointer(v)) + p.parray = value +} + type DISPPARAMS struct { Rgvarg *VARIANTARG RgdispidNamedArgs *DISPID @@ -194,26 +419,26 @@ type DISPPARAMS struct { var ( // Library - liboleaut32 uintptr + liboleaut32 *windows.LazyDLL // Functions - sysAllocString uintptr - sysFreeString uintptr - sysStringLen uintptr + sysAllocString *windows.LazyProc + sysFreeString *windows.LazyProc + sysStringLen *windows.LazyProc ) func init() { // Library - liboleaut32 = MustLoadLibrary("oleaut32.dll") + liboleaut32 = windows.NewLazySystemDLL("oleaut32.dll") // Functions - sysAllocString = MustGetProcAddress(liboleaut32, "SysAllocString") - sysFreeString = MustGetProcAddress(liboleaut32, "SysFreeString") - sysStringLen = MustGetProcAddress(liboleaut32, "SysStringLen") + sysAllocString = liboleaut32.NewProc("SysAllocString") + sysFreeString = liboleaut32.NewProc("SysFreeString") + sysStringLen = liboleaut32.NewProc("SysStringLen") } func SysAllocString(s string) *uint16 /*BSTR*/ { - ret, _, _ := syscall.Syscall(sysAllocString, 1, + ret, _, _ := syscall.Syscall(sysAllocString.Addr(), 1, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s))), 0, 0) @@ -222,14 +447,14 @@ func SysAllocString(s string) *uint16 /*BSTR*/ { } func SysFreeString(bstr *uint16 /*BSTR*/) { - syscall.Syscall(sysFreeString, 1, + syscall.Syscall(sysFreeString.Addr(), 1, uintptr(unsafe.Pointer(bstr)), 0, 0) } func SysStringLen(bstr *uint16 /*BSTR*/) uint32 { - ret, _, _ := syscall.Syscall(sysStringLen, 1, + ret, _, _ := syscall.Syscall(sysStringLen.Addr(), 1, uintptr(unsafe.Pointer(bstr)), 0, 0) diff --git a/oleaut32_32.go b/oleaut32_32.go new file mode 100644 index 00000000..3c2cc3da --- /dev/null +++ b/oleaut32_32.go @@ -0,0 +1,75 @@ +// Copyright 2012 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows,386 windows,arm + +package win + +type VARIANT struct { + Vt VARTYPE + reserved [14]byte +} + +type VAR_I4 struct { + vt VARTYPE + reserved1 [6]byte + lVal int32 + reserved2 [4]byte +} + +type VAR_UI4 struct { + vt VARTYPE + reserved1 [6]byte + ulVal uint32 + reserved2 [4]byte +} + +type VAR_BOOL struct { + vt VARTYPE + reserved1 [6]byte + boolVal VARIANT_BOOL + reserved2 [6]byte +} + +type VAR_BSTR struct { + vt VARTYPE + reserved1 [6]byte + bstrVal *uint16 /*BSTR*/ + reserved2 [4]byte +} + +type VAR_PDISP struct { + vt VARTYPE + reserved1 [6]byte + pdispVal *IDispatch + reserved2 [4]byte +} + +type VAR_PSAFEARRAY struct { + vt VARTYPE + reserved1 [6]byte + parray *SAFEARRAY + reserved2 [4]byte +} + +type VAR_PVAR struct { + vt VARTYPE + reserved1 [6]byte + pvarVal *VARIANT + reserved2 [4]byte +} + +type VAR_PBOOL struct { + vt VARTYPE + reserved1 [6]byte + pboolVal *VARIANT_BOOL + reserved2 [4]byte +} + +type VAR_PPDISP struct { + vt VARTYPE + reserved1 [6]byte + ppdispVal **IDispatch + reserved2 [4]byte +} diff --git a/oleaut32_386.go b/oleaut32_386.go deleted file mode 100644 index b057bd62..00000000 --- a/oleaut32_386.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2012 The win Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package win - -type VAR_BSTR struct { - vt VARTYPE - reserved1 [6]byte - bstrVal *uint16 /*BSTR*/ - reserved2 [4]byte -} diff --git a/oleaut32_64.go b/oleaut32_64.go new file mode 100644 index 00000000..4046a008 --- /dev/null +++ b/oleaut32_64.go @@ -0,0 +1,75 @@ +// Copyright 2012 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows,amd64 windows,arm64 + +package win + +type VARIANT struct { + Vt VARTYPE + reserved [22]byte +} + +type VAR_I4 struct { + vt VARTYPE + reserved1 [6]byte + lVal int32 + reserved2 [12]byte +} + +type VAR_UI4 struct { + vt VARTYPE + reserved1 [6]byte + ulVal uint32 + reserved2 [12]byte +} + +type VAR_BOOL struct { + vt VARTYPE + reserved1 [6]byte + boolVal VARIANT_BOOL + reserved2 [14]byte +} + +type VAR_BSTR struct { + vt VARTYPE + reserved1 [6]byte + bstrVal *uint16 /*BSTR*/ + reserved2 [8]byte +} + +type VAR_PDISP struct { + vt VARTYPE + reserved1 [6]byte + pdispVal *IDispatch + reserved2 [8]byte +} + +type VAR_PSAFEARRAY struct { + vt VARTYPE + reserved1 [6]byte + parray *SAFEARRAY + reserved2 [8]byte +} + +type VAR_PVAR struct { + vt VARTYPE + reserved1 [6]byte + pvarVal *VARIANT + reserved2 [8]byte +} + +type VAR_PBOOL struct { + vt VARTYPE + reserved1 [6]byte + pboolVal *VARIANT_BOOL + reserved2 [8]byte +} + +type VAR_PPDISP struct { + vt VARTYPE + reserved1 [6]byte + ppdispVal **IDispatch + reserved2 [8]byte +} diff --git a/oleaut32_amd64.go b/oleaut32_amd64.go deleted file mode 100644 index 0f7d92bf..00000000 --- a/oleaut32_amd64.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2012 The win Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package win - -type VAR_BSTR struct { - vt VARTYPE - reserved1 [6]byte - bstrVal *uint16 /*BSTR*/ -} diff --git a/opengl32.go b/opengl32.go index 0dfc84fe..1dbd6c38 100644 --- a/opengl32.go +++ b/opengl32.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -89,52 +92,52 @@ type GLYPHMETRICSFLOAT struct { var ( // Library - lib uintptr + lib *windows.LazyDLL // Functions - wglCopyContext uintptr - wglCreateContext uintptr - wglCreateLayerContext uintptr - wglDeleteContext uintptr - wglDescribeLayerPlane uintptr - wglGetCurrentContext uintptr - wglGetCurrentDC uintptr - wglGetLayerPaletteEntries uintptr - wglGetProcAddress uintptr - wglMakeCurrent uintptr - wglRealizeLayerPalette uintptr - wglSetLayerPaletteEntries uintptr - wglShareLists uintptr - wglSwapLayerBuffers uintptr - wglUseFontBitmaps uintptr - wglUseFontOutlines uintptr + wglCopyContext *windows.LazyProc + wglCreateContext *windows.LazyProc + wglCreateLayerContext *windows.LazyProc + wglDeleteContext *windows.LazyProc + wglDescribeLayerPlane *windows.LazyProc + wglGetCurrentContext *windows.LazyProc + wglGetCurrentDC *windows.LazyProc + wglGetLayerPaletteEntries *windows.LazyProc + wglGetProcAddress *windows.LazyProc + wglMakeCurrent *windows.LazyProc + wglRealizeLayerPalette *windows.LazyProc + wglSetLayerPaletteEntries *windows.LazyProc + wglShareLists *windows.LazyProc + wglSwapLayerBuffers *windows.LazyProc + wglUseFontBitmaps *windows.LazyProc + wglUseFontOutlines *windows.LazyProc ) func init() { // Library - lib = MustLoadLibrary("opengl32.dll") + lib = windows.NewLazySystemDLL("opengl32.dll") // Functions - wglCopyContext = MustGetProcAddress(lib, "wglCopyContext") - wglCreateContext = MustGetProcAddress(lib, "wglCreateContext") - wglCreateLayerContext = MustGetProcAddress(lib, "wglCreateLayerContext") - wglDeleteContext = MustGetProcAddress(lib, "wglDeleteContext") - wglDescribeLayerPlane = MustGetProcAddress(lib, "wglDescribeLayerPlane") - wglGetCurrentContext = MustGetProcAddress(lib, "wglGetCurrentContext") - wglGetCurrentDC = MustGetProcAddress(lib, "wglGetCurrentDC") - wglGetLayerPaletteEntries = MustGetProcAddress(lib, "wglGetLayerPaletteEntries") - wglGetProcAddress = MustGetProcAddress(lib, "wglGetProcAddress") - wglMakeCurrent = MustGetProcAddress(lib, "wglMakeCurrent") - wglRealizeLayerPalette = MustGetProcAddress(lib, "wglRealizeLayerPalette") - wglSetLayerPaletteEntries = MustGetProcAddress(lib, "wglSetLayerPaletteEntries") - wglShareLists = MustGetProcAddress(lib, "wglShareLists") - wglSwapLayerBuffers = MustGetProcAddress(lib, "wglSwapLayerBuffers") - wglUseFontBitmaps = MustGetProcAddress(lib, "wglUseFontBitmapsW") - wglUseFontOutlines = MustGetProcAddress(lib, "wglUseFontOutlinesW") + wglCopyContext = lib.NewProc("wglCopyContext") + wglCreateContext = lib.NewProc("wglCreateContext") + wglCreateLayerContext = lib.NewProc("wglCreateLayerContext") + wglDeleteContext = lib.NewProc("wglDeleteContext") + wglDescribeLayerPlane = lib.NewProc("wglDescribeLayerPlane") + wglGetCurrentContext = lib.NewProc("wglGetCurrentContext") + wglGetCurrentDC = lib.NewProc("wglGetCurrentDC") + wglGetLayerPaletteEntries = lib.NewProc("wglGetLayerPaletteEntries") + wglGetProcAddress = lib.NewProc("wglGetProcAddress") + wglMakeCurrent = lib.NewProc("wglMakeCurrent") + wglRealizeLayerPalette = lib.NewProc("wglRealizeLayerPalette") + wglSetLayerPaletteEntries = lib.NewProc("wglSetLayerPaletteEntries") + wglShareLists = lib.NewProc("wglShareLists") + wglSwapLayerBuffers = lib.NewProc("wglSwapLayerBuffers") + wglUseFontBitmaps = lib.NewProc("wglUseFontBitmapsW") + wglUseFontOutlines = lib.NewProc("wglUseFontOutlinesW") } func WglCopyContext(hglrcSrc, hglrcDst HGLRC, mask uint) bool { - ret, _, _ := syscall.Syscall(wglCopyContext, 3, + ret, _, _ := syscall.Syscall(wglCopyContext.Addr(), 3, uintptr(hglrcSrc), uintptr(hglrcDst), uintptr(mask)) @@ -143,7 +146,7 @@ func WglCopyContext(hglrcSrc, hglrcDst HGLRC, mask uint) bool { } func WglCreateContext(hdc HDC) HGLRC { - ret, _, _ := syscall.Syscall(wglCreateContext, 1, + ret, _, _ := syscall.Syscall(wglCreateContext.Addr(), 1, uintptr(hdc), 0, 0) @@ -152,7 +155,7 @@ func WglCreateContext(hdc HDC) HGLRC { } func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC { - ret, _, _ := syscall.Syscall(wglCreateLayerContext, 2, + ret, _, _ := syscall.Syscall(wglCreateLayerContext.Addr(), 2, uintptr(hdc), uintptr(iLayerPlane), 0) @@ -161,7 +164,7 @@ func WglCreateLayerContext(hdc HDC, iLayerPlane int) HGLRC { } func WglDeleteContext(hglrc HGLRC) bool { - ret, _, _ := syscall.Syscall(wglDeleteContext, 1, + ret, _, _ := syscall.Syscall(wglDeleteContext.Addr(), 1, uintptr(hglrc), 0, 0) @@ -170,7 +173,7 @@ func WglDeleteContext(hglrc HGLRC) bool { } func WglDescribeLayerPlane(hdc HDC, iPixelFormat, iLayerPlane int, nBytes uint8, plpd *LAYERPLANEDESCRIPTOR) bool { - ret, _, _ := syscall.Syscall6(wglDescribeLayerPlane, 5, + ret, _, _ := syscall.Syscall6(wglDescribeLayerPlane.Addr(), 5, uintptr(hdc), uintptr(iPixelFormat), uintptr(iLayerPlane), @@ -182,7 +185,7 @@ func WglDescribeLayerPlane(hdc HDC, iPixelFormat, iLayerPlane int, nBytes uint8, } func WglGetCurrentContext() HGLRC { - ret, _, _ := syscall.Syscall(wglGetCurrentContext, 0, + ret, _, _ := syscall.Syscall(wglGetCurrentContext.Addr(), 0, 0, 0, 0) @@ -191,7 +194,7 @@ func WglGetCurrentContext() HGLRC { } func WglGetCurrentDC() HDC { - ret, _, _ := syscall.Syscall(wglGetCurrentDC, 0, + ret, _, _ := syscall.Syscall(wglGetCurrentDC.Addr(), 0, 0, 0, 0) @@ -200,7 +203,7 @@ func WglGetCurrentDC() HDC { } func WglGetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int { - ret, _, _ := syscall.Syscall6(wglGetLayerPaletteEntries, 5, + ret, _, _ := syscall.Syscall6(wglGetLayerPaletteEntries.Addr(), 5, uintptr(hdc), uintptr(iLayerPlane), uintptr(iStart), @@ -212,7 +215,7 @@ func WglGetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr * } func WglGetProcAddress(lpszProc *byte) uintptr { - ret, _, _ := syscall.Syscall(wglGetProcAddress, 1, + ret, _, _ := syscall.Syscall(wglGetProcAddress.Addr(), 1, uintptr(unsafe.Pointer(lpszProc)), 0, 0) @@ -221,7 +224,7 @@ func WglGetProcAddress(lpszProc *byte) uintptr { } func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool { - ret, _, _ := syscall.Syscall(wglMakeCurrent, 2, + ret, _, _ := syscall.Syscall(wglMakeCurrent.Addr(), 2, uintptr(hdc), uintptr(hglrc), 0) @@ -230,7 +233,7 @@ func WglMakeCurrent(hdc HDC, hglrc HGLRC) bool { } func WglRealizeLayerPalette(hdc HDC, iLayerPlane int, bRealize bool) bool { - ret, _, _ := syscall.Syscall(wglRealizeLayerPalette, 3, + ret, _, _ := syscall.Syscall(wglRealizeLayerPalette.Addr(), 3, uintptr(hdc), uintptr(iLayerPlane), uintptr(BoolToBOOL(bRealize))) @@ -239,7 +242,7 @@ func WglRealizeLayerPalette(hdc HDC, iLayerPlane int, bRealize bool) bool { } func WglSetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr *COLORREF) int { - ret, _, _ := syscall.Syscall6(wglSetLayerPaletteEntries, 5, + ret, _, _ := syscall.Syscall6(wglSetLayerPaletteEntries.Addr(), 5, uintptr(hdc), uintptr(iLayerPlane), uintptr(iStart), @@ -251,7 +254,7 @@ func WglSetLayerPaletteEntries(hdc HDC, iLayerPlane, iStart, cEntries int, pcr * } func WglShareLists(hglrc1, hglrc2 HGLRC) bool { - ret, _, _ := syscall.Syscall(wglShareLists, 2, + ret, _, _ := syscall.Syscall(wglShareLists.Addr(), 2, uintptr(hglrc1), uintptr(hglrc2), 0) @@ -260,7 +263,7 @@ func WglShareLists(hglrc1, hglrc2 HGLRC) bool { } func WglSwapLayerBuffers(hdc HDC, fuPlanes uint) bool { - ret, _, _ := syscall.Syscall(wglSwapLayerBuffers, 2, + ret, _, _ := syscall.Syscall(wglSwapLayerBuffers.Addr(), 2, uintptr(hdc), uintptr(fuPlanes), 0) @@ -269,7 +272,7 @@ func WglSwapLayerBuffers(hdc HDC, fuPlanes uint) bool { } func WglUseFontBitmaps(hdc HDC, first, count, listbase uint32) bool { - ret, _, _ := syscall.Syscall6(wglUseFontBitmaps, 4, + ret, _, _ := syscall.Syscall6(wglUseFontBitmaps.Addr(), 4, uintptr(hdc), uintptr(first), uintptr(count), @@ -281,7 +284,7 @@ func WglUseFontBitmaps(hdc HDC, first, count, listbase uint32) bool { } func WglUseFontOutlines(hdc HDC, first, count, listbase uint32, deviation, extrusion float32, format int, pgmf *GLYPHMETRICSFLOAT) bool { - ret, _, _ := syscall.Syscall12(wglUseFontBitmaps, 8, + ret, _, _ := syscall.Syscall12(wglUseFontBitmaps.Addr(), 8, uintptr(hdc), uintptr(first), uintptr(count), diff --git a/pdh.go b/pdh.go index 318ae47d..a18b2608 100644 --- a/pdh.go +++ b/pdh.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -159,32 +162,32 @@ type PDH_FMT_COUNTERVALUE_ITEM_LONG struct { var ( // Library - libpdhDll *syscall.DLL + libpdhDll *windows.LazyDLL // Functions - pdh_AddCounterW *syscall.Proc - pdh_AddEnglishCounterW *syscall.Proc - pdh_CloseQuery *syscall.Proc - pdh_CollectQueryData *syscall.Proc - pdh_GetFormattedCounterValue *syscall.Proc - pdh_GetFormattedCounterArrayW *syscall.Proc - pdh_OpenQuery *syscall.Proc - pdh_ValidatePathW *syscall.Proc + pdh_AddCounterW *windows.LazyProc + pdh_AddEnglishCounterW *windows.LazyProc + pdh_CloseQuery *windows.LazyProc + pdh_CollectQueryData *windows.LazyProc + pdh_GetFormattedCounterValue *windows.LazyProc + pdh_GetFormattedCounterArrayW *windows.LazyProc + pdh_OpenQuery *windows.LazyProc + pdh_ValidatePathW *windows.LazyProc ) func init() { // Library - libpdhDll = syscall.MustLoadDLL("pdh.dll") + libpdhDll = windows.NewLazySystemDLL("pdh.dll") // Functions - pdh_AddCounterW = libpdhDll.MustFindProc("PdhAddCounterW") - pdh_AddEnglishCounterW = libpdhDll.MustFindProc("PdhAddEnglishCounterW") // XXX: only supported on versions > Vista. - pdh_CloseQuery = libpdhDll.MustFindProc("PdhCloseQuery") - pdh_CollectQueryData = libpdhDll.MustFindProc("PdhCollectQueryData") - pdh_GetFormattedCounterValue = libpdhDll.MustFindProc("PdhGetFormattedCounterValue") - pdh_GetFormattedCounterArrayW = libpdhDll.MustFindProc("PdhGetFormattedCounterArrayW") - pdh_OpenQuery = libpdhDll.MustFindProc("PdhOpenQuery") - pdh_ValidatePathW = libpdhDll.MustFindProc("PdhValidatePathW") + pdh_AddCounterW = libpdhDll.NewProc("PdhAddCounterW") + pdh_AddEnglishCounterW = libpdhDll.NewProc("PdhAddEnglishCounterW") + pdh_CloseQuery = libpdhDll.NewProc("PdhCloseQuery") + pdh_CollectQueryData = libpdhDll.NewProc("PdhCollectQueryData") + pdh_GetFormattedCounterValue = libpdhDll.NewProc("PdhGetFormattedCounterValue") + pdh_GetFormattedCounterArrayW = libpdhDll.NewProc("PdhGetFormattedCounterArrayW") + pdh_OpenQuery = libpdhDll.NewProc("PdhOpenQuery") + pdh_ValidatePathW = libpdhDll.NewProc("PdhValidatePathW") } // Adds the specified counter to the query. This is the internationalized version. Preferably, use the @@ -239,6 +242,10 @@ func PdhAddCounter(hQuery PDH_HQUERY, szFullCounterPath string, dwUserData uintp // Adds the specified language-neutral counter to the query. See the PdhAddCounter function. This function only exists on // Windows versions higher than Vista. func PdhAddEnglishCounter(hQuery PDH_HQUERY, szFullCounterPath string, dwUserData uintptr, phCounter *PDH_HCOUNTER) uint32 { + if pdh_AddEnglishCounterW.Find() != nil { + return ERROR_INVALID_FUNCTION + } + ptxt, _ := syscall.UTF16PtrFromString(szFullCounterPath) ret, _, _ := pdh_AddEnglishCounterW.Call( uintptr(hQuery), diff --git a/richedit.go b/richedit.go new file mode 100644 index 00000000..aa51204b --- /dev/null +++ b/richedit.go @@ -0,0 +1,1273 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +const ( + // NOTE: MSFTEDIT.DLL only registers MSFTEDIT_CLASS. If an application wants + // to use the following RichEdit classes, it needs to load riched20.dll. + // Otherwise, CreateWindow with RICHEDIT_CLASS will fail. + // This also applies to any dialog that uses RICHEDIT_CLASS + // RichEdit 2.0 Window Class + MSFTEDIT_CLASS = "RICHEDIT50W" + RICHEDIT_CLASS = "RichEdit20W" +) + +// RichEdit messages +const ( + EM_CANPASTE = WM_USER + 50 + EM_DISPLAYBAND = WM_USER + 51 + EM_EXGETSEL = WM_USER + 52 + EM_EXLIMITTEXT = WM_USER + 53 + EM_EXLINEFROMCHAR = WM_USER + 54 + EM_EXSETSEL = WM_USER + 55 + EM_FINDTEXT = WM_USER + 56 + EM_FORMATRANGE = WM_USER + 57 + EM_GETCHARFORMAT = WM_USER + 58 + EM_GETEVENTMASK = WM_USER + 59 + EM_GETOLEINTERFACE = WM_USER + 60 + EM_GETPARAFORMAT = WM_USER + 61 + EM_GETSELTEXT = WM_USER + 62 + EM_HIDESELECTION = WM_USER + 63 + EM_PASTESPECIAL = WM_USER + 64 + EM_REQUESTRESIZE = WM_USER + 65 + EM_SELECTIONTYPE = WM_USER + 66 + EM_SETBKGNDCOLOR = WM_USER + 67 + EM_SETCHARFORMAT = WM_USER + 68 + EM_SETEVENTMASK = WM_USER + 69 + EM_SETOLECALLBACK = WM_USER + 70 + EM_SETPARAFORMAT = WM_USER + 71 + EM_SETTARGETDEVICE = WM_USER + 72 + EM_STREAMIN = WM_USER + 73 + EM_STREAMOUT = WM_USER + 74 + EM_GETTEXTRANGE = WM_USER + 75 + EM_FINDWORDBREAK = WM_USER + 76 + EM_SETOPTIONS = WM_USER + 77 + EM_GETOPTIONS = WM_USER + 78 + EM_FINDTEXTEX = WM_USER + 79 + EM_GETWORDBREAKPROCEX = WM_USER + 80 + EM_SETWORDBREAKPROCEX = WM_USER + 81 +) + +// RichEdit 2.0 messages +const ( + EM_SETUNDOLIMIT = WM_USER + 82 + EM_REDO = WM_USER + 84 + EM_CANREDO = WM_USER + 85 + EM_GETUNDONAME = WM_USER + 86 + EM_GETREDONAME = WM_USER + 87 + EM_STOPGROUPTYPING = WM_USER + 88 + + EM_SETTEXTMODE = WM_USER + 89 + EM_GETTEXTMODE = WM_USER + 90 +) + +type TEXTMODE int32 + +const ( + TM_PLAINTEXT TEXTMODE = 1 + TM_RICHTEXT = 2 // Default behavior + TM_SINGLELEVELUNDO = 4 + TM_MULTILEVELUNDO = 8 // Default behavior + TM_SINGLECODEPAGE = 16 + TM_MULTICODEPAGE = 32 // Default behavior +) + +const ( + EM_AUTOURLDETECT = WM_USER + 91 +) + +// RichEdit 8.0 messages +const ( + AURL_ENABLEURL = 1 + AURL_ENABLEEMAILADDR = 2 + AURL_ENABLETELNO = 4 + AURL_ENABLEEAURLS = 8 + AURL_ENABLEDRIVELETTERS = 16 + AURL_DISABLEMIXEDLGC = 32 // Disable mixed Latin Greek Cyrillic IDNs +) + +const ( + EM_GETAUTOURLDETECT = WM_USER + 92 + EM_SETPALETTE = WM_USER + 93 + EM_GETTEXTEX = WM_USER + 94 + EM_GETTEXTLENGTHEX = WM_USER + 95 + EM_SHOWSCROLLBAR = WM_USER + 96 + EM_SETTEXTEX = WM_USER + 97 +) + +// East Asia specific messages +const ( + EM_SETPUNCTUATION = WM_USER + 100 + EM_GETPUNCTUATION = WM_USER + 101 + EM_SETWORDWRAPMODE = WM_USER + 102 + EM_GETWORDWRAPMODE = WM_USER + 103 + EM_SETIMECOLOR = WM_USER + 104 + EM_GETIMECOLOR = WM_USER + 105 + EM_SETIMEOPTIONS = WM_USER + 106 + EM_GETIMEOPTIONS = WM_USER + 107 + EM_CONVPOSITION = WM_USER + 108 +) + +const ( + EM_SETLANGOPTIONS = WM_USER + 120 + EM_GETLANGOPTIONS = WM_USER + 121 + EM_GETIMECOMPMODE = WM_USER + 122 + + EM_FINDTEXTW = WM_USER + 123 + EM_FINDTEXTEXW = WM_USER + 124 +) + +// RE3.0 FE messages +const ( + EM_RECONVERSION = WM_USER + 125 + EM_SETIMEMODEBIAS = WM_USER + 126 + EM_GETIMEMODEBIAS = WM_USER + 127 +) + +// BiDi specific messages +const ( + EM_SETBIDIOPTIONS = WM_USER + 200 + EM_GETBIDIOPTIONS = WM_USER + 201 + + EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202 + EM_GETTYPOGRAPHYOPTIONS = WM_USER + 203 +) + +// Extended edit style specific messages +const ( + EM_SETEDITSTYLE = WM_USER + 204 + EM_GETEDITSTYLE = WM_USER + 205 +) + +// Extended edit style masks +const ( + SES_EMULATESYSEDIT = 1 + SES_BEEPONMAXTEXT = 2 + SES_EXTENDBACKCOLOR = 4 + SES_MAPCPS = 8 // Obsolete (never used) + SES_HYPERLINKTOOLTIPS = 8 + SES_EMULATE10 = 16 // Obsolete (never used) + SES_DEFAULTLATINLIGA = 16 + SES_USECRLF = 32 // Obsolete (never used) + SES_NOFOCUSLINKNOTIFY = 32 + SES_USEAIMM = 64 + SES_NOIME = 128 + + SES_ALLOWBEEPS = 256 + SES_UPPERCASE = 512 + SES_LOWERCASE = 1024 + SES_NOINPUTSEQUENCECHK = 2048 + SES_BIDI = 4096 + SES_SCROLLONKILLFOCUS = 8192 + SES_XLTCRCRLFTOCR = 16384 + SES_DRAFTMODE = 32768 + + SES_USECTF = 0x00010000 + SES_HIDEGRIDLINES = 0x00020000 + SES_USEATFONT = 0x00040000 + SES_CUSTOMLOOK = 0x00080000 + SES_LBSCROLLNOTIFY = 0x00100000 + SES_CTFALLOWEMBED = 0x00200000 + SES_CTFALLOWSMARTTAG = 0x00400000 + SES_CTFALLOWPROOFING = 0x00800000 + SES_LOGICALCARET = 0x01000000 + SES_WORDDRAGDROP = 0x02000000 + SES_SMARTDRAGDROP = 0x04000000 + SES_MULTISELECT = 0x08000000 + SES_CTFNOLOCK = 0x10000000 + SES_NOEALINEHEIGHTADJUST = 0x20000000 + SES_MAX = 0x20000000 +) + +// Options for EM_SETLANGOPTIONS and EM_GETLANGOPTIONS +const ( + IMF_AUTOKEYBOARD = 0x0001 + IMF_AUTOFONT = 0x0002 + IMF_IMECANCELCOMPLETE = 0x0004 // High completes comp string when aborting, low cancels + IMF_IMEALWAYSSENDNOTIFY = 0x0008 + IMF_AUTOFONTSIZEADJUST = 0x0010 + IMF_UIFONTS = 0x0020 + IMF_NOIMPLICITLANG = 0x0040 + IMF_DUALFONT = 0x0080 + IMF_NOKBDLIDFIXUP = 0x0200 + IMF_NORTFFONTSUBSTITUTE = 0x0400 + IMF_SPELLCHECKING = 0x0800 + IMF_TKBPREDICTION = 0x1000 + IMF_IMEUIINTEGRATION = 0x2000 +) + +// Values for EM_GETIMECOMPMODE +const ( + ICM_NOTOPEN = 0x0000 + ICM_LEVEL3 = 0x0001 + ICM_LEVEL2 = 0x0002 + ICM_LEVEL2_5 = 0x0003 + ICM_LEVEL2_SUI = 0x0004 + ICM_CTF = 0x0005 +) + +// Options for EM_SETTYPOGRAPHYOPTIONS +const ( + TO_ADVANCEDTYPOGRAPHY = 0x0001 + TO_SIMPLELINEBREAK = 0x0002 + TO_DISABLECUSTOMTEXTOUT = 0x0004 + TO_ADVANCEDLAYOUT = 0x0008 +) + +// Pegasus outline mode messages (RE 3.0) +const ( + // Outline mode message + EM_OUTLINE = WM_USER + 220 + + // Message for getting and restoring scroll pos + EM_GETSCROLLPOS = WM_USER + 221 + EM_SETSCROLLPOS = WM_USER + 222 + + // Change fontsize in current selection by wParam + EM_SETFONTSIZE = WM_USER + 223 + EM_GETZOOM = WM_USER + 224 + EM_SETZOOM = WM_USER + 225 + EM_GETVIEWKIND = WM_USER + 226 + EM_SETVIEWKIND = WM_USER + 227 +) + +// RichEdit 4.0 messages +const ( + EM_GETPAGE = WM_USER + 228 + EM_SETPAGE = WM_USER + 229 + EM_GETHYPHENATEINFO = WM_USER + 230 + EM_SETHYPHENATEINFO = WM_USER + 231 + + EM_GETPAGEROTATE = WM_USER + 235 + EM_SETPAGEROTATE = WM_USER + 236 + EM_GETCTFMODEBIAS = WM_USER + 237 + EM_SETCTFMODEBIAS = WM_USER + 238 + EM_GETCTFOPENSTATUS = WM_USER + 240 + EM_SETCTFOPENSTATUS = WM_USER + 241 + EM_GETIMECOMPTEXT = WM_USER + 242 + EM_ISIME = WM_USER + 243 + EM_GETIMEPROPERTY = WM_USER + 244 +) + +// These messages control what rich edit does when it comes accross +// OLE objects during RTF stream in. Normally rich edit queries the client +// application only after OleLoad has been called. With these messages it is possible to +// set the rich edit control to a mode where it will query the client application before +// OleLoad is called +const ( + EM_GETQUERYRTFOBJ = WM_USER + 269 + EM_SETQUERYRTFOBJ = WM_USER + 270 +) + +// EM_SETPAGEROTATE wparam values +const ( + EPR_0 = 0 // Text flows left to right and top to bottom + EPR_270 = 1 // Text flows top to bottom and right to left + EPR_180 = 2 // Text flows right to left and bottom to top + EPR_90 = 3 // Text flows bottom to top and left to right + EPR_SE = 5 // Text flows top to bottom and left to right (Mongolian text layout) +) + +// EM_SETCTFMODEBIAS wparam values +const ( + CTFMODEBIAS_DEFAULT = 0x0000 + CTFMODEBIAS_FILENAME = 0x0001 + CTFMODEBIAS_NAME = 0x0002 + CTFMODEBIAS_READING = 0x0003 + CTFMODEBIAS_DATETIME = 0x0004 + CTFMODEBIAS_CONVERSATION = 0x0005 + CTFMODEBIAS_NUMERIC = 0x0006 + CTFMODEBIAS_HIRAGANA = 0x0007 + CTFMODEBIAS_KATAKANA = 0x0008 + CTFMODEBIAS_HANGUL = 0x0009 + CTFMODEBIAS_HALFWIDTHKATAKANA = 0x000A + CTFMODEBIAS_FULLWIDTHALPHANUMERIC = 0x000B + CTFMODEBIAS_HALFWIDTHALPHANUMERIC = 0x000C +) + +// EM_SETIMEMODEBIAS lparam values +const ( + IMF_SMODE_PLAURALCLAUSE = 0x0001 + IMF_SMODE_NONE = 0x0002 +) + +// EM_GETIMECOMPTEXT wparam structure +type IMECOMPTEXT struct { + // count of bytes in the output buffer. + Cb int32 + + // value specifying the composition string type. + // Currently only support ICT_RESULTREADSTR + Flags uint32 +} + +const ICT_RESULTREADSTR = 1 + +// Outline mode wparam values +const ( + // Enter normal mode, lparam ignored + EMO_EXIT = 0 + + // Enter outline mode, lparam ignored + EMO_ENTER = 1 + + // LOWORD(lparam) == 0 ==> + // promote to body-text + // LOWORD(lparam) != 0 ==> + // promote/demote current selection + // by indicated number of levels + EMO_PROMOTE = 2 + + // HIWORD(lparam) = EMO_EXPANDSELECTION + // -> expands selection to level + // indicated in LOWORD(lparam) + // LOWORD(lparam) = -1/+1 corresponds + // to collapse/expand button presses + // in winword (other values are + // equivalent to having pressed these + // buttons more than once) + // HIWORD(lparam) = EMO_EXPANDDOCUMENT + // -> expands whole document to + // indicated level + EMO_EXPAND = 3 + + // LOWORD(lparam) != 0 -> move current + // selection up/down by indicated amount + EMO_MOVESELECTION = 4 + + // Returns VM_NORMAL or VM_OUTLINE + EMO_GETVIEWMODE = 5 +) + +// EMO_EXPAND options +const ( + EMO_EXPANDSELECTION = 0 + EMO_EXPANDDOCUMENT = 1 +) + +const ( + // Agrees with RTF \viewkindN + VM_NORMAL = 4 + + VM_OUTLINE = 2 + + // Screen page view (not print layout) + VM_PAGE = 9 +) + +// New messages as of Win8 +const ( + EM_INSERTTABLE = WM_USER + 232 +) + +// Data type defining table rows for EM_INSERTTABLE +// Note: The Richedit.h is completely #pragma pack(4)-ed +type TABLEROWPARMS struct { // EM_INSERTTABLE wparam is a (TABLEROWPARMS *) + CbRow uint32 // Count of bytes in this structure + CbCell uint32 // Count of bytes in TABLECELLPARMS + CCell uint32 // Count of cells + CRow uint32 // Count of rows + DxCellMargin int32 // Cell left/right margin (\trgaph) + DxIndent int32 // Row left (right if fRTL indent (similar to \trleft) + DyHeight int32 // Row height (\trrh) + + // nAlignment:3 Row alignment (like PARAFORMAT::bAlignment, \trql, trqr, \trqc) + // fRTL:1 Display cells in RTL order (\rtlrow) + // fKeep:1 Keep row together (\trkeep} + // fKeepFollow:1 Keep row on same page as following row (\trkeepfollow) + // fWrap:1 Wrap text to right/left (depending on bAlignment) (see \tdfrmtxtLeftN, \tdfrmtxtRightN) + // fIdentCells:1 lparam points at single struct valid for all cells + Flags uint32 + + CpStartRow int32 // cp where to insert table (-1 for selection cp) (can be used for either TRD by EM_GETTABLEPARMS) + BTableLevel uint32 // Table nesting level (EM_GETTABLEPARMS only) + ICell uint32 // Index of cell to insert/delete (EM_SETTABLEPARMS only) +} + +// Data type defining table cells for EM_INSERTTABLE +// Note: The Richedit.h is completely #pragma pack(4)-ed +type TABLECELLPARMS struct { // EM_INSERTTABLE lparam is a (TABLECELLPARMS *) + DxWidth int32 // Cell width (\cellx) + + // nVertAlign:2 Vertical alignment (0/1/2 = top/center/bottom \clvertalt (def), \clvertalc, \clvertalb) + // fMergeTop:1 Top cell for vertical merge (\clvmgf) + // fMergePrev:1 Merge with cell above (\clvmrg) + // fVertical:1 Display text top to bottom, right to left (\cltxtbrlv) + // fMergeStart:1 Start set of horizontally merged cells (\clmgf) + // fMergeCont:1 Merge with previous cell (\clmrg) + Flags uint32 + + WShading uint32 // Shading in .01% (\clshdng) e.g., 10000 flips fore/back + + DxBrdrLeft int32 // Left border width (\clbrdrl\brdrwN) (in twips) + DyBrdrTop int32 // Top border width (\clbrdrt\brdrwN) + DxBrdrRight int32 // Right border width (\clbrdrr\brdrwN) + DyBrdrBottom int32 // Bottom border width (\clbrdrb\brdrwN) + + CrBrdrLeft COLORREF // Left border color (\clbrdrl\brdrcf) + CrBrdrTop COLORREF // Top border color (\clbrdrt\brdrcf) + CrBrdrRight COLORREF // Right border color (\clbrdrr\brdrcf) + CrBrdrBottom COLORREF // Bottom border color (\clbrdrb\brdrcf) + CrBackPat COLORREF // Background color (\clcbpat) + CrForePat COLORREF // Foreground color (\clcfpat) +} + +const ( + EM_GETAUTOCORRECTPROC = WM_USER + 233 + EM_SETAUTOCORRECTPROC = WM_USER + 234 + EM_CALLAUTOCORRECTPROC = WM_USER + 255 +) + +// AutoCorrect callback +type AutoCorrectProc func(langid LANGID, pszBefore *uint16, pszAfter *uint16, cchAfter int32, pcchReplaced *int32) int + +const ( + ATP_NOCHANGE = 0 + ATP_CHANGE = 1 + ATP_NODELIMITER = 2 + ATP_REPLACEALLTEXT = 4 +) + +const ( + EM_GETTABLEPARMS = WM_USER + 265 + + EM_SETEDITSTYLEEX = WM_USER + 275 + EM_GETEDITSTYLEEX = WM_USER + 276 +) + +// wparam values for EM_SETEDITSTYLEEX/EM_GETEDITSTYLEEX +// All unused bits are reserved. +const ( + SES_EX_NOTABLE = 0x00000004 + SES_EX_NOMATH = 0x00000040 + SES_EX_HANDLEFRIENDLYURL = 0x00000100 + SES_EX_NOTHEMING = 0x00080000 + SES_EX_NOACETATESELECTION = 0x00100000 + SES_EX_USESINGLELINE = 0x00200000 + SES_EX_MULTITOUCH = 0x08000000 // Only works under Win8+ + SES_EX_HIDETEMPFORMAT = 0x10000000 + SES_EX_USEMOUSEWPARAM = 0x20000000 // Use wParam when handling WM_MOUSEMOVE message and do not call GetAsyncKeyState +) + +const ( + EM_GETSTORYTYPE = WM_USER + 290 + EM_SETSTORYTYPE = WM_USER + 291 + + EM_GETELLIPSISMODE = WM_USER + 305 + EM_SETELLIPSISMODE = WM_USER + 306 +) + +// uint32: *lparam for EM_GETELLIPSISMODE, lparam for EM_SETELLIPSISMODE +const ( + ELLIPSIS_MASK = 0x00000003 // all meaningful bits + ELLIPSIS_NONE = 0x00000000 // ellipsis disabled + ELLIPSIS_END = 0x00000001 // ellipsis at the end (forced break) + ELLIPSIS_WORD = 0x00000003 // ellipsis at the end (word break) +) + +const ( + EM_SETTABLEPARMS = WM_USER + 307 + + EM_GETTOUCHOPTIONS = WM_USER + 310 + EM_SETTOUCHOPTIONS = WM_USER + 311 + EM_INSERTIMAGE = WM_USER + 314 + EM_SETUIANAME = WM_USER + 320 + EM_GETELLIPSISSTATE = WM_USER + 322 +) + +// Values for EM_SETTOUCHOPTIONS/EM_GETTOUCHOPTIONS +const ( + RTO_SHOWHANDLES = 1 + RTO_DISABLEHANDLES = 2 + RTO_READINGMODE = 3 +) + +// lparam for EM_INSERTIMAGE +type RICHEDIT_IMAGE_PARAMETERS struct { + XWidth int32 // Units are HIMETRIC + YHeight int32 // Units are HIMETRIC + Ascent int32 // Units are HIMETRIC + Type int32 // Valid values are TA_TOP, TA_BOTTOM and TA_BASELINE + PwszAlternateText *uint16 + PIStream uintptr +} + +// New notifications +const ( + EN_MSGFILTER = 0x0700 + EN_REQUESTRESIZE = 0x0701 + EN_SELCHANGE = 0x0702 + EN_DROPFILES = 0x0703 + EN_PROTECTED = 0x0704 + EN_CORRECTTEXT = 0x0705 // PenWin specific + EN_STOPNOUNDO = 0x0706 + EN_IMECHANGE = 0x0707 // East Asia specific + EN_SAVECLIPBOARD = 0x0708 + EN_OLEOPFAILED = 0x0709 + EN_OBJECTPOSITIONS = 0x070a + EN_LINK = 0x070b + EN_DRAGDROPDONE = 0x070c + EN_PARAGRAPHEXPANDED = 0x070d + EN_PAGECHANGE = 0x070e + EN_LOWFIRTF = 0x070f + EN_ALIGNLTR = 0x0710 // BiDi specific notification + EN_ALIGNRTL = 0x0711 // BiDi specific notification + EN_CLIPFORMAT = 0x0712 + EN_STARTCOMPOSITION = 0x0713 + EN_ENDCOMPOSITION = 0x0714 +) + +// Notification structure for EN_ENDCOMPOSITION +type ENDCOMPOSITIONNOTIFY struct { + Nmhdr NMHDR + DwCode uint32 +} + +// Constants for ENDCOMPOSITIONNOTIFY dwCode +const ( + ECN_ENDCOMPOSITION = 0x0001 + ECN_NEWTEXT = 0x0002 +) + +// Event notification masks +const ( + ENM_NONE = 0x00000000 + ENM_CHANGE = 0x00000001 + ENM_UPDATE = 0x00000002 + ENM_SCROLL = 0x00000004 + ENM_SCROLLEVENTS = 0x00000008 + ENM_DRAGDROPDONE = 0x00000010 + ENM_PARAGRAPHEXPANDED = 0x00000020 + ENM_PAGECHANGE = 0x00000040 + ENM_CLIPFORMAT = 0x00000080 + ENM_KEYEVENTS = 0x00010000 + ENM_MOUSEEVENTS = 0x00020000 + ENM_REQUESTRESIZE = 0x00040000 + ENM_SELCHANGE = 0x00080000 + ENM_DROPFILES = 0x00100000 + ENM_PROTECTED = 0x00200000 + ENM_CORRECTTEXT = 0x00400000 // PenWin specific + ENM_IMECHANGE = 0x00800000 // Used by RE1.0 compatibility + ENM_LANGCHANGE = 0x01000000 + ENM_OBJECTPOSITIONS = 0x02000000 + ENM_LINK = 0x04000000 + ENM_LOWFIRTF = 0x08000000 + ENM_STARTCOMPOSITION = 0x10000000 + ENM_ENDCOMPOSITION = 0x20000000 + ENM_GROUPTYPINGCHANGE = 0x40000000 + ENM_HIDELINKTOOLTIP = 0x80000000 +) + +// New edit control styles +const ( + ES_SAVESEL = 0x00008000 + ES_SUNKEN = 0x00004000 + ES_DISABLENOSCROLL = 0x00002000 + ES_SELECTIONBAR = 0x01000000 // Same as WS_MAXIMIZE, but that doesn't make sense so we re-use the value + ES_NOOLEDRAGDROP = 0x00000008 // Same as ES_UPPERCASE, but re-used to completely disable OLE drag'n'drop +) + +// Obsolete Edit Style +const ( + ES_EX_NOCALLOLEINIT = 0x00000000 // Not supported in RE 2.0/3.0 +) + +// These flags are used in FE Windows +const ( + ES_VERTICAL = 0x00400000 // Not supported in RE 2.0/3.0 + ES_NOIME = 0x00080000 + ES_SELFIME = 0x00040000 +) + +// Edit control options +const ( + ECO_AUTOWORDSELECTION = 0x00000001 + ECO_AUTOVSCROLL = 0x00000040 + ECO_AUTOHSCROLL = 0x00000080 + ECO_NOHIDESEL = 0x00000100 + ECO_READONLY = 0x00000800 + ECO_WANTRETURN = 0x00001000 + ECO_SAVESEL = 0x00008000 + ECO_SELECTIONBAR = 0x01000000 + ECO_VERTICAL = 0x00400000 // FE specific +) + +// ECO operations +const ( + ECOOP_SET = 0x0001 + ECOOP_OR = 0x0002 + ECOOP_AND = 0x0003 + ECOOP_XOR = 0x0004 +) + +// New word break function actions +const ( + WB_CLASSIFY = 3 + WB_MOVEWORDLEFT = 4 + WB_MOVEWORDRIGHT = 5 + WB_LEFTBREAK = 6 + WB_RIGHTBREAK = 7 +) + +// East Asia specific flags +const ( + WB_MOVEWORDPREV = 4 + WB_MOVEWORDNEXT = 5 + WB_PREVBREAK = 6 + WB_NEXTBREAK = 7 + + PC_FOLLOWING = 1 + PC_LEADING = 2 + PC_OVERFLOW = 3 + PC_DELIMITER = 4 + WBF_WORDWRAP = 0x010 + WBF_WORDBREAK = 0x020 + WBF_OVERFLOW = 0x040 + WBF_LEVEL1 = 0x080 + WBF_LEVEL2 = 0x100 + WBF_CUSTOM = 0x200 +) + +// East Asia specific flags +const ( + IMF_FORCENONE = 0x0001 + IMF_FORCEENABLE = 0x0002 + IMF_FORCEDISABLE = 0x0004 + IMF_CLOSESTATUSWINDOW = 0x0008 + IMF_VERTICAL = 0x0020 + IMF_FORCEACTIVE = 0x0040 + IMF_FORCEINACTIVE = 0x0080 + IMF_FORCEREMEMBER = 0x0100 + IMF_MULTIPLEEDIT = 0x0400 +) + +// Word break flags (used with WB_CLASSIFY) +const ( + WBF_CLASS byte = 0x0F + WBF_ISWHITE byte = 0x10 + WBF_BREAKLINE byte = 0x20 + WBF_BREAKAFTER byte = 0x40 +) + +type CHARFORMAT struct { + CbSize uint32 + DwMask uint32 + DwEffects uint32 + YHeight int32 + YOffset int32 + CrTextColor COLORREF + BCharSet byte + BPitchAndFamily byte + SzFaceName [LF_FACESIZE]uint16 +} + +type CHARFORMAT2 struct { + CHARFORMAT + WWeight uint16 // Font weight (LOGFONT value) + SSpacing int16 // Amount to space between letters + CrBackColor COLORREF // Background color + Lcid LCID // Locale ID + DwCookie uint32 // Client cookie opaque to RichEdit + SStyle int16 // Style handle + WKerning uint16 // Twip size above which to kern char pair + BUnderlineType byte // Underline type + BAnimation byte // Animated text like marching ants + BRevAuthor byte // Revision author index + BUnderlineColor byte // Underline color +} + +// CHARFORMAT masks +const ( + CFM_BOLD = 0x00000001 + CFM_ITALIC = 0x00000002 + CFM_UNDERLINE = 0x00000004 + CFM_STRIKEOUT = 0x00000008 + CFM_PROTECTED = 0x00000010 + CFM_LINK = 0x00000020 // Exchange hyperlink extension + CFM_SIZE = 0x80000000 + CFM_COLOR = 0x40000000 + CFM_FACE = 0x20000000 + CFM_OFFSET = 0x10000000 + CFM_CHARSET = 0x08000000 +) + +// CHARFORMAT effects +const ( + CFE_BOLD = 0x00000001 + CFE_ITALIC = 0x00000002 + CFE_UNDERLINE = 0x00000004 + CFE_STRIKEOUT = 0x00000008 + CFE_PROTECTED = 0x00000010 + CFE_LINK = 0x00000020 + CFE_AUTOCOLOR = 0x40000000 // NOTE: this corresponds to CFM_COLOR, which controls it + + // Masks and effects defined for CHARFORMAT2 -- an (*) indicates that the data is stored by RichEdit 2.0/3.0, but not displayed + CFM_SMALLCAPS = 0x00000040 // (*) + CFM_ALLCAPS = 0x00000080 // Displayed by 3.0 + CFM_HIDDEN = 0x00000100 // Hidden by 3.0 + CFM_OUTLINE = 0x00000200 // (*) + CFM_SHADOW = 0x00000400 // (*) + CFM_EMBOSS = 0x00000800 // (*) + CFM_IMPRINT = 0x00001000 // (*) + CFM_DISABLED = 0x00002000 + CFM_REVISED = 0x00004000 + + CFM_REVAUTHOR = 0x00008000 + CFE_SUBSCRIPT = 0x00010000 // Superscript and subscript are + CFE_SUPERSCRIPT = 0x00020000 // mutually exclusive + CFM_ANIMATION = 0x00040000 // (*) + CFM_STYLE = 0x00080000 // (*) + CFM_KERNING = 0x00100000 + CFM_SPACING = 0x00200000 // Displayed by 3.0 + CFM_WEIGHT = 0x00400000 + CFM_UNDERLINETYPE = 0x00800000 // Many displayed by 3.0 + CFM_COOKIE = 0x01000000 // RE 6.0 + CFM_LCID = 0x02000000 + CFM_BACKCOLOR = 0x04000000 // Higher mask bits defined above + + CFM_SUBSCRIPT = (CFE_SUBSCRIPT | CFE_SUPERSCRIPT) + CFM_SUPERSCRIPT = CFM_SUBSCRIPT + + // CHARFORMAT "ALL" masks + CFM_EFFECTS = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_COLOR | CFM_STRIKEOUT | CFE_PROTECTED | CFM_LINK + CFM_ALL = CFM_EFFECTS | CFM_SIZE | CFM_FACE | CFM_OFFSET | CFM_CHARSET + CFM_EFFECTS2 = CFM_EFFECTS | CFM_DISABLED | CFM_SMALLCAPS | CFM_ALLCAPS | CFM_HIDDEN | CFM_OUTLINE | CFM_SHADOW | CFM_EMBOSS | CFM_IMPRINT | CFM_REVISED | CFM_SUBSCRIPT | CFM_SUPERSCRIPT | CFM_BACKCOLOR + CFM_ALL2 = CFM_ALL | CFM_EFFECTS2 | CFM_BACKCOLOR | CFM_LCID | CFM_UNDERLINETYPE | CFM_WEIGHT | CFM_REVAUTHOR | CFM_SPACING | CFM_KERNING | CFM_STYLE | CFM_ANIMATION | CFM_COOKIE + + CFE_SMALLCAPS = CFM_SMALLCAPS + CFE_ALLCAPS = CFM_ALLCAPS + CFE_HIDDEN = CFM_HIDDEN + CFE_OUTLINE = CFM_OUTLINE + CFE_SHADOW = CFM_SHADOW + CFE_EMBOSS = CFM_EMBOSS + CFE_IMPRINT = CFM_IMPRINT + CFE_DISABLED = CFM_DISABLED + CFE_REVISED = CFM_REVISED + + // CFE_AUTOCOLOR and CFE_AUTOBACKCOLOR correspond to CFM_COLOR and + // CFM_BACKCOLOR, respectively, which control them + CFE_AUTOBACKCOLOR = CFM_BACKCOLOR + + CFM_FONTBOUND = 0x00100000 + CFM_LINKPROTECTED = 0x00800000 // Word hyperlink field + CFM_EXTENDED = 0x02000000 + CFM_MATHNOBUILDUP = 0x08000000 + CFM_MATH = 0x10000000 + CFM_MATHORDINARY = 0x20000000 + + CFM_ALLEFFECTS = (CFM_EFFECTS2 | CFM_FONTBOUND | CFM_EXTENDED | CFM_MATHNOBUILDUP | CFM_MATH | CFM_MATHORDINARY) + + CFE_FONTBOUND = 0x00100000 // Font chosen by binder, not user + CFE_LINKPROTECTED = 0x00800000 + CFE_EXTENDED = 0x02000000 + CFE_MATHNOBUILDUP = 0x08000000 + CFE_MATH = 0x10000000 + CFE_MATHORDINARY = 0x20000000 + + // Underline types. RE 1.0 displays only CFU_UNDERLINE + CFU_CF1UNDERLINE = 0xFF // Map charformat's bit underline to CF2 + CFU_INVERT = 0xFE // For IME composition fake a selection + CFU_UNDERLINETHICKLONGDASH = 18 // (*) display as dash + CFU_UNDERLINETHICKDOTTED = 17 // (*) display as dot + CFU_UNDERLINETHICKDASHDOTDOT = 16 // (*) display as dash dot dot + CFU_UNDERLINETHICKDASHDOT = 15 // (*) display as dash dot + CFU_UNDERLINETHICKDASH = 14 // (*) display as dash + CFU_UNDERLINELONGDASH = 13 // (*) display as dash + CFU_UNDERLINEHEAVYWAVE = 12 // (*) display as wave + CFU_UNDERLINEDOUBLEWAVE = 11 // (*) display as wave + CFU_UNDERLINEHAIRLINE = 10 // (*) display as single + CFU_UNDERLINETHICK = 9 + CFU_UNDERLINEWAVE = 8 + CFU_UNDERLINEDASHDOTDOT = 7 + CFU_UNDERLINEDASHDOT = 6 + CFU_UNDERLINEDASH = 5 + CFU_UNDERLINEDOTTED = 4 + CFU_UNDERLINEDOUBLE = 3 // (*) display as single + CFU_UNDERLINEWORD = 2 // (*) display as single + CFU_UNDERLINE = 1 + CFU_UNDERLINENONE = 0 +) + +const YHeightCharPtsMost = 1638 + +const ( + // EM_SETCHARFORMAT wParam masks + SCF_SELECTION = 0x0001 + SCF_WORD = 0x0002 + SCF_DEFAULT = 0x0000 // Set default charformat or paraformat + SCF_ALL = 0x0004 // Not valid with SCF_SELECTION or SCF_WORD + SCF_USEUIRULES = 0x0008 // Modifier for SCF_SELECTION; says that came from a toolbar, etc., and UI formatting rules should be instead of literal formatting + SCF_ASSOCIATEFONT = 0x0010 // Associate fontname with bCharSet (one possible for each of Western, ME, FE, Thai) + SCF_NOKBUPDATE = 0x0020 // Do not update KB layout for this change even if autokeyboard is on + SCF_ASSOCIATEFONT2 = 0x0040 // Associate plane-2 (surrogate) font + SCF_SMARTFONT = 0x0080 // Apply font only if it can handle script (5.0) + SCF_CHARREPFROMLCID = 0x0100 // Get character repertoire from lcid (5.0) + + SPF_DONTSETDEFAULT = 0x0002 // Suppress setting default on empty control + SPF_SETDEFAULT = 0x0004 // Set the default paraformat +) + +type CHARRANGE struct { + CpMin int32 + CpMax int32 +} + +type TEXTRANGE struct { + Chrg CHARRANGE + LpstrText *uint16 // Allocated by caller, zero terminated by RichEdit +} + +type EDITSTREAM struct { + DwCookie uintptr // User value passed to callback as first parameter + DwError uint32 // Last error + PfnCallback uintptr +} + +const ( + // Stream formats. Flags are all in low word, since high word gives possible codepage choice. + SF_TEXT = 0x0001 + SF_RTF = 0x0002 + SF_RTFNOOBJS = 0x0003 // Write only + SF_TEXTIZED = 0x0004 // Write only + + SF_UNICODE = 0x0010 // Unicode file (UCS2 little endian) + SF_USECODEPAGE = 0x0020 // CodePage given by high word + SF_NCRFORNONASCII = 0x40 // Output \uN for nonASCII + SFF_WRITEXTRAPAR = 0x80 // Output \par at end + + // Flag telling stream operations to operate on selection only + // EM_STREAMIN replaces current selection + // EM_STREAMOUT streams out current selection + SFF_SELECTION = 0x8000 + + // Flag telling stream operations to ignore some FE control words having to do with FE word breaking and horiz vs vertical text. + // Not used in RichEdit 2.0 and later + SFF_PLAINRTF = 0x4000 + + // Flag telling file stream output (SFF_SELECTION flag not set) to persist // \viewscaleN control word. + SFF_PERSISTVIEWSCALE = 0x2000 + + // Flag telling file stream input with SFF_SELECTION flag not set not to // close the document + SFF_KEEPDOCINFO = 0x1000 + + // Flag telling stream operations to output in Pocket Word format + SFF_PWD = 0x0800 + + // 3-bit field specifying the value of N - 1 to use for \rtfN or \pwdN + SF_RTFVAL = 0x0700 +) + +type FINDTEXT struct { + Chrg CHARRANGE + LpstrText *uint16 +} + +type FINDTEXTEX struct { + chrg CHARRANGE + lpstrText *uint16 + chrgText CHARRANGE +} + +type FORMATRANGE struct { + hdc HDC + hdcTarget HDC + rc RECT + rcPage RECT + chrg CHARRANGE +} + +// All paragraph measurements are in twips +const ( + MAX_TAB_STOPS = 32 + LDefaultTab = 720 + MAX_TABLE_CELLS = 63 +) + +type PARAFORMAT struct { + CbSize uint32 + DwMask uint32 + WNumbering uint16 + WEffects uint16 + DxStartIndent int32 + DxRightIndent int32 + DxOffset int32 + WAlignment uint16 + CTabCount int16 + RgxTabs [MAX_TAB_STOPS]int32 +} + +type PARAFORMAT2 struct { + PARAFORMAT + DySpaceBefore int32 // Vertical spacing before para + DySpaceAfter int32 // Vertical spacing after para + DyLineSpacing int32 // Line spacing depending on Rule + SStyle int16 // Style handle + BLineSpacingRule byte // Rule for line spacing (see tom.doc) + BOutlineLevel byte // Outline level + WShadingWeight uint16 // Shading in hundredths of a per cent + WShadingStyle uint16 // Nibble 0: style, 1: cfpat, 2: cbpat + WNumberingStart uint16 // Starting value for numbering + WNumberingStyle uint16 // Alignment, roman/arabic, (), ), ., etc. + WNumberingTab uint16 // Space bet FirstIndent & 1st-line text + WBorderSpace uint16 // Border-text spaces (nbl/bdr in pts) + WBorderWidth uint16 // Pen widths (nbl/bdr in half pts) + WBorders uint16 // Border styles (nibble/border) +} + +const ( + // PARAFORMAT mask values + PFM_STARTINDENT = 0x00000001 + PFM_RIGHTINDENT = 0x00000002 + PFM_OFFSET = 0x00000004 + PFM_ALIGNMENT = 0x00000008 + PFM_TABSTOPS = 0x00000010 + PFM_NUMBERING = 0x00000020 + PFM_OFFSETINDENT = 0x80000000 + + // PARAFORMAT 2.0 masks and effects + PFM_SPACEBEFORE = 0x00000040 + PFM_SPACEAFTER = 0x00000080 + PFM_LINESPACING = 0x00000100 + PFM_STYLE = 0x00000400 + PFM_BORDER = 0x00000800 // (*) + PFM_SHADING = 0x00001000 // (*) + PFM_NUMBERINGSTYLE = 0x00002000 // RE 3.0 + PFM_NUMBERINGTAB = 0x00004000 // RE 3.0 + PFM_NUMBERINGSTART = 0x00008000 // RE 3.0 + + PFM_RTLPARA = 0x00010000 + PFM_KEEP = 0x00020000 // (*) + PFM_KEEPNEXT = 0x00040000 // (*) + PFM_PAGEBREAKBEFORE = 0x00080000 // (*) + PFM_NOLINENUMBER = 0x00100000 // (*) + PFM_NOWIDOWCONTROL = 0x00200000 // (*) + PFM_DONOTHYPHEN = 0x00400000 // (*) + PFM_SIDEBYSIDE = 0x00800000 // (*) + + // The following two paragraph-format properties are read only + PFM_COLLAPSED = 0x01000000 // RE 3.0 + PFM_OUTLINELEVEL = 0x02000000 // RE 3.0 + PFM_BOX = 0x04000000 // RE 3.0 + PFM_RESERVED2 = 0x08000000 // RE 4.0 + PFM_TABLEROWDELIMITER = 0x10000000 // RE 4.0 + PFM_TEXTWRAPPINGBREAK = 0x20000000 // RE 3.0 + PFM_TABLE = 0x40000000 // RE 3.0 + + // PARAFORMAT "ALL" masks + PFM_ALL = PFM_STARTINDENT | PFM_RIGHTINDENT | PFM_OFFSET | PFM_ALIGNMENT | PFM_TABSTOPS | PFM_NUMBERING | PFM_OFFSETINDENT | PFM_RTLPARA + + // Note: PARAFORMAT has no effects (BiDi RichEdit 1.0 does have PFE_RTLPARA) + PFM_EFFECTS = PFM_RTLPARA | PFM_KEEP | PFM_KEEPNEXT | PFM_TABLE | PFM_PAGEBREAKBEFORE | PFM_NOLINENUMBER | PFM_NOWIDOWCONTROL | PFM_DONOTHYPHEN | PFM_SIDEBYSIDE | PFM_TABLE | PFM_TABLEROWDELIMITER + + PFM_ALL2 = PFM_ALL | PFM_EFFECTS | PFM_SPACEBEFORE | PFM_SPACEAFTER | PFM_LINESPACING | PFM_STYLE | PFM_SHADING | PFM_BORDER | PFM_NUMBERINGTAB | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE + + PFE_RTLPARA = PFM_RTLPARA >> 16 + PFE_KEEP = PFM_KEEP >> 16 // (*) + PFE_KEEPNEXT = PFM_KEEPNEXT >> 16 // (*) + PFE_PAGEBREAKBEFORE = PFM_PAGEBREAKBEFORE >> 16 // (*) + PFE_NOLINENUMBER = PFM_NOLINENUMBER >> 16 // (*) + PFE_NOWIDOWCONTROL = PFM_NOWIDOWCONTROL >> 16 // (*) + PFE_DONOTHYPHEN = PFM_DONOTHYPHEN >> 16 // (*) + PFE_SIDEBYSIDE = PFM_SIDEBYSIDE >> 16 // (*) + PFE_TEXTWRAPPINGBREAK = PFM_TEXTWRAPPINGBREAK >> 16 // (*) + + // The following four effects are read only + PFE_COLLAPSED = PFM_COLLAPSED >> 16 // (+) + PFE_BOX = PFM_BOX >> 16 // (+) + PFE_TABLE = PFM_TABLE >> 16 // Inside table row. RE 3.0 + PFE_TABLEROWDELIMITER = PFM_TABLEROWDELIMITER >> 16 // Table row start. RE 4.0 + + // PARAFORMAT numbering options + PFN_BULLET = 1 // tomListBullet + + // PARAFORMAT2 wNumbering options + PFN_ARABIC = 2 // tomListNumberAsArabic: 0, 1, 2, ... + PFN_LCLETTER = 3 // tomListNumberAsLCLetter: a, b, c, ... + PFN_UCLETTER = 4 // tomListNumberAsUCLetter: A, B, C, ... + PFN_LCROMAN = 5 // tomListNumberAsLCRoman: i, ii, iii, ... + PFN_UCROMAN = 6 // tomListNumberAsUCRoman: I, II, III, ... + + // PARAFORMAT2 wNumberingStyle options + PFNS_PAREN = 0x000 // default, e.g., 1) + PFNS_PARENS = 0x100 // tomListParentheses/256, e.g., (1) + PFNS_PERIOD = 0x200 // tomListPeriod/256, e.g., 1. + PFNS_PLAIN = 0x300 // tomListPlain/256, e.g., 1 + PFNS_NONUMBER = 0x400 // Used for continuation w/o number + + PFNS_NEWNUMBER = 0x8000 // Start new number with wNumberingStart + // (can be combined with other PFNS_xxx) + // PARAFORMAT alignment options + PFA_LEFT = 1 + PFA_RIGHT = 2 + PFA_CENTER = 3 + + // PARAFORMAT2 alignment options + PFA_JUSTIFY = 4 // New paragraph-alignment option 2.0 (*) + PFA_FULL_INTERWORD = 4 // These are supported in 3.0 with advanced +) + +type MSGFILTER struct { + Nmhdr NMHDR + Msg uint32 + WParam uintptr + LParam uintptr +} + +type REQRESIZE struct { + Nmhdr NMHDR + Rc RECT +} + +type SELCHANGE struct { + Nmhdr NMHDR + Chrg CHARRANGE + Seltyp uint16 +} + +type GROUPTYPINGCHANGE struct { + Nmhdr NMHDR + FGroupTyping BOOL +} + +type CLIPBOARDFORMAT struct { + Nmhdr NMHDR + Cf CLIPFORMAT +} + +const ( + SEL_EMPTY = 0x0000 + SEL_TEXT = 0x0001 + SEL_OBJECT = 0x0002 + SEL_MULTICHAR = 0x0004 + SEL_MULTIOBJECT = 0x0008 +) + +const ( + // Used with IRichEditOleCallback::GetContextMenu, this flag will be passed as a "selection type". It indicates that a context menu for a right-mouse drag drop should be generated. The IOleObject parameter will really be the IDataObject for the drop + GCM_RIGHTMOUSEDROP = 0x8000 +) + +type GETCONTEXTMENUEX struct { + Chrg CHARRANGE + DwFlags uint32 + Pt POINT + PvReserved uintptr +} + +const ( + // bits for GETCONTEXTMENUEX::dwFlags + GCMF_GRIPPER = 0x00000001 + GCMF_SPELLING = 0x00000002 // pSpellingSuggestions is valid and points to the list of spelling suggestions + GCMF_TOUCHMENU = 0x00004000 + GCMF_MOUSEMENU = 0x00002000 +) + +type ENDROPFILES struct { + Nmhdr NMHDR + HDrop HANDLE + Cp int32 + FProtected BOOL +} + +type ENPROTECTED struct { + Nmhdr NMHDR + Msg uint32 + WParam uintptr + LParam uintptr + Chrg CHARRANGE +} + +type ENSAVECLIPBOARD struct { + Nmhdr NMHDR + CObjectCount int32 + Cch int32 +} + +type ENOLEOPFAILED struct { + Nmhdr NMHDR + Iob int32 + LOper int32 + Hr HRESULT +} + +const OLEOP_DOVERB = 1 + +type OBJECTPOSITIONS struct { + Nmhdr NMHDR + CObjectCount int32 + PcpPositions *int32 +} + +type ENLINK struct { + Nmhdr NMHDR + Msg uint32 + WParam uintptr + LParam uintptr + Chrg CHARRANGE +} + +type ENLOWFIRTF struct { + Nmhdr NMHDR + SzControl *byte +} + +// PenWin specific +type ENCORRECTTEXT struct { + Nmhdr NMHDR + Chrg CHARRANGE + Seltyp uint16 +} + +// East Asia specific +type PUNCTUATION struct { + ISize uint32 + SzPunctuation *byte +} + +// East Asia specific +type COMPCOLOR struct { + CrText COLORREF + CrBackground COLORREF + DwEffects uint32 +} + +const ( + // Clipboard formats - use as parameter to RegisterClipboardFormat() + CF_RTF = "Rich Text Format" + CF_RTFNOOBJS = "Rich Text Format Without Objects" + CF_RETEXTOBJ = "RichEdit Text and Objects" +) + +// Paste Special +type REPASTESPECIAL struct { + DwAspect uint32 + DwParam uintptr +} + +// UndoName info +type UNDONAMEID int32 + +const ( + UID_UNKNOWN UNDONAMEID = 0 + UID_TYPING = 1 + UID_DELETE = 2 + UID_DRAGDROP = 3 + UID_CUT = 4 + UID_PASTE = 5 + UID_AUTOTABLE = 6 +) + +const ( + // Flags for the SETEXTEX data structure + ST_DEFAULT = 0 + ST_KEEPUNDO = 1 + ST_SELECTION = 2 + ST_NEuint16S = 4 + ST_UNICODE = 8 +) + +// EM_SETTEXTEX info; this struct is passed in the wparam of the message +type SETTEXTEX struct { + Flags uint32 // Flags (see the ST_XXX defines) + Codepage uint32 // Code page for translation (CP_ACP for sys default, 1200 for Unicode, -1 for control default) +} + +const ( + // Flags for the GETEXTEX data structure + GT_DEFAULT = 0 + GT_USECRLF = 1 + GT_SELECTION = 2 + GT_RAWTEXT = 4 + GT_NOHIDDENTEXT = 8 +) + +// EM_GETTEXTEX info; this struct is passed in the wparam of the message +type GETTEXTEX struct { + Cb uint32 // Count of bytes in the string + Flags uint32 // Flags (see the GT_XXX defines + Codepage uint32 // Code page for translation (CP_ACP for sys default, 1200 for Unicode, -1 for control default) + LpDefaultChar *byte // Replacement for unmappable chars + LpUsedDefChar *BOOL // Pointer to flag set when def char used +} + +const ( + // Flags for the GETTEXTLENGTHEX data structure + GTL_DEFAULT = 0 // Do default (return # of chars) + GTL_USECRLF = 1 // Compute answer using CRLFs for paragraphs + GTL_PRECISE = 2 // Compute a precise answer + GTL_CLOSE = 4 // Fast computation of a "close" answer + GTL_NUMCHARS = 8 // Return number of characters + GTL_NUMBYTES = 16 // Return number of _bytes_ +) + +// EM_GETTEXTLENGTHEX info; this struct is passed in the wparam of the msg +type GETTEXTLENGTHEX struct { + Flags uint32 // Flags (see GTL_XXX defines) + Codepage uint32 // Code page for translation (CP_ACP for default, 1200 for Unicode) +} + +// BiDi specific features +type BIDIOPTIONS struct { + CbSize uint32 + WMask uint16 + WEffects uint16 +} + +const ( + // BIDIOPTIONS masks + BOM_NEUTRALOVERRIDE = 0x0004 // Override neutral layout (obsolete) + BOM_CONTEXTREADING = 0x0008 // Context reading order + BOM_CONTEXTALIGNMENT = 0x0010 // Context alignment + BOM_LEGACYBIDICLASS = 0x0040 // Legacy Bidi classification (obsolete) + BOM_UNICODEBIDI = 0x0080 // Use Unicode BiDi algorithm + + // BIDIOPTIONS effects + BOE_NEUTRALOVERRIDE = 0x0004 // Override neutral layout (obsolete) + BOE_CONTEXTREADING = 0x0008 // Context reading order + BOE_CONTEXTALIGNMENT = 0x0010 // Context alignment + BOE_FORCERECALC = 0x0020 // Force recalc and redraw + BOE_LEGACYBIDICLASS = 0x0040 // Legacy Bidi classification (obsolete) + BOE_UNICODEBIDI = 0x0080 // Use Unicode BiDi algorithm + + // Additional EM_FINDTEXT[EX] flags + FR_MATCHDIAC = 0x20000000 + FR_MATCHKASHIDA = 0x40000000 + FR_MATCHALEFHAMZA = 0x80000000 + + // UNICODE embedding character + WCH_EMBEDDING uint16 = 0xFFFC +) + +// khyph - Kind of hyphenation +type KHYPH int32 + +const ( + KhyphNil KHYPH = iota // No Hyphenation + KhyphNormal // Normal Hyphenation + KhyphAddBefore // Add letter before hyphen + KhyphChangeBefore // Change letter before hyphen + KhyphDeleteBefore // Delete letter before hyphen + KhyphChangeAfter // Change letter after hyphen + KhyphDelAndChange // Delete letter before hyphen and change letter preceding hyphen +) + +type HYPHRESULT struct { + Khyph KHYPH // Kind of hyphenation + IchHyph int32 // Character which was hyphenated + ChHyph uint16 // Depending on hyphenation type, character added, changed, etc. +} + +type HYPHENATEINFO struct { + CbSize int16 // Size of HYPHENATEINFO structure + DxHyphenateZone int16 // If a space character is closer to the margin than this value, don't hyphenate (in TWIPs) + PfnHyphenate uintptr +} + +const ( + // Additional class for Richedit 6.0 + RICHEDIT60_CLASS = "RICHEDIT60W" +) diff --git a/richole.go b/richole.go new file mode 100644 index 00000000..e1e3fa65 --- /dev/null +++ b/richole.go @@ -0,0 +1,213 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +import ( + "syscall" + "unsafe" +) + +type REOBJECT struct { + cbStruct uint32 // Size of structure + cp int32 // Character position of object + clsid CLSID // Class ID of object + poleobj *IOleObject // OLE object interface + pstg *IStorage // Associated storage interface + polesite *IOleClientSite // Associated client site interface + sizel SIZE // Size of object (may be 0,0) + dvaspect uint32 // Display aspect to use + dwFlags uint32 // Object status flags + dwUser uint32 // Dword for user's use +} + +type IRichEditOleVtbl struct { + IUnknownVtbl + GetClientSite uintptr + GetObjectCount uintptr + GetLinkCount uintptr + GetObject uintptr + InsertObject uintptr + ConvertObject uintptr + ActivateAs uintptr + SetHostNames uintptr + SetLinkAvailable uintptr + SetDvaspect uintptr + HandsOffStorage uintptr + SaveCompleted uintptr + InPlaceDeactivate uintptr + ContextSensitiveHelp uintptr + GetClipboardData uintptr + ImportDataObject uintptr +} + +type IRichEditOle struct { + LpVtbl *IRichEditOleVtbl +} + +func (obj *IRichEditOle) QueryInterface(riid REFIID, ppvObject *unsafe.Pointer) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.QueryInterface, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(ppvObject))) + return HRESULT(ret) +} + +func (obj *IRichEditOle) AddRef() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.AddRef, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *IRichEditOle) Release() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Release, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *IRichEditOle) GetClientSite(lplpolesite **IOleClientSite) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetClientSite, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(lplpolesite)), + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) GetObjectCount() int32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetObjectCount, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return int32(ret) +} + +func (obj *IRichEditOle) GetLinkCount() int32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetLinkCount, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return int32(ret) +} + +func (obj *IRichEditOle) GetObject(iob int32, lpreobject *REOBJECT, dwFlags uint32) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.GetObject, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + uintptr(unsafe.Pointer(lpreobject)), + uintptr(dwFlags), + 0, + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) InsertObject(lpreobject *REOBJECT) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.InsertObject, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(lpreobject)), + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) ConvertObject(iob int32, rclsidNew REFCLSID, lpstrUserTypeNew *byte) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ConvertObject, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + uintptr(unsafe.Pointer(rclsidNew)), + uintptr(unsafe.Pointer(lpstrUserTypeNew)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) ActivateAs(rclsid REFCLSID, rclsidAs REFCLSID) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.ActivateAs, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(rclsid)), + uintptr(unsafe.Pointer(rclsidAs))) + return HRESULT(ret) +} + +func (obj *IRichEditOle) SetHostNames(lpstrContainerApp *byte, lpstrContainerObj *byte) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SetHostNames, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(lpstrContainerApp)), + uintptr(unsafe.Pointer(lpstrContainerObj))) + return HRESULT(ret) +} + +func (obj *IRichEditOle) SetLinkAvailable(iob int32, fAvailable BOOL) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SetLinkAvailable, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + uintptr(fAvailable)) + return HRESULT(ret) +} + +func (obj *IRichEditOle) SetDvaspect(iob int32, dvaspect uint32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SetDvaspect, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + uintptr(dvaspect)) + return HRESULT(ret) +} + +func (obj *IRichEditOle) HandsOffStorage(iob int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.HandsOffStorage, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) SaveCompleted(iob int32, lpstg *IStorage) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SaveCompleted, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(iob), + uintptr(unsafe.Pointer(lpstg))) + return HRESULT(ret) +} + +func (obj *IRichEditOle) InPlaceDeactivate() HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.InPlaceDeactivate, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) ContextSensitiveHelp(fEnterMode BOOL) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.ContextSensitiveHelp, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(fEnterMode), + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) GetClipboardData(lpchrg *CHARRANGE, reco uint32, lplpdataobj **IDataObject) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.GetClipboardData, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(lpchrg)), + uintptr(reco), + uintptr(unsafe.Pointer(lplpdataobj)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *IRichEditOle) ImportDataObject(lpdataobj *IDataObject, cf CLIPFORMAT, hMetaPict HGLOBAL) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.ImportDataObject, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(lpdataobj)), + uintptr(cf), + uintptr(hMetaPict), + 0, + 0) + return HRESULT(ret) +} diff --git a/shdocvw.go b/shdocvw.go index e8004ba1..6d1e81a5 100644 --- a/shdocvw.go +++ b/shdocvw.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( @@ -64,10 +66,11 @@ const ( ) var ( - CLSID_WebBrowser = CLSID{0x8856F961, 0x340A, 0x11D0, [8]byte{0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2}} - DIID_DWebBrowserEvents2 = IID{0x34A715A0, 0x6587, 0x11D0, [8]byte{0x92, 0x4A, 0x00, 0x20, 0xAF, 0xC7, 0xAC, 0x4D}} - IID_IWebBrowser2 = IID{0xD30C1661, 0xCDAF, 0x11D0, [8]byte{0x8A, 0x3E, 0x00, 0xC0, 0x4F, 0xC9, 0xE2, 0x6E}} - IID_IDocHostUIHandler = IID{0xBD3F23C0, 0xD43E, 0x11CF, [8]byte{0x89, 0x3B, 0x00, 0xAA, 0x00, 0xBD, 0xCE, 0x1A}} + CLSID_WebBrowser = CLSID{0x8856F961, 0x340A, 0x11D0, [8]byte{0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2}} + DIID_DWebBrowserEvents2 = IID{0x34A715A0, 0x6587, 0x11D0, [8]byte{0x92, 0x4A, 0x00, 0x20, 0xAF, 0xC7, 0xAC, 0x4D}} + IID_IWebBrowser2 = IID{0xD30C1661, 0xCDAF, 0x11D0, [8]byte{0x8A, 0x3E, 0x00, 0xC0, 0x4F, 0xC9, 0xE2, 0x6E}} + IID_IDocHostUIHandler = IID{0xBD3F23C0, 0xD43E, 0x11CF, [8]byte{0x89, 0x3B, 0x00, 0xAA, 0x00, 0xBD, 0xCE, 0x1A}} + IID_IOleInPlaceActiveObject = IID{0x00000117, 0x0000, 0x0000, [8]byte{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}} ) type DWebBrowserEvents2Vtbl struct { @@ -162,6 +165,15 @@ type IWebBrowser2 struct { LpVtbl *IWebBrowser2Vtbl } +func (wb2 *IWebBrowser2) QueryInterface(riid REFIID, ppvObject *unsafe.Pointer) HRESULT { + ret, _, _ := syscall.Syscall(wb2.LpVtbl.QueryInterface, 3, + uintptr(unsafe.Pointer(wb2)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(ppvObject))) + + return HRESULT(ret) +} + func (wb2 *IWebBrowser2) Release() HRESULT { ret, _, _ := syscall.Syscall(wb2.LpVtbl.Release, 1, uintptr(unsafe.Pointer(wb2)), @@ -269,3 +281,47 @@ type DOCHOSTUIINFO struct { PchHostCss *uint16 PchHostNS *uint16 } + +type IOleInPlaceActiveObjectVtbl struct { + QueryInterface uintptr + AddRef uintptr + Release uintptr + GetWindow uintptr + ContextSensitiveHelp uintptr + TranslateAccelerator uintptr + OnFrameWindowActivate uintptr + OnDocWindowActivate uintptr + ResizeBorder uintptr + EnableModeless uintptr +} + +type IOleInPlaceActiveObject struct { + LpVtbl *IOleInPlaceActiveObjectVtbl +} + +func (activeObj *IOleInPlaceActiveObject) Release() HRESULT { + ret, _, _ := syscall.Syscall(activeObj.LpVtbl.Release, 1, + uintptr(unsafe.Pointer(activeObj)), + 0, + 0) + + return HRESULT(ret) +} + +func (activeObj *IOleInPlaceActiveObject) GetWindow(hWndPtr *HWND) HRESULT { + ret, _, _ := syscall.Syscall(activeObj.LpVtbl.GetWindow, 2, + uintptr(unsafe.Pointer(activeObj)), + uintptr(unsafe.Pointer(hWndPtr)), + 0) + + return HRESULT(ret) +} + +func (activeObj *IOleInPlaceActiveObject) TranslateAccelerator(msg *MSG) HRESULT { + ret, _, _ := syscall.Syscall(activeObj.LpVtbl.TranslateAccelerator, 2, + uintptr(unsafe.Pointer(activeObj)), + uintptr(unsafe.Pointer(msg)), + 0) + + return HRESULT(ret) +} diff --git a/shell32.go b/shell32.go index f51c3845..8c683aec 100644 --- a/shell32.go +++ b/shell32.go @@ -2,14 +2,18 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) type CSIDL uint32 +type HDROP HANDLE const ( CSIDL_DESKTOP = 0x00 @@ -78,11 +82,14 @@ const ( // NotifyIcon flags const ( - NIF_MESSAGE = 0x00000001 - NIF_ICON = 0x00000002 - NIF_TIP = 0x00000004 - NIF_STATE = 0x00000008 - NIF_INFO = 0x00000010 + NIF_MESSAGE = 0x00000001 + NIF_ICON = 0x00000002 + NIF_TIP = 0x00000004 + NIF_STATE = 0x00000008 + NIF_INFO = 0x00000010 + NIF_GUID = 0x00000020 + NIF_REALTIME = 0x00000040 + NIF_SHOWTIP = 0x00000080 ) // NotifyIcon messages @@ -102,15 +109,33 @@ const ( // NotifyIcon info flags const ( - NIIF_NONE = 0x00000000 - NIIF_INFO = 0x00000001 - NIIF_WARNING = 0x00000002 - NIIF_ERROR = 0x00000003 - NIIF_USER = 0x00000004 - NIIF_NOSOUND = 0x00000010 + NIIF_NONE = 0x00000000 + NIIF_INFO = 0x00000001 + NIIF_WARNING = 0x00000002 + NIIF_ERROR = 0x00000003 + NIIF_USER = 0x00000004 + NIIF_NOSOUND = 0x00000010 + NIIF_LARGE_ICON = 0x00000020 + NIIF_RESPECT_QUIET_TIME = 0x00000080 ) -const NOTIFYICON_VERSION = 3 +// NotifyIcon notifications +const ( + NIN_SELECT = WM_USER + 0 + NIN_KEYSELECT = WM_USER + 1 + NIN_BALLOONSHOW = WM_USER + 2 + NIN_BALLOONHIDE = WM_USER + 3 + NIN_BALLOONTIMEOUT = WM_USER + 4 + NIN_BALLOONUSERCLICK = WM_USER + 5 + NIN_POPUPOPEN = WM_USER + 6 + NIN_POPUPCLOSE = WM_USER + 7 +) + +// NotifyIcon versions +const ( + NOTIFYICON_VERSION = 3 + NOTIFYICON_VERSION_4 = 4 +) // SHGetFileInfo flags const ( @@ -134,6 +159,116 @@ const ( SHGFI_ATTR_SPECIFIED = 0x000020000 ) +// SHGetStockIconInfo flags +const ( + SHGSI_ICONLOCATION = 0 + SHGSI_ICON = 0x000000100 + SHGSI_SYSICONINDEX = 0x000004000 + SHGSI_LINKOVERLAY = 0x000008000 + SHGSI_SELECTED = 0x000010000 + SHGSI_LARGEICON = 0x000000000 + SHGSI_SMALLICON = 0x000000001 + SHGSI_SHELLICONSIZE = 0x000000004 +) + +// SHSTOCKICONID values +const ( + SIID_DOCNOASSOC = 0 + SIID_DOCASSOC = 1 + SIID_APPLICATION = 2 + SIID_FOLDER = 3 + SIID_FOLDEROPEN = 4 + SIID_DRIVE525 = 5 + SIID_DRIVE35 = 6 + SIID_DRIVEREMOVE = 7 + SIID_DRIVEFIXED = 8 + SIID_DRIVENET = 9 + SIID_DRIVENETDISABLED = 10 + SIID_DRIVECD = 11 + SIID_DRIVERAM = 12 + SIID_WORLD = 13 + SIID_SERVER = 15 + SIID_PRINTER = 16 + SIID_MYNETWORK = 17 + SIID_FIND = 22 + SIID_HELP = 23 + SIID_SHARE = 28 + SIID_LINK = 29 + SIID_SLOWFILE = 30 + SIID_RECYCLER = 31 + SIID_RECYCLERFULL = 32 + SIID_MEDIACDAUDIO = 40 + SIID_LOCK = 47 + SIID_AUTOLIST = 49 + SIID_PRINTERNET = 50 + SIID_SERVERSHARE = 51 + SIID_PRINTERFAX = 52 + SIID_PRINTERFAXNET = 53 + SIID_PRINTERFILE = 54 + SIID_STACK = 55 + SIID_MEDIASVCD = 56 + SIID_STUFFEDFOLDER = 57 + SIID_DRIVEUNKNOWN = 58 + SIID_DRIVEDVD = 59 + SIID_MEDIADVD = 60 + SIID_MEDIADVDRAM = 61 + SIID_MEDIADVDRW = 62 + SIID_MEDIADVDR = 63 + SIID_MEDIADVDROM = 64 + SIID_MEDIACDAUDIOPLUS = 65 + SIID_MEDIACDRW = 66 + SIID_MEDIACDR = 67 + SIID_MEDIACDBURN = 68 + SIID_MEDIABLANKCD = 69 + SIID_MEDIACDROM = 70 + SIID_AUDIOFILES = 71 + SIID_IMAGEFILES = 72 + SIID_VIDEOFILES = 73 + SIID_MIXEDFILES = 74 + SIID_FOLDERBACK = 75 + SIID_FOLDERFRONT = 76 + SIID_SHIELD = 77 + SIID_WARNING = 78 + SIID_INFO = 79 + SIID_ERROR = 80 + SIID_KEY = 81 + SIID_SOFTWARE = 82 + SIID_RENAME = 83 + SIID_DELETE = 84 + SIID_MEDIAAUDIODVD = 85 + SIID_MEDIAMOVIEDVD = 86 + SIID_MEDIAENHANCEDCD = 87 + SIID_MEDIAENHANCEDDVD = 88 + SIID_MEDIAHDDVD = 89 + SIID_MEDIABLURAY = 90 + SIID_MEDIAVCD = 91 + SIID_MEDIADVDPLUSR = 92 + SIID_MEDIADVDPLUSRW = 93 + SIID_DESKTOPPC = 94 + SIID_MOBILEPC = 95 + SIID_USERS = 96 + SIID_MEDIASMARTMEDIA = 97 + SIID_MEDIACOMPACTFLASH = 98 + SIID_DEVICECELLPHONE = 99 + SIID_DEVICECAMERA = 100 + SIID_DEVICEVIDEOCAMERA = 101 + SIID_DEVICEAUDIOPLAYER = 102 + SIID_NETWORKCONNECT = 103 + SIID_INTERNET = 104 + SIID_ZIPFILE = 105 + SIID_SETTINGS = 106 + SIID_DRIVEHDDVD = 132 + SIID_DRIVEBD = 133 + SIID_MEDIAHDDVDROM = 134 + SIID_MEDIAHDDVDR = 135 + SIID_MEDIAHDDVDRAM = 136 + SIID_MEDIABDROM = 137 + SIID_MEDIABDR = 138 + SIID_MEDIABDRE = 139 + SIID_CLUSTEREDDRIVE = 140 + SIID_MAX_ICONS = 175 +) + type NOTIFYICONDATA struct { CbSize uint32 HWnd HWND @@ -148,7 +283,8 @@ type NOTIFYICONDATA struct { UVersion uint32 SzInfoTitle [64]uint16 DwInfoFlags uint32 - GuidItem GUID + GuidItem syscall.GUID + HBalloonIcon HICON } type SHFILEINFO struct { @@ -170,32 +306,93 @@ type BROWSEINFO struct { IImage int32 } +type SHSTOCKICONINFO struct { + CbSize uint32 + HIcon HICON + ISysImageIndex int32 + IIcon int32 + SzPath [MAX_PATH]uint16 +} + var ( // Library - libshell32 uintptr + libshell32 *windows.LazyDLL // Functions - shBrowseForFolder uintptr - shGetFileInfo uintptr - shGetPathFromIDList uintptr - shGetSpecialFolderPath uintptr - shell_NotifyIcon uintptr + dragAcceptFiles *windows.LazyProc + dragFinish *windows.LazyProc + dragQueryFile *windows.LazyProc + extractIcon *windows.LazyProc + shBrowseForFolder *windows.LazyProc + shDefExtractIcon *windows.LazyProc + shGetFileInfo *windows.LazyProc + shGetPathFromIDList *windows.LazyProc + shGetSpecialFolderPath *windows.LazyProc + shParseDisplayName *windows.LazyProc + shGetStockIconInfo *windows.LazyProc + shellExecute *windows.LazyProc + shell_NotifyIcon *windows.LazyProc ) func init() { // Library - libshell32 = MustLoadLibrary("shell32.dll") + libshell32 = windows.NewLazySystemDLL("shell32.dll") // Functions - shBrowseForFolder = MustGetProcAddress(libshell32, "SHBrowseForFolderW") - shGetFileInfo = MustGetProcAddress(libshell32, "SHGetFileInfoW") - shGetPathFromIDList = MustGetProcAddress(libshell32, "SHGetPathFromIDListW") - shGetSpecialFolderPath = MustGetProcAddress(libshell32, "SHGetSpecialFolderPathW") - shell_NotifyIcon = MustGetProcAddress(libshell32, "Shell_NotifyIconW") + dragAcceptFiles = libshell32.NewProc("DragAcceptFiles") + dragFinish = libshell32.NewProc("DragFinish") + dragQueryFile = libshell32.NewProc("DragQueryFileW") + extractIcon = libshell32.NewProc("ExtractIconW") + shBrowseForFolder = libshell32.NewProc("SHBrowseForFolderW") + shDefExtractIcon = libshell32.NewProc("SHDefExtractIconW") + shGetFileInfo = libshell32.NewProc("SHGetFileInfoW") + shGetPathFromIDList = libshell32.NewProc("SHGetPathFromIDListW") + shGetSpecialFolderPath = libshell32.NewProc("SHGetSpecialFolderPathW") + shGetStockIconInfo = libshell32.NewProc("SHGetStockIconInfo") + shellExecute = libshell32.NewProc("ShellExecuteW") + shell_NotifyIcon = libshell32.NewProc("Shell_NotifyIconW") + shParseDisplayName = libshell32.NewProc("SHParseDisplayName") +} + +func DragAcceptFiles(hWnd HWND, fAccept bool) bool { + ret, _, _ := syscall.Syscall(dragAcceptFiles.Addr(), 2, + uintptr(hWnd), + uintptr(BoolToBOOL(fAccept)), + 0) + + return ret != 0 +} + +func DragQueryFile(hDrop HDROP, iFile uint, lpszFile *uint16, cch uint) uint { + ret, _, _ := syscall.Syscall6(dragQueryFile.Addr(), 4, + uintptr(hDrop), + uintptr(iFile), + uintptr(unsafe.Pointer(lpszFile)), + uintptr(cch), + 0, + 0) + + return uint(ret) +} + +func DragFinish(hDrop HDROP) { + syscall.Syscall(dragAcceptFiles.Addr(), 1, + uintptr(hDrop), + 0, + 0) +} + +func ExtractIcon(hInst HINSTANCE, exeFileName *uint16, iconIndex int32) HICON { + ret, _, _ := syscall.Syscall(extractIcon.Addr(), 3, + uintptr(hInst), + uintptr(unsafe.Pointer(exeFileName)), + uintptr(iconIndex)) + + return HICON(ret) } func SHBrowseForFolder(lpbi *BROWSEINFO) uintptr { - ret, _, _ := syscall.Syscall(shBrowseForFolder, 1, + ret, _, _ := syscall.Syscall(shBrowseForFolder.Addr(), 1, uintptr(unsafe.Pointer(lpbi)), 0, 0) @@ -203,8 +400,20 @@ func SHBrowseForFolder(lpbi *BROWSEINFO) uintptr { return ret } +func SHDefExtractIcon(pszIconFile *uint16, iIndex int32, uFlags uint32, phiconLarge, phiconSmall *HICON, nIconSize uint32) HRESULT { + ret, _, _ := syscall.Syscall6(shDefExtractIcon.Addr(), 6, + uintptr(unsafe.Pointer(pszIconFile)), + uintptr(iIndex), + uintptr(uFlags), + uintptr(unsafe.Pointer(phiconLarge)), + uintptr(unsafe.Pointer(phiconSmall)), + uintptr(nIconSize)) + + return HRESULT(ret) +} + func SHGetFileInfo(pszPath *uint16, dwFileAttributes uint32, psfi *SHFILEINFO, cbFileInfo, uFlags uint32) uintptr { - ret, _, _ := syscall.Syscall6(shGetFileInfo, 5, + ret, _, _ := syscall.Syscall6(shGetFileInfo.Addr(), 5, uintptr(unsafe.Pointer(pszPath)), uintptr(dwFileAttributes), uintptr(unsafe.Pointer(psfi)), @@ -216,7 +425,7 @@ func SHGetFileInfo(pszPath *uint16, dwFileAttributes uint32, psfi *SHFILEINFO, c } func SHGetPathFromIDList(pidl uintptr, pszPath *uint16) bool { - ret, _, _ := syscall.Syscall(shGetPathFromIDList, 2, + ret, _, _ := syscall.Syscall(shGetPathFromIDList.Addr(), 2, pidl, uintptr(unsafe.Pointer(pszPath)), 0) @@ -225,7 +434,7 @@ func SHGetPathFromIDList(pidl uintptr, pszPath *uint16) bool { } func SHGetSpecialFolderPath(hwndOwner HWND, lpszPath *uint16, csidl CSIDL, fCreate bool) bool { - ret, _, _ := syscall.Syscall6(shGetSpecialFolderPath, 4, + ret, _, _ := syscall.Syscall6(shGetSpecialFolderPath.Addr(), 4, uintptr(hwndOwner), uintptr(unsafe.Pointer(lpszPath)), uintptr(csidl), @@ -236,8 +445,47 @@ func SHGetSpecialFolderPath(hwndOwner HWND, lpszPath *uint16, csidl CSIDL, fCrea return ret != 0 } +func SHParseDisplayName(pszName *uint16, pbc uintptr, ppidl *uintptr, sfgaoIn uint32, psfgaoOut *uint32) HRESULT { + ret, _, _ := syscall.Syscall6(shParseDisplayName.Addr(), 5, + uintptr(unsafe.Pointer(pszName)), + pbc, + uintptr(unsafe.Pointer(ppidl)), + 0, + uintptr(unsafe.Pointer(psfgaoOut)), + 0) + + return HRESULT(ret) +} + +func SHGetStockIconInfo(stockIconId int32, uFlags uint32, stockIcon *SHSTOCKICONINFO) HRESULT { + if shGetStockIconInfo.Find() != nil { + return HRESULT(0) + } + ret, _, _ := syscall.Syscall6(shGetStockIconInfo.Addr(), 3, + uintptr(stockIconId), + uintptr(uFlags), + uintptr(unsafe.Pointer(stockIcon)), + 0, + 0, + 0, + ) + return HRESULT(ret) +} + +func ShellExecute(hWnd HWND, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int) bool { + ret, _, _ := syscall.Syscall6(shellExecute.Addr(), 6, + uintptr(hWnd), + uintptr(unsafe.Pointer(verb)), + uintptr(unsafe.Pointer(file)), + uintptr(unsafe.Pointer(args)), + uintptr(unsafe.Pointer(cwd)), + uintptr(showCmd), + ) + return ret != 0 +} + func Shell_NotifyIcon(dwMessage uint32, lpdata *NOTIFYICONDATA) bool { - ret, _, _ := syscall.Syscall(shell_NotifyIcon, 2, + ret, _, _ := syscall.Syscall(shell_NotifyIcon.Addr(), 2, uintptr(dwMessage), uintptr(unsafe.Pointer(lpdata)), 0) diff --git a/shobj.go b/shobj.go index c9392a46..656e02d2 100644 --- a/shobj.go +++ b/shobj.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( @@ -58,3 +60,14 @@ func (obj *ITaskbarList3) SetProgressState(hwnd HWND, state int) HRESULT { uintptr(state)) return HRESULT(ret) } + +func (obj *ITaskbarList3) SetOverlayIcon(hwnd HWND, icon HICON, description *uint16) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.SetOverlayIcon, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(hwnd), + uintptr(icon), + uintptr(unsafe.Pointer(description)), + 0, + 0) + return HRESULT(ret) +} diff --git a/shobj_386.go b/shobj_32.go similarity index 93% rename from shobj_386.go rename to shobj_32.go index 6c5e9c35..a5a5c289 100644 --- a/shobj_386.go +++ b/shobj_32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows,386 windows,arm + package win import ( diff --git a/shobj_amd64.go b/shobj_64.go similarity index 92% rename from shobj_amd64.go rename to shobj_64.go index f33d9c14..6e75ffd4 100644 --- a/shobj_amd64.go +++ b/shobj_64.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows,amd64 windows,arm64 + package win import ( diff --git a/statusbar.go b/statusbar.go index be694ca3..41b7067c 100644 --- a/statusbar.go +++ b/statusbar.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // Styles diff --git a/syslink.go b/syslink.go new file mode 100644 index 00000000..26455d0a --- /dev/null +++ b/syslink.go @@ -0,0 +1,65 @@ +// Copyright 2017 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +const ( + INVALID_LINK_INDEX = -1 + MAX_LINKID_TEXT = 48 + L_MAX_URL_LENGTH = 2048 + 32 + len("://") + WC_LINK = "SysLink" +) + +const ( + LWS_TRANSPARENT = 0x0001 + LWS_IGNORERETURN = 0x0002 + LWS_NOPREFIX = 0x0004 + LWS_USEVISUALSTYLE = 0x0008 + LWS_USECUSTOMTEXT = 0x0010 + LWS_RIGHT = 0x0020 +) + +const ( + LIF_ITEMINDEX = 0x00000001 + LIF_STATE = 0x00000002 + LIF_ITEMID = 0x00000004 + LIF_URL = 0x00000008 +) + +const ( + LIS_FOCUSED = 0x00000001 + LIS_ENABLED = 0x00000002 + LIS_VISITED = 0x00000004 + LIS_HOTTRACK = 0x00000008 + LIS_DEFAULTCOLORS = 0x00000010 +) + +const ( + LM_HITTEST = WM_USER + 0x300 + LM_GETIDEALHEIGHT = WM_USER + 0x301 + LM_SETITEM = WM_USER + 0x302 + LM_GETITEM = WM_USER + 0x303 + LM_GETIDEALSIZE = LM_GETIDEALHEIGHT +) + +type LITEM struct { + Mask uint32 + ILink int32 + State uint32 + StateMask uint32 + SzID [MAX_LINKID_TEXT]uint16 + SzUrl [L_MAX_URL_LENGTH]uint16 +} + +type LHITTESTINFO struct { + Pt POINT + Item LITEM +} + +type NMLINK struct { + Hdr NMHDR + Item LITEM +} diff --git a/tab.go b/tab.go index 400223eb..10dbd3de 100644 --- a/tab.go +++ b/tab.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win const TCM_FIRST = 0x1300 diff --git a/tom.go b/tom.go new file mode 100644 index 00000000..7587c2fb --- /dev/null +++ b/tom.go @@ -0,0 +1,989 @@ +// Copyright 2011 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +import ( + "syscall" + "unsafe" +) + +type TomConstants uint32 + +const ( + TomFalse TomConstants = 0 + TomTrue = -1 + TomUndefined = -9999999 + TomToggle = -9999998 + TomAutoColor = -9999997 + TomDefault = -9999996 + TomSuspend = -9999995 + TomResume = -9999994 + TomApplyNow = 0 + TomApplyLater = 1 + TomTrackParms = 2 + TomCacheParms = 3 + TomApplyTmp = 4 + TomDisableSmartFont = 8 + TomEnableSmartFont = 9 + TomUsePoints = 10 + TomUseTwips = 11 + TomBackward = 0xc0000001 + TomForward = 0x3fffffff + TomMove = 0 + TomExtend = 1 + TomNoSelection = 0 + TomSelectionIP = 1 + TomSelectionNormal = 2 + TomSelectionFrame = 3 + TomSelectionColumn = 4 + TomSelectionRow = 5 + TomSelectionBlock = 6 + TomSelectionInlineShape = 7 + TomSelectionShape = 8 + TomSelStartActive = 1 + TomSelAtEOL = 2 + TomSelOvertype = 4 + TomSelActive = 8 + TomSelReplace = 16 + TomEnd = 0 + TomStart = 32 + TomCollapseEnd = 0 + TomCollapseStart = 1 + TomClientCoord = 256 + TomAllowOffClient = 512 + TomTransform = 1024 + TomObjectArg = 2048 + TomAtEnd = 4096 + TomNone = 0 + TomSingle = 1 + TomWords = 2 + TomDouble = 3 + TomDotted = 4 + TomDash = 5 + TomDashDot = 6 + TomDashDotDot = 7 + TomWave = 8 + TomThick = 9 + TomHair = 10 + TomDoubleWave = 11 + TomHeavyWave = 12 + TomLongDash = 13 + TomThickDash = 14 + TomThickDashDot = 15 + TomThickDashDotDot = 16 + TomThickDotted = 17 + TomThickLongDash = 18 + TomLineSpaceSingle = 0 + TomLineSpace1pt5 = 1 + TomLineSpaceDouble = 2 + TomLineSpaceAtLeast = 3 + TomLineSpaceExactly = 4 + TomLineSpaceMultiple = 5 + TomLineSpacePercent = 6 + TomAlignLeft = 0 + TomAlignCenter = 1 + TomAlignRight = 2 + TomAlignJustify = 3 + TomAlignDecimal = 3 + TomAlignBar = 4 + TomDefaultTab = 5 + TomAlignInterWord = 3 + TomAlignNewspaper = 4 + TomAlignInterLetter = 5 + TomAlignScaled = 6 + TomSpaces = 0 + TomDots = 1 + TomDashes = 2 + TomLines = 3 + TomThickLines = 4 + TomEquals = 5 + TomTabBack = -3 + TomTabNext = -2 + TomTabHere = -1 + TomListNone = 0 + TomListBullet = 1 + TomListNumberAsArabic = 2 + TomListNumberAsLCLetter = 3 + TomListNumberAsUCLetter = 4 + TomListNumberAsLCRoman = 5 + TomListNumberAsUCRoman = 6 + TomListNumberAsSequence = 7 + TomListNumberedCircle = 8 + TomListNumberedBlackCircleWingding = 9 + TomListNumberedWhiteCircleWingding = 10 + TomListNumberedArabicWide = 11 + TomListNumberedChS = 12 + TomListNumberedChT = 13 + TomListNumberedJpnChS = 14 + TomListNumberedJpnKor = 15 + TomListNumberedArabic1 = 16 + TomListNumberedArabic2 = 17 + TomListNumberedHebrew = 18 + TomListNumberedThaiAlpha = 19 + TomListNumberedThaiNum = 20 + TomListNumberedHindiAlpha = 21 + TomListNumberedHindiAlpha1 = 22 + TomListNumberedHindiNum = 23 + TomListParentheses = 0x10000 + TomListPeriod = 0x20000 + TomListPlain = 0x30000 + TomListNoNumber = 0x40000 + TomListMinus = 0x80000 + TomIgnoreNumberStyle = 0x1000000 + TomParaStyleNormal = -1 + TomParaStyleHeading1 = -2 + TomParaStyleHeading2 = -3 + TomParaStyleHeading3 = -4 + TomParaStyleHeading4 = -5 + TomParaStyleHeading5 = -6 + TomParaStyleHeading6 = -7 + TomParaStyleHeading7 = -8 + TomParaStyleHeading8 = -9 + TomParaStyleHeading9 = -10 + TomCharacter = 1 + TomWord = 2 + TomSentence = 3 + TomParagraph = 4 + TomLine = 5 + TomStory = 6 + TomScreen = 7 + TomSection = 8 + TomTableColumn = 9 + TomColumn = 9 + TomRow = 10 + TomWindow = 11 + TomCell = 12 + TomCharFormat = 13 + TomParaFormat = 14 + TomTable = 15 + TomObject = 16 + TomPage = 17 + TomHardParagraph = 18 + TomCluster = 19 + TomInlineObject = 20 + TomInlineObjectArg = 21 + TomLeafLine = 22 + TomLayoutColumn = 23 + TomProcessId = 0x40000001 + TomMatchWord = 2 + TomMatchCase = 4 + TomMatchPattern = 8 + TomUnknownStory = 0 + TomMainTextStory = 1 + TomFootnotesStory = 2 + TomEndnotesStory = 3 + TomCommentsStory = 4 + TomTextFrameStory = 5 + TomEvenPagesHeaderStory = 6 + TomPrimaryHeaderStory = 7 + TomEvenPagesFooterStory = 8 + TomPrimaryFooterStory = 9 + TomFirstPageHeaderStory = 10 + TomFirstPageFooterStory = 11 + TomScratchStory = 127 + TomFindStory = 128 + TomReplaceStory = 129 + TomStoryInactive = 0 + TomStoryActiveDisplay = 1 + TomStoryActiveUI = 2 + TomStoryActiveDisplayUI = 3 + TomNoAnimation = 0 + TomLasVegasLights = 1 + TomBlinkingBackground = 2 + TomSparkleText = 3 + TomMarchingBlackAnts = 4 + TomMarchingRedAnts = 5 + TomShimmer = 6 + TomWipeDown = 7 + TomWipeRight = 8 + TomAnimationMax = 8 + TomLowerCase = 0 + TomUpperCase = 1 + TomTitleCase = 2 + TomSentenceCase = 4 + TomToggleCase = 5 + TomReadOnly = 0x100 + TomShareDenyRead = 0x200 + TomShareDenyWrite = 0x400 + TomPasteFile = 0x1000 + TomCreateNew = 0x10 + TomCreateAlways = 0x20 + TomOpenExisting = 0x30 + TomOpenAlways = 0x40 + TomTruncateExisting = 0x50 + TomRTF = 0x1 + TomText = 0x2 + TomHTML = 0x3 + TomWordDocument = 0x4 + TomBold = 0x80000001 + TomItalic = 0x80000002 + TomUnderline = 0x80000004 + TomStrikeout = 0x80000008 + TomProtected = 0x80000010 + TomLink = 0x80000020 + TomSmallCaps = 0x80000040 + TomAllCaps = 0x80000080 + TomHidden = 0x80000100 + TomOutline = 0x80000200 + TomShadow = 0x80000400 + TomEmboss = 0x80000800 + TomImprint = 0x80001000 + TomDisabled = 0x80002000 + TomRevised = 0x80004000 + TomSubscriptCF = 0x80010000 + TomSuperscriptCF = 0x80020000 + TomFontBound = 0x80100000 + TomLinkProtected = 0x80800000 + TomInlineObjectStart = 0x81000000 + TomExtendedChar = 0x82000000 + TomAutoBackColor = 0x84000000 + TomMathZoneNoBuildUp = 0x88000000 + TomMathZone = 0x90000000 + TomMathZoneOrdinary = 0xa0000000 + TomAutoTextColor = 0xc0000000 + TomMathZoneDisplay = 0x40000 + TomParaEffectRTL = 0x1 + TomParaEffectKeep = 0x2 + TomParaEffectKeepNext = 0x4 + TomParaEffectPageBreakBefore = 0x8 + TomParaEffectNoLineNumber = 0x10 + TomParaEffectNoWidowControl = 0x20 + TomParaEffectDoNotHyphen = 0x40 + TomParaEffectSideBySide = 0x80 + TomParaEffectCollapsed = 0x100 + TomParaEffectOutlineLevel = 0x200 + TomParaEffectBox = 0x400 + TomParaEffectTableRowDelimiter = 0x1000 + TomParaEffectTable = 0x4000 + TomModWidthPairs = 0x1 + TomModWidthSpace = 0x2 + TomAutoSpaceAlpha = 0x4 + TomAutoSpaceNumeric = 0x8 + TomAutoSpaceParens = 0x10 + TomEmbeddedFont = 0x20 + TomDoublestrike = 0x40 + TomOverlapping = 0x80 + TomNormalCaret = 0 + TomKoreanBlockCaret = 0x1 + TomNullCaret = 0x2 + TomIncludeInset = 0x1 + TomUnicodeBiDi = 0x1 + TomMathCFCheck = 0x4 + TomUnlink = 0x8 + TomUnhide = 0x10 + TomCheckTextLimit = 0x20 + TomIgnoreCurrentFont = 0 + TomMatchCharRep = 0x1 + TomMatchFontSignature = 0x2 + TomMatchAscii = 0x4 + TomGetHeightOnly = 0x8 + TomMatchMathFont = 0x10 + TomCharset = 0x80000000 + TomCharRepFromLcid = 0x40000000 + TomAnsi = 0 + TomEastEurope = 1 + TomCyrillic = 2 + TomGreek = 3 + TomTurkish = 4 + TomHebrew = 5 + TomArabic = 6 + TomBaltic = 7 + TomVietnamese = 8 + TomDefaultCharRep = 9 + TomSymbol = 10 + TomThai = 11 + TomShiftJIS = 12 + TomGB2312 = 13 + TomHangul = 14 + TomBIG5 = 15 + TomPC437 = 16 + TomOEM = 17 + TomMac = 18 + TomArmenian = 19 + TomSyriac = 20 + TomThaana = 21 + TomDevanagari = 22 + TomBengali = 23 + TomGurmukhi = 24 + TomGujarati = 25 + TomOriya = 26 + TomTamil = 27 + TomTelugu = 28 + TomKannada = 29 + TomMalayalam = 30 + TomSinhala = 31 + TomLao = 32 + TomTibetan = 33 + TomMyanmar = 34 + TomGeorgian = 35 + TomJamo = 36 + TomEthiopic = 37 + TomCherokee = 38 + TomAboriginal = 39 + TomOgham = 40 + TomRunic = 41 + TomKhmer = 42 + TomMongolian = 43 + TomBraille = 44 + TomYi = 45 + TomLimbu = 46 + TomTaiLe = 47 + TomNewTaiLue = 48 + TomSylotiNagri = 49 + TomKharoshthi = 50 + TomKayahli = 51 + TomUsymbol = 52 + TomEmoji = 53 + TomGlagolitic = 54 + TomLisu = 55 + TomVai = 56 + TomNKo = 57 + TomOsmanya = 58 + TomPhagsPa = 59 + TomGothic = 60 + TomDeseret = 61 + TomTifinagh = 62 + TomCharRepMax = 63 + TomRE10Mode = 0x1 + TomUseAtFont = 0x2 + TomTextFlowMask = 0xc + TomTextFlowES = 0 + TomTextFlowSW = 0x4 + TomTextFlowWN = 0x8 + TomTextFlowNE = 0xc + TomNoIME = 0x80000 + TomSelfIME = 0x40000 + TomNoUpScroll = 0x10000 + TomNoVpScroll = 0x40000 + TomNoLink = 0 + TomClientLink = 1 + TomFriendlyLinkName = 2 + TomFriendlyLinkAddress = 3 + TomAutoLinkURL = 4 + TomAutoLinkEmail = 5 + TomAutoLinkPhone = 6 + TomAutoLinkPath = 7 + TomCompressNone = 0 + TomCompressPunctuation = 1 + TomCompressPunctuationAndKana = 2 + TomCompressMax = 2 + TomUnderlinePositionAuto = 0 + TomUnderlinePositionBelow = 1 + TomUnderlinePositionAbove = 2 + TomUnderlinePositionMax = 2 + TomFontAlignmentAuto = 0 + TomFontAlignmentTop = 1 + TomFontAlignmentBaseline = 2 + TomFontAlignmentBottom = 3 + TomFontAlignmentCenter = 4 + TomFontAlignmentMax = 4 + TomRubyBelow = 0x80 + TomRubyAlignCenter = 0 + TomRubyAlign010 = 1 + TomRubyAlign121 = 2 + TomRubyAlignLeft = 3 + TomRubyAlignRight = 4 + TomLimitsDefault = 0 + TomLimitsUnderOver = 1 + TomLimitsSubSup = 2 + TomUpperLimitAsSuperScript = 3 + TomLimitsOpposite = 4 + TomShowLLimPlaceHldr = 8 + TomShowULimPlaceHldr = 16 + TomDontGrowWithContent = 64 + TomGrowWithContent = 128 + TomSubSupAlign = 1 + TomLimitAlignMask = 3 + TomLimitAlignCenter = 0 + TomLimitAlignLeft = 1 + TomLimitAlignRight = 2 + TomShowDegPlaceHldr = 8 + TomAlignDefault = 0 + TomAlignMatchAscentDescent = 2 + TomMathVariant = 0x20 + TomStyleDefault = 0 + TomStyleScriptScriptCramped = 1 + TomStyleScriptScript = 2 + TomStyleScriptCramped = 3 + TomStyleScript = 4 + TomStyleTextCramped = 5 + TomStyleText = 6 + TomStyleDisplayCramped = 7 + TomStyleDisplay = 8 + TomMathRelSize = 0x40 + TomDecDecSize = 0xfe + TomDecSize = 0xff + TomIncSize = (1 | TomMathRelSize) + TomIncIncSize = (2 | TomMathRelSize) + TomGravityUI = 0 + TomGravityBack = 1 + TomGravityFore = 2 + TomGravityIn = 3 + TomGravityOut = 4 + TomGravityBackward = 0x20000000 + TomGravityForward = 0x40000000 + TomAdjustCRLF = 1 + TomUseCRLF = 2 + TomTextize = 4 + TomAllowFinalEOP = 8 + TomFoldMathAlpha = 16 + TomNoHidden = 32 + TomIncludeNumbering = 64 + TomTranslateTableCell = 128 + TomNoMathZoneBrackets = 0x100 + TomConvertMathChar = 0x200 + TomNoUCGreekItalic = 0x400 + TomAllowMathBold = 0x800 + TomLanguageTag = 0x1000 + TomConvertRTF = 0x2000 + TomApplyRtfDocProps = 0x4000 + TomPhantomShow = 1 + TomPhantomZeroWidth = 2 + TomPhantomZeroAscent = 4 + TomPhantomZeroDescent = 8 + TomPhantomTransparent = 16 + TomPhantomASmash = (TomPhantomShow | TomPhantomZeroAscent) + TomPhantomDSmash = (TomPhantomShow | TomPhantomZeroDescent) + TomPhantomHSmash = (TomPhantomShow | TomPhantomZeroWidth) + TomPhantomSmash = ((TomPhantomShow | TomPhantomZeroAscent) | TomPhantomZeroDescent) + TomPhantomHorz = (TomPhantomZeroAscent | TomPhantomZeroDescent) + TomPhantomVert = TomPhantomZeroWidth + TomBoxHideTop = 1 + TomBoxHideBottom = 2 + TomBoxHideLeft = 4 + TomBoxHideRight = 8 + TomBoxStrikeH = 16 + TomBoxStrikeV = 32 + TomBoxStrikeTLBR = 64 + TomBoxStrikeBLTR = 128 + TomBoxAlignCenter = 1 + TomSpaceMask = 0x1c + TomSpaceDefault = 0 + TomSpaceUnary = 4 + TomSpaceBinary = 8 + TomSpaceRelational = 12 + TomSpaceSkip = 16 + TomSpaceOrd = 20 + TomSpaceDifferential = 24 + TomSizeText = 32 + TomSizeScript = 64 + TomSizeScriptScript = 96 + TomNoBreak = 128 + TomTransparentForPositioning = 256 + TomTransparentForSpacing = 512 + TomStretchCharBelow = 0 + TomStretchCharAbove = 1 + TomStretchBaseBelow = 2 + TomStretchBaseAbove = 3 + TomMatrixAlignMask = 3 + TomMatrixAlignCenter = 0 + TomMatrixAlignTopRow = 1 + TomMatrixAlignBottomRow = 3 + TomShowMatPlaceHldr = 8 + TomEqArrayLayoutWidth = 1 + TomEqArrayAlignMask = 0xc + TomEqArrayAlignCenter = 0 + TomEqArrayAlignTopRow = 4 + TomEqArrayAlignBottomRow = 0xc + TomMathManualBreakMask = 0x7f + TomMathBreakLeft = 0x7d + TomMathBreakCenter = 0x7e + TomMathBreakRight = 0x7f + TomMathEqAlign = 0x80 + TomMathArgShadingStart = 0x251 + TomMathArgShadingEnd = 0x252 + TomMathObjShadingStart = 0x253 + TomMathObjShadingEnd = 0x254 + TomFunctionTypeNone = 0 + TomFunctionTypeTakesArg = 1 + TomFunctionTypeTakesLim = 2 + TomFunctionTypeTakesLim2 = 3 + TomFunctionTypeIsLim = 4 + TomMathParaAlignDefault = 0 + TomMathParaAlignCenterGroup = 1 + TomMathParaAlignCenter = 2 + TomMathParaAlignLeft = 3 + TomMathParaAlignRight = 4 + TomMathDispAlignMask = 3 + TomMathDispAlignCenterGroup = 0 + TomMathDispAlignCenter = 1 + TomMathDispAlignLeft = 2 + TomMathDispAlignRight = 3 + TomMathDispIntUnderOver = 4 + TomMathDispFracTeX = 8 + TomMathDispNaryGrow = 0x10 + TomMathDocEmptyArgMask = 0x60 + TomMathDocEmptyArgAuto = 0 + TomMathDocEmptyArgAlways = 0x20 + TomMathDocEmptyArgNever = 0x40 + TomMathDocSbSpOpUnchanged = 0x80 + TomMathDocDiffMask = 0x300 + TomMathDocDiffDefault = 0 + TomMathDocDiffUpright = 0x100 + TomMathDocDiffItalic = 0x200 + TomMathDocDiffOpenItalic = 0x300 + TomMathDispNarySubSup = 0x400 + TomMathDispDef = 0x800 + TomMathEnableRtl = 0x1000 + TomMathBrkBinMask = 0x30000 + TomMathBrkBinBefore = 0 + TomMathBrkBinAfter = 0x10000 + TomMathBrkBinDup = 0x20000 + TomMathBrkBinSubMask = 0xc0000 + TomMathBrkBinSubMM = 0 + TomMathBrkBinSubPM = 0x40000 + TomMathBrkBinSubMP = 0x80000 + TomSelRange = 0x255 + TomHstring = 0x254 + TomFontPropTeXStyle = 0x33c + TomFontPropAlign = 0x33d + TomFontStretch = 0x33e + TomFontStyle = 0x33f + TomFontStyleUpright = 0 + TomFontStyleOblique = 1 + TomFontStyleItalic = 2 + TomFontStretchDefault = 0 + TomFontStretchUltraCondensed = 1 + TomFontStretchExtraCondensed = 2 + TomFontStretchCondensed = 3 + TomFontStretchSemiCondensed = 4 + TomFontStretchNormal = 5 + TomFontStretchSemiExpanded = 6 + TomFontStretchExpanded = 7 + TomFontStretchExtraExpanded = 8 + TomFontStretchUltraExpanded = 9 + TomFontWeightDefault = 0 + TomFontWeightThin = 100 + TomFontWeightExtraLight = 200 + TomFontWeightLight = 300 + TomFontWeightNormal = 400 + TomFontWeightRegular = 400 + TomFontWeightMedium = 500 + TomFontWeightSemiBold = 600 + TomFontWeightBold = 700 + TomFontWeightExtraBold = 800 + TomFontWeightBlack = 900 + TomFontWeightHeavy = 900 + TomFontWeightExtraBlack = 950 + TomParaPropMathAlign = 0x437 + TomDocMathBuild = 0x80 + TomMathLMargin = 0x81 + TomMathRMargin = 0x82 + TomMathWrapIndent = 0x83 + TomMathWrapRight = 0x84 + TomMathPostSpace = 0x86 + TomMathPreSpace = 0x85 + TomMathInterSpace = 0x87 + TomMathIntraSpace = 0x88 + TomCanCopy = 0x89 + TomCanRedo = 0x8a + TomCanUndo = 0x8b + TomUndoLimit = 0x8c + TomDocAutoLink = 0x8d + TomEllipsisMode = 0x8e + TomEllipsisState = 0x8f + TomEllipsisNone = 0 + TomEllipsisEnd = 1 + TomEllipsisWord = 3 + TomEllipsisPresent = 1 + TomVTopCell = 1 + TomVLowCell = 2 + TomHStartCell = 4 + TomHContCell = 8 + TomRowUpdate = 1 + TomRowApplyDefault = 0 + TomCellStructureChangeOnly = 1 + TomRowHeightActual = 0x80b +) + +type OBJECTTYPE int32 + +const ( + TomSimpleText OBJECTTYPE = 0 + TomRuby = (TomSimpleText + 1) + TomHorzVert = (TomRuby + 1) + TomWarichu = (TomHorzVert + 1) + TomEq = 9 + TomMath = 10 + TomAccent = TomMath + TomBox = (TomAccent + 1) + TomBoxedFormula = (TomBox + 1) + TomBrackets = (TomBoxedFormula + 1) + TomBracketsWithSeps = (TomBrackets + 1) + TomEquationArray = (TomBracketsWithSeps + 1) + TomFraction = (TomEquationArray + 1) + TomFunctionApply = (TomFraction + 1) + TomLeftSubSup = (TomFunctionApply + 1) + TomLowerLimit = (TomLeftSubSup + 1) + TomMatrix = (TomLowerLimit + 1) + TomNary = (TomMatrix + 1) + TomOpChar = (TomNary + 1) + TomOverbar = (TomOpChar + 1) + TomPhanTom = (TomOverbar + 1) + TomRadical = (TomPhanTom + 1) + TomSlashedFraction = (TomRadical + 1) + TomStack = (TomSlashedFraction + 1) + TomStretchStack = (TomStack + 1) + TomSubscript = (TomStretchStack + 1) + TomSubSup = (TomSubscript + 1) + TomSuperscript = (TomSubSup + 1) + TomUnderbar = (TomSuperscript + 1) + TomUpperLimit = (TomUnderbar + 1) + TomObjectMax = TomUpperLimit +) + +type ITextRangeVtbl struct { + IDispatchVtbl + GetText uintptr + SetText uintptr + GetChar uintptr + SetChar uintptr + GetDuplicate uintptr + GetFormattedText uintptr + SetFormattedText uintptr + GetStart uintptr + SetStart uintptr + GetEnd uintptr + SetEnd uintptr + GetFont uintptr + SetFont uintptr + GetPara uintptr + SetPara uintptr + GetStoryLength uintptr + GetStoryType uintptr + Collapse uintptr + Expand uintptr + GetIndex uintptr + SetIndex uintptr + SetRange uintptr + InRange uintptr + InStory uintptr + IsEqual uintptr + Select uintptr + StartOf uintptr + EndOf uintptr + Move uintptr + MoveStart uintptr + MoveEnd uintptr + MoveWhile uintptr + MoveStartWhile uintptr + MoveEndWhile uintptr + MoveUntil uintptr + MoveStartUntil uintptr + MoveEndUntil uintptr + FindText uintptr + FindTextStart uintptr + FindTextEnd uintptr + Delete uintptr + Cut uintptr + Copy uintptr + Paste uintptr + CanPaste uintptr + CanEdit uintptr + ChangeCase uintptr + GetPoint uintptr + SetPoint uintptr + ScrollIntoView uintptr + GetEmbeddedObject uintptr +} + +type ITextRange struct { + LpVtbl *ITextRangeVtbl +} + +type ITextSelectionVtbl struct { + ITextRangeVtbl + GetFlags uintptr + SetFlags uintptr + GetType uintptr + MoveLeft uintptr + MoveRight uintptr + MoveUp uintptr + MoveDown uintptr + HomeKey uintptr + EndKey uintptr + TypeText uintptr +} + +type ITextSelection struct { + LpVtbl *ITextSelectionVtbl +} + +type ITextDocumentVtbl struct { + IDispatchVtbl + GetName uintptr + GetSelection uintptr + GetStoryCount uintptr + GetStoryRanges uintptr + GetSaved uintptr + SetSaved uintptr + GetDefaultTabStop uintptr + SetDefaultTabStop uintptr + New uintptr + Open uintptr + Save uintptr + Freeze uintptr + Unfreeze uintptr + BeginEditCollection uintptr + EndEditCollection uintptr + Undo uintptr + Redo uintptr + Range uintptr + RangeFromPoint uintptr +} + +type ITextStoryRangesVtbl struct { + IDispatchVtbl + NewEnum uintptr + Item uintptr + GetCount uintptr +} + +type ITextStoryRanges struct { + LpVtbl *ITextStoryRangesVtbl +} + +var ( + IID_ITextDocument = IID{0x8CC497C0, 0xA1DF, 0x11CE, [8]byte{0x80, 0x98, 0x00, 0xAA, 0x00, 0x47, 0xBE, 0x5D}} +) + +type ITextDocument struct { + LpVtbl *ITextDocumentVtbl +} + +func (obj *ITextDocument) QueryInterface(riid REFIID, ppvObject *unsafe.Pointer) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.QueryInterface, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(ppvObject))) + return HRESULT(ret) +} + +func (obj *ITextDocument) AddRef() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.AddRef, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *ITextDocument) Release() uint32 { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Release, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return uint32(ret) +} + +func (obj *ITextDocument) GetTypeInfoCount(pctinfo *uint32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetTypeInfoCount, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pctinfo)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetTypeInfo(iTInfo uint32, lcid LCID, ppTInfo **ITypeInfo) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.GetTypeInfo, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(iTInfo), + uintptr(lcid), + uintptr(unsafe.Pointer(ppTInfo)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetIDsOfNames(riid REFIID, rgszNames **uint16, cNames uint32, lcid LCID, rgDispId *DISPID) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.GetIDsOfNames, 6, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(riid)), + uintptr(unsafe.Pointer(rgszNames)), + uintptr(cNames), + uintptr(lcid), + uintptr(unsafe.Pointer(rgDispId))) + return HRESULT(ret) +} + +func (obj *ITextDocument) Invoke(dispIdMember DISPID, riid REFIID, lcid LCID, wFlags uint16, pDispParams *DISPPARAMS, pVarResult *VARIANT, pExcepInfo *EXCEPINFO, puArgErr *uint32) HRESULT { + ret, _, _ := syscall.Syscall9(obj.LpVtbl.Invoke, 9, + uintptr(unsafe.Pointer(obj)), + uintptr(dispIdMember), + uintptr(unsafe.Pointer(riid)), + uintptr(lcid), + uintptr(wFlags), + uintptr(unsafe.Pointer(pDispParams)), + uintptr(unsafe.Pointer(pVarResult)), + uintptr(unsafe.Pointer(pExcepInfo)), + uintptr(unsafe.Pointer(puArgErr))) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetName(pName **uint16 /*BSTR*/) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetName, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pName)), + 0) + return HRESULT(ret) + +} + +func (obj *ITextDocument) GetSelection(ppSel **ITextSelection) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetSelection, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(ppSel)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetStoryCount(pCount *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetStoryCount, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pCount)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetStoryRanges(ppStories **ITextStoryRanges) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetStoryRanges, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(ppStories)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetSaved(pValue *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetSaved, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pValue)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) SetSaved(Value int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SetSaved, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(Value), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) GetDefaultTabStop(pValue *float32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.GetDefaultTabStop, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pValue)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) SetDefaultTabStop(Value float32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.SetDefaultTabStop, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(Value), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) New() HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.New, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) Open(pVar *VARIANT, Flags int32, CodePage int32) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.Open, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pVar)), + uintptr(Flags), + uintptr(CodePage), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) Save(pVar *VARIANT, Flags int32, CodePage int32) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.Save, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pVar)), + uintptr(Flags), + uintptr(CodePage), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) Freeze(pCount *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Freeze, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pCount)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) Unfreeze(pCount *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Freeze, 2, + uintptr(unsafe.Pointer(obj)), + uintptr(unsafe.Pointer(pCount)), + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) BeginEditCollection() HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.BeginEditCollection, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) EndEditCollection() HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.EndEditCollection, 1, + uintptr(unsafe.Pointer(obj)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) Undo(Count int32, pCount *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Undo, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(Count), + uintptr(unsafe.Pointer(pCount))) + return HRESULT(ret) +} + +func (obj *ITextDocument) Redo(Count int32, pCount *int32) HRESULT { + ret, _, _ := syscall.Syscall(obj.LpVtbl.Redo, 3, + uintptr(unsafe.Pointer(obj)), + uintptr(Count), + uintptr(unsafe.Pointer(pCount))) + return HRESULT(ret) +} + +func (obj *ITextDocument) Range(cpActive int32, cpAnchor int32, ppRange **ITextRange) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.Range, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(cpActive), + uintptr(cpAnchor), + uintptr(unsafe.Pointer(ppRange)), + 0, + 0) + return HRESULT(ret) +} + +func (obj *ITextDocument) RangeFromPoint(x int32, y int32, ppRange **ITextRange) HRESULT { + ret, _, _ := syscall.Syscall6(obj.LpVtbl.RangeFromPoint, 4, + uintptr(unsafe.Pointer(obj)), + uintptr(x), + uintptr(y), + uintptr(unsafe.Pointer(ppRange)), + 0, + 0) + return HRESULT(ret) +} diff --git a/toolbar.go b/toolbar.go index 85656d6e..74efe94c 100644 --- a/toolbar.go +++ b/toolbar.go @@ -2,10 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // ToolBar messages const ( + TB_THUMBPOSITION = 4 + TB_THUMBTRACK = 5 + TB_ENDTRACK = 8 TB_ENABLEBUTTON = WM_USER + 1 TB_CHECKBUTTON = WM_USER + 2 TB_PRESSBUTTON = WM_USER + 3 @@ -83,6 +88,8 @@ const ( TB_GETINSERTMARKCOLOR = WM_USER + 89 TB_MAPACCELERATOR = WM_USER + 90 TB_GETSTRING = WM_USER + 91 + TB_GETIDEALSIZE = WM_USER + 99 + TB_GETMETRICS = WM_USER + 101 TB_SETCOLORSCHEME = CCM_SETCOLORSCHEME TB_GETCOLORSCHEME = CCM_GETCOLORSCHEME TB_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT @@ -168,6 +175,13 @@ const ( TBIF_BYINDEX = 0x80000000 ) +// TBMETRICS mask flags +const ( + TBMF_PAD = 0x00000001 + TBMF_BARPAD = 0x00000002 + TBMF_BUTTONSPACING = 0x00000004 +) + type NMMOUSE struct { Hdr NMHDR DwItemSpec uintptr @@ -211,3 +225,14 @@ type TBBUTTONINFO struct { PszText uintptr CchText int32 } + +type TBMETRICS struct { + CbSize uint32 + DwMask uint32 + CxPad int32 + CyPad int32 + CxBarPad int32 + CyBarPad int32 + CxButtonSpacing int32 + CyButtonSpacing int32 +} diff --git a/tooltip.go b/tooltip.go index 9a11533e..8e2aec71 100644 --- a/tooltip.go +++ b/tooltip.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( diff --git a/treeview.go b/treeview.go index ce51ef75..b21e42fd 100644 --- a/treeview.go +++ b/treeview.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win // TreeView styles @@ -24,6 +26,20 @@ const ( TVS_NOHSCROLL = 0x8000 ) +const ( + TVS_EX_NOSINGLECOLLAPSE = 0x0001 + TVS_EX_MULTISELECT = 0x0002 + TVS_EX_DOUBLEBUFFER = 0x0004 + TVS_EX_NOINDENTSTATE = 0x0008 + TVS_EX_RICHTOOLTIP = 0x0010 + TVS_EX_AUTOHSCROLL = 0x0020 + TVS_EX_FADEINOUTEXPANDOS = 0x0040 + TVS_EX_PARTIALCHECKBOXES = 0x0080 + TVS_EX_EXCLUSIONCHECKBOXES = 0x0100 + TVS_EX_DIMMEDCHECKBOXES = 0x0200 + TVS_EX_DRAWIMAGEASYNC = 0x0400 +) + const ( TVIF_TEXT = 0x0001 TVIF_IMAGE = 0x0002 @@ -218,6 +234,12 @@ type NMTVDISPINFO struct { Item TVITEM } +type NMTVKEYDOWN struct { + Hdr NMHDR + WVKey uint16 + Flags uint32 +} + type TVHITTESTINFO struct { Pt POINT Flags uint32 diff --git a/updown.go b/updown.go index 672dde08..f315c3f0 100644 --- a/updown.go +++ b/updown.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win const UDN_FIRST = ^uint32(720) diff --git a/user32.go b/user32.go index 84272e61..fd5eb4e1 100644 --- a/user32.go +++ b/user32.go @@ -2,37 +2,51 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( "syscall" "unsafe" + + "golang.org/x/sys/windows" ) const CW_USEDEFAULT = ^0x7fffffff // MessageBox constants const ( - MB_OK = 0x00000000 - MB_OKCANCEL = 0x00000001 - MB_ABORTRETRYIGNORE = 0x00000002 - MB_YESNOCANCEL = 0x00000003 - MB_YESNO = 0x00000004 - MB_RETRYCANCEL = 0x00000005 - MB_CANCELTRYCONTINUE = 0x00000006 - MB_ICONHAND = 0x00000010 - MB_ICONQUESTION = 0x00000020 - MB_ICONEXCLAMATION = 0x00000030 - MB_ICONASTERISK = 0x00000040 - MB_USERICON = 0x00000080 - MB_ICONWARNING = MB_ICONEXCLAMATION - MB_ICONERROR = MB_ICONHAND - MB_ICONINFORMATION = MB_ICONASTERISK - MB_ICONSTOP = MB_ICONHAND - MB_DEFBUTTON1 = 0x00000000 - MB_DEFBUTTON2 = 0x00000100 - MB_DEFBUTTON3 = 0x00000200 - MB_DEFBUTTON4 = 0x00000300 + MB_OK = 0x00000000 + MB_OKCANCEL = 0x00000001 + MB_ABORTRETRYIGNORE = 0x00000002 + MB_YESNOCANCEL = 0x00000003 + MB_YESNO = 0x00000004 + MB_RETRYCANCEL = 0x00000005 + MB_CANCELTRYCONTINUE = 0x00000006 + MB_ICONHAND = 0x00000010 + MB_ICONQUESTION = 0x00000020 + MB_ICONEXCLAMATION = 0x00000030 + MB_ICONASTERISK = 0x00000040 + MB_USERICON = 0x00000080 + MB_ICONWARNING = MB_ICONEXCLAMATION + MB_ICONERROR = MB_ICONHAND + MB_ICONINFORMATION = MB_ICONASTERISK + MB_ICONSTOP = MB_ICONHAND + MB_DEFBUTTON1 = 0x00000000 + MB_DEFBUTTON2 = 0x00000100 + MB_DEFBUTTON3 = 0x00000200 + MB_DEFBUTTON4 = 0x00000300 + MB_APPLMODAL = 0x00000000 + MB_SYSTEMMODAL = 0x00001000 + MB_TASKMODAL = 0x00002000 + MB_HELP = 0x00004000 + MB_SETFOREGROUND = 0x00010000 + MB_DEFAULT_DESKTOP_ONLY = 0x00020000 + MB_TOPMOST = 0x00040000 + MB_RIGHT = 0x00080000 + MB_RTLREADING = 0x00100000 + MB_SERVICE_NOTIFICATION = 0x00200000 ) // Dialog box command ids @@ -125,6 +139,7 @@ const ( // Button notifications const ( + BCN_DROPDOWN = 0xfffffb20 BN_CLICKED = 0 BN_PAINT = 1 BN_HILITE = 2 @@ -185,6 +200,7 @@ const ( BS_RADIOBUTTON = 4 BS_RIGHT = 512 BS_RIGHTBUTTON = 32 + BS_SPLITBUTTON = 0x0000000c BS_TEXT = 0 BS_TOP = 0X400 BS_USERBUTTON = 8 @@ -660,6 +676,7 @@ const ( WS_EX_LAYERED = 0X00080000 WS_EX_NOINHERITLAYOUT = 0X00100000 WS_EX_LAYOUTRTL = 0X00400000 + WS_EX_COMPOSITED = 0X02000000 WS_EX_NOACTIVATE = 0X08000000 ) @@ -703,6 +720,7 @@ const ( WM_DEVICECHANGE = 537 WM_DEVMODECHANGE = 27 WM_DISPLAYCHANGE = 126 + WM_DPICHANGED = 0x02E0 WM_DRAWCLIPBOARD = 776 WM_DRAWITEM = 43 WM_DROPFILES = 563 @@ -868,6 +886,131 @@ const ( WM_MOUSELAST = 525 WM_MOUSEHOVER = 0X2A1 WM_MOUSELEAVE = 0X2A3 + WM_CLIPBOARDUPDATE = 0x031D + WM_UNICHAR = 0x0109 +) + +const ( + CHILDID_SELF = 0 + INDEXID_OBJECT = 0 + INDEXID_CONTAINER = 0 + + OBJID_WINDOW = int32(0x00000000) + OBJID_SYSMENU = int32(-((0xFFFFFFFF ^ 0xFFFFFFFF) + 1)) + OBJID_TITLEBAR = int32(-((0xFFFFFFFE ^ 0xFFFFFFFF) + 1)) + OBJID_MENU = int32(-((0xFFFFFFFD ^ 0xFFFFFFFF) + 1)) + OBJID_CLIENT = int32(-((0xFFFFFFFC ^ 0xFFFFFFFF) + 1)) + OBJID_VSCROLL = int32(-((0xFFFFFFFB ^ 0xFFFFFFFF) + 1)) + OBJID_HSCROLL = int32(-((0xFFFFFFFA ^ 0xFFFFFFFF) + 1)) + OBJID_SIZEGRIP = int32(-((0xFFFFFFF9 ^ 0xFFFFFFFF) + 1)) + OBJID_CARET = int32(-((0xFFFFFFF8 ^ 0xFFFFFFFF) + 1)) + OBJID_CURSOR = int32(-((0xFFFFFFF7 ^ 0xFFFFFFFF) + 1)) + OBJID_ALERT = int32(-((0xFFFFFFF6 ^ 0xFFFFFFFF) + 1)) + OBJID_SOUND = int32(-((0xFFFFFFF5 ^ 0xFFFFFFFF) + 1)) + OBJID_QUERYCLASSNAMEIDX = int32(-((0xFFFFFFF4 ^ 0xFFFFFFFF) + 1)) + OBJID_NATIVEOM = int32(-((0xFFFFFFF0 ^ 0xFFFFFFFF) + 1)) +) + +// event constants +const ( + EVENT_MIN = 0x00000001 + EVENT_MAX = 0x7FFFFFFF + + EVENT_SYSTEM_SOUND = 0x0001 + EVENT_SYSTEM_ALERT = 0x0002 + EVENT_SYSTEM_FOREGROUND = 0x0003 + EVENT_SYSTEM_MENUSTART = 0x0004 + EVENT_SYSTEM_MENUEND = 0x0005 + EVENT_SYSTEM_MENUPOPUPSTART = 0x0006 + EVENT_SYSTEM_MENUPOPUPEND = 0x0007 + EVENT_SYSTEM_CAPTURESTART = 0x0008 + EVENT_SYSTEM_CAPTUREEND = 0x0009 + EVENT_SYSTEM_MOVESIZESTART = 0x000A + EVENT_SYSTEM_MOVESIZEEND = 0x000B + EVENT_SYSTEM_CONTEXTHELPSTART = 0x000C + EVENT_SYSTEM_CONTEXTHELPEND = 0x000D + EVENT_SYSTEM_DRAGDROPSTART = 0x000E + EVENT_SYSTEM_DRAGDROPEND = 0x000F + EVENT_SYSTEM_DIALOGSTART = 0x0010 + EVENT_SYSTEM_DIALOGEND = 0x0011 + EVENT_SYSTEM_SCROLLINGSTART = 0x0012 + EVENT_SYSTEM_SCROLLINGEND = 0x0013 + EVENT_SYSTEM_SWITCHSTART = 0x0014 + EVENT_SYSTEM_SWITCHEND = 0x0015 + EVENT_SYSTEM_MINIMIZESTART = 0x0016 + EVENT_SYSTEM_MINIMIZEEND = 0x0017 + EVENT_SYSTEM_DESKTOPSWITCH = 0x0020 + EVENT_SYSTEM_SWITCHER_APPGRABBED = 0x0024 + EVENT_SYSTEM_SWITCHER_APPOVERTARGET = 0x0025 + EVENT_SYSTEM_SWITCHER_APPDROPPED = 0x0026 + EVENT_SYSTEM_SWITCHER_CANCELLED = 0x0027 + EVENT_SYSTEM_IME_KEY_NOTIFICATION = 0x0029 + EVENT_SYSTEM_END = 0x00FF + + EVENT_OEM_DEFINED_START = 0x0101 + EVENT_OEM_DEFINED_END = 0x01FF + + EVENT_CONSOLE_CARET = 0x4001 + EVENT_CONSOLE_UPDATE_REGION = 0x4002 + EVENT_CONSOLE_UPDATE_SIMPLE = 0x4003 + EVENT_CONSOLE_UPDATE_SCROLL = 0x4004 + EVENT_CONSOLE_LAYOUT = 0x4005 + EVENT_CONSOLE_START_APPLICATION = 0x4006 + EVENT_CONSOLE_END_APPLICATION = 0x4007 + EVENT_CONSOLE_END = 0x40FF + + EVENT_UIA_EVENTID_START = 0x4E00 + EVENT_UIA_EVENTID_END = 0x4EFF + + EVENT_UIA_PROPID_START = 0x7500 + EVENT_UIA_PROPID_END = 0x75FF + + EVENT_OBJECT_CREATE = 0x8000 + EVENT_OBJECT_DESTROY = 0x8001 + EVENT_OBJECT_SHOW = 0x8002 + EVENT_OBJECT_HIDE = 0x8003 + EVENT_OBJECT_REORDER = 0x8004 + EVENT_OBJECT_FOCUS = 0x8005 + EVENT_OBJECT_SELECTION = 0x8006 + EVENT_OBJECT_SELECTIONADD = 0x8007 + EVENT_OBJECT_SELECTIONREMOVE = 0x8008 + EVENT_OBJECT_SELECTIONWITHIN = 0x8009 + EVENT_OBJECT_STATECHANGE = 0x800A + EVENT_OBJECT_LOCATIONCHANGE = 0x800B + EVENT_OBJECT_NAMECHANGE = 0x800C + EVENT_OBJECT_DESCRIPTIONCHANGE = 0x800D + EVENT_OBJECT_VALUECHANGE = 0x800E + EVENT_OBJECT_PARENTCHANGE = 0x800F + EVENT_OBJECT_HELPCHANGE = 0x8010 + EVENT_OBJECT_DEFACTIONCHANGE = 0x8011 + EVENT_OBJECT_ACCELERATORCHANGE = 0x8012 + EVENT_OBJECT_INVOKED = 0x8013 + EVENT_OBJECT_TEXTSELECTIONCHANGED = 0x8014 + EVENT_OBJECT_CONTENTSCROLLED = 0x8015 + EVENT_SYSTEM_ARRANGMENTPREVIEW = 0x8016 + EVENT_OBJECT_CLOAKED = 0x8017 + EVENT_OBJECT_UNCLOAKED = 0x8018 + EVENT_OBJECT_LIVEREGIONCHANGED = 0x8019 + EVENT_OBJECT_HOSTEDOBJECTSINVALIDATED = 0x8020 + EVENT_OBJECT_DRAGSTART = 0x8021 + EVENT_OBJECT_DRAGCANCEL = 0x8022 + EVENT_OBJECT_DRAGCOMPLETE = 0x8023 + EVENT_OBJECT_DRAGENTER = 0x8024 + EVENT_OBJECT_DRAGLEAVE = 0x8025 + EVENT_OBJECT_DRAGDROPPED = 0x8026 + EVENT_OBJECT_IME_SHOW = 0x8027 + EVENT_OBJECT_IME_HIDE = 0x8028 + EVENT_OBJECT_IME_CHANGE = 0x8029 + EVENT_OBJECT_TEXTEDIT_CONVERSIONTARGETCHANGED = 0x8030 + EVENT_OBJECT_END = 0x80FF + + EVENT_AIA_START = 0xa000 + EVENT_AIA_END = 0xafff + + WINEVENT_OUTOFCONTEXT = 0x0000 + WINEVENT_SKIPOWNTHREAD = 0x0001 + WINEVENT_SKIPOWNPROCESS = 0x0002 + WINEVENT_INCONTEXT = 0x0004 ) // mouse button constants @@ -959,6 +1102,7 @@ const ( // SystemParametersInfo actions const ( SPI_GETNONCLIENTMETRICS = 0x0029 + SPI_GETHIGHCONTRAST = 0x0042 ) // Dialog styles @@ -1003,6 +1147,13 @@ const ( WA_INACTIVE = 0 ) +// Owner drawing actions +const ( + ODA_DRAWENTIRE = 0x0001 + ODA_FOCUS = 0x0002 + ODA_SELECT = 0x0004 +) + // Owner drawing states const ( ODS_CHECKED = 0x0001 @@ -1170,6 +1321,147 @@ const ( CF_WAVE = 12 ) +// ScrollBar constants +const ( + SB_HORZ = 0 + SB_VERT = 1 + SB_CTL = 2 + SB_BOTH = 3 +) + +// ScrollBar commands +const ( + SB_LINEUP = 0 + SB_LINELEFT = 0 + SB_LINEDOWN = 1 + SB_LINERIGHT = 1 + SB_PAGEUP = 2 + SB_PAGELEFT = 2 + SB_PAGEDOWN = 3 + SB_PAGERIGHT = 3 + SB_THUMBPOSITION = 4 + SB_THUMBTRACK = 5 + SB_TOP = 6 + SB_LEFT = 6 + SB_BOTTOM = 7 + SB_RIGHT = 7 + SB_ENDSCROLL = 8 +) + +// [Get|Set]ScrollInfo mask constants +const ( + SIF_RANGE = 1 + SIF_PAGE = 2 + SIF_POS = 4 + SIF_DISABLENOSCROLL = 8 + SIF_TRACKPOS = 16 + SIF_ALL = SIF_RANGE + SIF_PAGE + SIF_POS + SIF_TRACKPOS +) + +// DrawIconEx flags +const ( + DI_COMPAT = 0x0004 + DI_DEFAULTSIZE = 0x0008 + DI_IMAGE = 0x0002 + DI_MASK = 0x0001 + DI_NOMIRROR = 0x0010 + DI_NORMAL = DI_IMAGE | DI_MASK +) + +// WM_NCHITTEST constants +const ( + HTBORDER = 18 + HTBOTTOM = 15 + HTBOTTOMLEFT = 16 + HTBOTTOMRIGHT = 17 + HTCAPTION = 2 + HTCLIENT = 1 + HTCLOSE = 20 + HTERROR = -2 + HTGROWBOX = 4 + HTHELP = 21 + HTHSCROLL = 6 + HTLEFT = 10 + HTMENU = 5 + HTMAXBUTTON = 9 + HTMINBUTTON = 8 + HTNOWHERE = 0 + HTREDUCE = 8 + HTRIGHT = 11 + HTSIZE = 4 + HTSYSMENU = 3 + HTTOP = 12 + HTTOPLEFT = 13 + HTTOPRIGHT = 14 + HTTRANSPARENT = -1 + HTVSCROLL = 7 + HTZOOM = 9 +) + +// AnimateWindow flags +const ( + AW_ACTIVATE = 0x00020000 + AW_BLEND = 0x00080000 + AW_CENTER = 0x00000010 + AW_HIDE = 0x00010000 + AW_HOR_POSITIVE = 0x00000001 + AW_HOR_NEGATIVE = 0x00000002 + AW_SLIDE = 0x00040000 + AW_VER_POSITIVE = 0x00000004 + AW_VER_NEGATIVE = 0x00000008 +) + +// Session ending constants +const ( + ENDSESSION_CLOSEAPP = 0x00000001 + ENDSESSION_CRITICAL = 0x40000000 + ENDSESSION_LOGOFF = 0x80000000 +) + +// ChangeWindowMessageFilterEx constants +const ( + MSGFLT_RESET = 0 + MSGFLT_ALLOW = 1 + MSGFLT_DISALLOW = 2 + + MSGFLTINFO_NONE = 0 + MSGFLTINFO_ALREADYALLOWED_FORWND = 1 + MSGFLTINFO_ALREADYDISALLOWED_FORWND = 2 + MSGFLTINFO_ALLOWED_HIGHER = 3 +) + +// TRACKMOUSEEVENT flags +const ( + TME_CANCEL = 0x80000000 + TME_HOVER = 0x00000001 + TME_LEAVE = 0x00000002 + TME_NONCLIENT = 0x00000010 + TME_QUERY = 0x40000000 +) + +// HIGHCONTRAST flags +const ( + HCF_HIGHCONTRASTON = 0x00000001 + HCF_AVAILABLE = 0x00000002 + HCF_HOTKEYACTIVE = 0x00000004 + HCF_CONFIRMHOTKEY = 0x00000008 + HCF_HOTKEYSOUND = 0x00000010 + HCF_INDICATOR = 0x00000020 + HCF_HOTKEYAVAILABLE = 0x00000040 +) + +// EDITWORDBREAKPROC codes +const ( + WB_LEFT = 0 + WB_RIGHT = 1 + WB_ISDELIMITER = 2 +) + +type NMBCDROPDOWN struct { + Hdr NMHDR + RcButton RECT +} + type MONITORINFO struct { CbSize uint32 RcMonitor RECT @@ -1272,6 +1564,11 @@ type CREATESTRUCT struct { ExStyle uint32 } +type CHANGEFILTERSTRUCT struct { + size uint32 + extStatus uint32 +} + type WNDCLASSEX struct { CbSize uint32 Style uint32 @@ -1413,6 +1710,39 @@ type HARDWAREINPUT struct { Unused [16]byte } +type SCROLLINFO struct { + CbSize uint32 + FMask uint32 + NMin int32 + NMax int32 + NPage uint32 + NPos int32 + NTrackPos int32 +} + +type WINDOWPOS struct { + Hwnd HWND + HwndInsertAfter HWND + X int32 + Y int32 + Cx int32 + Cy int32 + Flags uint32 +} + +type TRACKMOUSEEVENT struct { + CbSize uint32 + DwFlags uint32 + HwndTrack HWND + DwHoverTime uint32 +} + +type HIGHCONTRAST struct { + CbSize uint32 + DwFlags uint32 + LpszDefaultScheme *uint16 +} + func GET_X_LPARAM(lp uintptr) int32 { return int32(int16(LOWORD(uint32(lp)))) } @@ -1423,240 +1753,327 @@ func GET_Y_LPARAM(lp uintptr) int32 { var ( // Library - libuser32 uintptr + libuser32 *windows.LazyDLL // Functions - adjustWindowRect uintptr - beginDeferWindowPos uintptr - beginPaint uintptr - callWindowProc uintptr - clientToScreen uintptr - closeClipboard uintptr - createDialogParam uintptr - createIconIndirect uintptr - createMenu uintptr - createPopupMenu uintptr - createWindowEx uintptr - deferWindowPos uintptr - defWindowProc uintptr - destroyIcon uintptr - destroyMenu uintptr - destroyWindow uintptr - dialogBoxParam uintptr - dispatchMessage uintptr - drawMenuBar uintptr - drawFocusRect uintptr - drawTextEx uintptr - emptyClipboard uintptr - enableWindow uintptr - endDeferWindowPos uintptr - endDialog uintptr - endPaint uintptr - enumChildWindows uintptr - findWindow uintptr - getAncestor uintptr - getCaretPos uintptr - getClientRect uintptr - getClipboardData uintptr - getCursorPos uintptr - getDC uintptr - getFocus uintptr - getKeyState uintptr - getMenuInfo uintptr - getMessage uintptr - getMonitorInfo uintptr - getParent uintptr - getRawInputData uintptr - getSysColor uintptr - getSysColorBrush uintptr - getSystemMetrics uintptr - getWindow uintptr - getWindowLong uintptr - getWindowLongPtr uintptr - getWindowPlacement uintptr - getWindowRect uintptr - insertMenuItem uintptr - invalidateRect uintptr - isChild uintptr - isClipboardFormatAvailable uintptr - isDialogMessage uintptr - isWindowEnabled uintptr - isWindowVisible uintptr - killTimer uintptr - loadCursor uintptr - loadIcon uintptr - loadImage uintptr - loadMenu uintptr - loadString uintptr - messageBeep uintptr - messageBox uintptr - monitorFromWindow uintptr - moveWindow uintptr - unregisterClass uintptr - openClipboard uintptr - peekMessage uintptr - postMessage uintptr - postQuitMessage uintptr - registerClassEx uintptr - registerRawInputDevices uintptr - registerWindowMessage uintptr - releaseCapture uintptr - releaseDC uintptr - removeMenu uintptr - screenToClient uintptr - sendDlgItemMessage uintptr - sendInput uintptr - sendMessage uintptr - setActiveWindow uintptr - setCapture uintptr - setClipboardData uintptr - setCursor uintptr - setCursorPos uintptr - setFocus uintptr - setForegroundWindow uintptr - setMenu uintptr - setMenuInfo uintptr - setMenuItemInfo uintptr - setParent uintptr - setRect uintptr - setTimer uintptr - setWindowLong uintptr - setWindowLongPtr uintptr - setWindowPlacement uintptr - setWindowPos uintptr - showWindow uintptr - systemParametersInfo uintptr - trackPopupMenuEx uintptr - translateMessage uintptr - updateWindow uintptr - windowFromPoint uintptr + addClipboardFormatListener *windows.LazyProc + adjustWindowRect *windows.LazyProc + attachThreadInput *windows.LazyProc + animateWindow *windows.LazyProc + beginDeferWindowPos *windows.LazyProc + beginPaint *windows.LazyProc + bringWindowToTop *windows.LazyProc + callWindowProc *windows.LazyProc + changeWindowMessageFilterEx *windows.LazyProc + checkMenuRadioItem *windows.LazyProc + clientToScreen *windows.LazyProc + closeClipboard *windows.LazyProc + createDialogParam *windows.LazyProc + createIconIndirect *windows.LazyProc + createMenu *windows.LazyProc + createPopupMenu *windows.LazyProc + createWindowEx *windows.LazyProc + deferWindowPos *windows.LazyProc + defWindowProc *windows.LazyProc + deleteMenu *windows.LazyProc + destroyIcon *windows.LazyProc + destroyMenu *windows.LazyProc + destroyWindow *windows.LazyProc + dialogBoxParam *windows.LazyProc + dispatchMessage *windows.LazyProc + drawIconEx *windows.LazyProc + drawMenuBar *windows.LazyProc + drawFocusRect *windows.LazyProc + drawTextEx *windows.LazyProc + emptyClipboard *windows.LazyProc + enableMenuItem *windows.LazyProc + enableWindow *windows.LazyProc + endDeferWindowPos *windows.LazyProc + endDialog *windows.LazyProc + endPaint *windows.LazyProc + enumChildWindows *windows.LazyProc + findWindow *windows.LazyProc + getActiveWindow *windows.LazyProc + getAncestor *windows.LazyProc + getCaretPos *windows.LazyProc + getClassName *windows.LazyProc + getClientRect *windows.LazyProc + getClipboardData *windows.LazyProc + getCursorPos *windows.LazyProc + getDC *windows.LazyProc + getDesktopWindow *windows.LazyProc + getDlgItem *windows.LazyProc + getDpiForWindow *windows.LazyProc + getFocus *windows.LazyProc + getForegroundWindow *windows.LazyProc + getIconInfo *windows.LazyProc + getKeyState *windows.LazyProc + getMenuCheckMarkDimensions *windows.LazyProc + getMenuInfo *windows.LazyProc + getMenuItemCount *windows.LazyProc + getMenuItemID *windows.LazyProc + getMenuItemInfo *windows.LazyProc + getMessage *windows.LazyProc + getMonitorInfo *windows.LazyProc + getParent *windows.LazyProc + getRawInputData *windows.LazyProc + getScrollInfo *windows.LazyProc + getSubMenu *windows.LazyProc + getSysColor *windows.LazyProc + getSysColorBrush *windows.LazyProc + getSystemMenu *windows.LazyProc + getSystemMetrics *windows.LazyProc + getSystemMetricsForDpi *windows.LazyProc + getWindow *windows.LazyProc + getWindowLong *windows.LazyProc + getWindowLongPtr *windows.LazyProc + getWindowPlacement *windows.LazyProc + getWindowRect *windows.LazyProc + getWindowThreadProcessId *windows.LazyProc + insertMenuItem *windows.LazyProc + invalidateRect *windows.LazyProc + isChild *windows.LazyProc + isClipboardFormatAvailable *windows.LazyProc + isDialogMessage *windows.LazyProc + isIconic *windows.LazyProc + isWindowEnabled *windows.LazyProc + isWindowVisible *windows.LazyProc + isZoomed *windows.LazyProc + killTimer *windows.LazyProc + loadCursor *windows.LazyProc + loadIcon *windows.LazyProc + loadImage *windows.LazyProc + loadMenu *windows.LazyProc + loadString *windows.LazyProc + messageBeep *windows.LazyProc + messageBox *windows.LazyProc + monitorFromWindow *windows.LazyProc + moveWindow *windows.LazyProc + notifyWinEvent *windows.LazyProc + unregisterClass *windows.LazyProc + openClipboard *windows.LazyProc + peekMessage *windows.LazyProc + postMessage *windows.LazyProc + postQuitMessage *windows.LazyProc + redrawWindow *windows.LazyProc + registerClassEx *windows.LazyProc + registerRawInputDevices *windows.LazyProc + registerWindowMessage *windows.LazyProc + releaseCapture *windows.LazyProc + releaseDC *windows.LazyProc + removeMenu *windows.LazyProc + screenToClient *windows.LazyProc + sendDlgItemMessage *windows.LazyProc + sendInput *windows.LazyProc + sendMessage *windows.LazyProc + setActiveWindow *windows.LazyProc + setCapture *windows.LazyProc + setClipboardData *windows.LazyProc + setCursor *windows.LazyProc + setCursorPos *windows.LazyProc + setFocus *windows.LazyProc + setForegroundWindow *windows.LazyProc + setMenu *windows.LazyProc + setMenuDefaultItem *windows.LazyProc + setMenuInfo *windows.LazyProc + setMenuItemBitmaps *windows.LazyProc + setMenuItemInfo *windows.LazyProc + setParent *windows.LazyProc + setRect *windows.LazyProc + setScrollInfo *windows.LazyProc + setTimer *windows.LazyProc + setWinEventHook *windows.LazyProc + setWindowLong *windows.LazyProc + setWindowLongPtr *windows.LazyProc + setWindowPlacement *windows.LazyProc + setWindowPos *windows.LazyProc + showWindow *windows.LazyProc + systemParametersInfo *windows.LazyProc + trackMouseEvent *windows.LazyProc + trackPopupMenu *windows.LazyProc + trackPopupMenuEx *windows.LazyProc + translateMessage *windows.LazyProc + unhookWinEvent *windows.LazyProc + updateWindow *windows.LazyProc + windowFromDC *windows.LazyProc + windowFromPoint *windows.LazyProc ) func init() { is64bit := unsafe.Sizeof(uintptr(0)) == 8 // Library - libuser32 = MustLoadLibrary("user32.dll") + libuser32 = windows.NewLazySystemDLL("user32.dll") // Functions - adjustWindowRect = MustGetProcAddress(libuser32, "AdjustWindowRect") - beginDeferWindowPos = MustGetProcAddress(libuser32, "BeginDeferWindowPos") - beginPaint = MustGetProcAddress(libuser32, "BeginPaint") - callWindowProc = MustGetProcAddress(libuser32, "CallWindowProcW") - clientToScreen = MustGetProcAddress(libuser32, "ClientToScreen") - closeClipboard = MustGetProcAddress(libuser32, "CloseClipboard") - createDialogParam = MustGetProcAddress(libuser32, "CreateDialogParamW") - createIconIndirect = MustGetProcAddress(libuser32, "CreateIconIndirect") - createMenu = MustGetProcAddress(libuser32, "CreateMenu") - createPopupMenu = MustGetProcAddress(libuser32, "CreatePopupMenu") - createWindowEx = MustGetProcAddress(libuser32, "CreateWindowExW") - deferWindowPos = MustGetProcAddress(libuser32, "DeferWindowPos") - defWindowProc = MustGetProcAddress(libuser32, "DefWindowProcW") - destroyIcon = MustGetProcAddress(libuser32, "DestroyIcon") - destroyMenu = MustGetProcAddress(libuser32, "DestroyMenu") - destroyWindow = MustGetProcAddress(libuser32, "DestroyWindow") - dialogBoxParam = MustGetProcAddress(libuser32, "DialogBoxParamW") - dispatchMessage = MustGetProcAddress(libuser32, "DispatchMessageW") - drawFocusRect = MustGetProcAddress(libuser32, "DrawFocusRect") - drawMenuBar = MustGetProcAddress(libuser32, "DrawMenuBar") - drawTextEx = MustGetProcAddress(libuser32, "DrawTextExW") - emptyClipboard = MustGetProcAddress(libuser32, "EmptyClipboard") - enableWindow = MustGetProcAddress(libuser32, "EnableWindow") - endDeferWindowPos = MustGetProcAddress(libuser32, "EndDeferWindowPos") - endDialog = MustGetProcAddress(libuser32, "EndDialog") - endPaint = MustGetProcAddress(libuser32, "EndPaint") - enumChildWindows = MustGetProcAddress(libuser32, "EnumChildWindows") - findWindow = MustGetProcAddress(libuser32, "FindWindowW") - getAncestor = MustGetProcAddress(libuser32, "GetAncestor") - getCaretPos = MustGetProcAddress(libuser32, "GetCaretPos") - getClientRect = MustGetProcAddress(libuser32, "GetClientRect") - getClipboardData = MustGetProcAddress(libuser32, "GetClipboardData") - getCursorPos = MustGetProcAddress(libuser32, "GetCursorPos") - getDC = MustGetProcAddress(libuser32, "GetDC") - getFocus = MustGetProcAddress(libuser32, "GetFocus") - getKeyState = MustGetProcAddress(libuser32, "GetKeyState") - getMenuInfo = MustGetProcAddress(libuser32, "GetMenuInfo") - getMessage = MustGetProcAddress(libuser32, "GetMessageW") - getMonitorInfo = MustGetProcAddress(libuser32, "GetMonitorInfoW") - getParent = MustGetProcAddress(libuser32, "GetParent") - getRawInputData = MustGetProcAddress(libuser32, "GetRawInputData") - getSysColor = MustGetProcAddress(libuser32, "GetSysColor") - getSysColorBrush = MustGetProcAddress(libuser32, "GetSysColorBrush") - getSystemMetrics = MustGetProcAddress(libuser32, "GetSystemMetrics") - getWindow = MustGetProcAddress(libuser32, "GetWindow") - getWindowLong = MustGetProcAddress(libuser32, "GetWindowLongW") + addClipboardFormatListener = libuser32.NewProc("AddClipboardFormatListener") + adjustWindowRect = libuser32.NewProc("AdjustWindowRect") + attachThreadInput = libuser32.NewProc("AttachThreadInput") + animateWindow = libuser32.NewProc("AnimateWindow") + beginDeferWindowPos = libuser32.NewProc("BeginDeferWindowPos") + beginPaint = libuser32.NewProc("BeginPaint") + bringWindowToTop = libuser32.NewProc("BringWindowToTop") + callWindowProc = libuser32.NewProc("CallWindowProcW") + changeWindowMessageFilterEx = libuser32.NewProc("ChangeWindowMessageFilterEx") + checkMenuRadioItem = libuser32.NewProc("CheckMenuRadioItem") + clientToScreen = libuser32.NewProc("ClientToScreen") + closeClipboard = libuser32.NewProc("CloseClipboard") + createDialogParam = libuser32.NewProc("CreateDialogParamW") + createIconIndirect = libuser32.NewProc("CreateIconIndirect") + createMenu = libuser32.NewProc("CreateMenu") + createPopupMenu = libuser32.NewProc("CreatePopupMenu") + createWindowEx = libuser32.NewProc("CreateWindowExW") + deferWindowPos = libuser32.NewProc("DeferWindowPos") + defWindowProc = libuser32.NewProc("DefWindowProcW") + deleteMenu = libuser32.NewProc("DeleteMenu") + destroyIcon = libuser32.NewProc("DestroyIcon") + destroyMenu = libuser32.NewProc("DestroyMenu") + destroyWindow = libuser32.NewProc("DestroyWindow") + dialogBoxParam = libuser32.NewProc("DialogBoxParamW") + dispatchMessage = libuser32.NewProc("DispatchMessageW") + drawIconEx = libuser32.NewProc("DrawIconEx") + drawFocusRect = libuser32.NewProc("DrawFocusRect") + drawMenuBar = libuser32.NewProc("DrawMenuBar") + drawTextEx = libuser32.NewProc("DrawTextExW") + emptyClipboard = libuser32.NewProc("EmptyClipboard") + enableMenuItem = libuser32.NewProc("EnableMenuItem") + enableWindow = libuser32.NewProc("EnableWindow") + endDeferWindowPos = libuser32.NewProc("EndDeferWindowPos") + endDialog = libuser32.NewProc("EndDialog") + endPaint = libuser32.NewProc("EndPaint") + enumChildWindows = libuser32.NewProc("EnumChildWindows") + findWindow = libuser32.NewProc("FindWindowW") + getActiveWindow = libuser32.NewProc("GetActiveWindow") + getAncestor = libuser32.NewProc("GetAncestor") + getCaretPos = libuser32.NewProc("GetCaretPos") + getClassName = libuser32.NewProc("GetClassNameW") + getClientRect = libuser32.NewProc("GetClientRect") + getClipboardData = libuser32.NewProc("GetClipboardData") + getCursorPos = libuser32.NewProc("GetCursorPos") + getDC = libuser32.NewProc("GetDC") + getDesktopWindow = libuser32.NewProc("GetDesktopWindow") + getDlgItem = libuser32.NewProc("GetDlgItem") + getDpiForWindow = libuser32.NewProc("GetDpiForWindow") + getFocus = libuser32.NewProc("GetFocus") + getForegroundWindow = libuser32.NewProc("GetForegroundWindow") + getIconInfo = libuser32.NewProc("GetIconInfo") + getKeyState = libuser32.NewProc("GetKeyState") + getMenuCheckMarkDimensions = libuser32.NewProc("GetMenuCheckMarkDimensions") + getMenuInfo = libuser32.NewProc("GetMenuInfo") + getMenuItemCount = libuser32.NewProc("GetMenuItemCount") + getMenuItemID = libuser32.NewProc("GetMenuItemID") + getMenuItemInfo = libuser32.NewProc("GetMenuItemInfoW") + getMessage = libuser32.NewProc("GetMessageW") + getMonitorInfo = libuser32.NewProc("GetMonitorInfoW") + getParent = libuser32.NewProc("GetParent") + getRawInputData = libuser32.NewProc("GetRawInputData") + getScrollInfo = libuser32.NewProc("GetScrollInfo") + getSubMenu = libuser32.NewProc("GetSubMenu") + getSysColor = libuser32.NewProc("GetSysColor") + getSysColorBrush = libuser32.NewProc("GetSysColorBrush") + getSystemMenu = libuser32.NewProc("GetSystemMenu") + getSystemMetrics = libuser32.NewProc("GetSystemMetrics") + getSystemMetricsForDpi = libuser32.NewProc("GetSystemMetricsForDpi") + getWindow = libuser32.NewProc("GetWindow") + getWindowLong = libuser32.NewProc("GetWindowLongW") // On 32 bit GetWindowLongPtrW is not available if is64bit { - getWindowLongPtr = MustGetProcAddress(libuser32, "GetWindowLongPtrW") + getWindowLongPtr = libuser32.NewProc("GetWindowLongPtrW") } else { - getWindowLongPtr = MustGetProcAddress(libuser32, "GetWindowLongW") + getWindowLongPtr = libuser32.NewProc("GetWindowLongW") } - getWindowPlacement = MustGetProcAddress(libuser32, "GetWindowPlacement") - getWindowRect = MustGetProcAddress(libuser32, "GetWindowRect") - insertMenuItem = MustGetProcAddress(libuser32, "InsertMenuItemW") - invalidateRect = MustGetProcAddress(libuser32, "InvalidateRect") - isChild = MustGetProcAddress(libuser32, "IsChild") - isClipboardFormatAvailable = MustGetProcAddress(libuser32, "IsClipboardFormatAvailable") - isDialogMessage = MustGetProcAddress(libuser32, "IsDialogMessageW") - isWindowEnabled = MustGetProcAddress(libuser32, "IsWindowEnabled") - isWindowVisible = MustGetProcAddress(libuser32, "IsWindowVisible") - killTimer = MustGetProcAddress(libuser32, "KillTimer") - loadCursor = MustGetProcAddress(libuser32, "LoadCursorW") - loadIcon = MustGetProcAddress(libuser32, "LoadIconW") - loadImage = MustGetProcAddress(libuser32, "LoadImageW") - loadMenu = MustGetProcAddress(libuser32, "LoadMenuW") - loadString = MustGetProcAddress(libuser32, "LoadStringW") - messageBeep = MustGetProcAddress(libuser32, "MessageBeep") - messageBox = MustGetProcAddress(libuser32, "MessageBoxW") - monitorFromWindow = MustGetProcAddress(libuser32, "MonitorFromWindow") - moveWindow = MustGetProcAddress(libuser32, "MoveWindow") - unregisterClass = MustGetProcAddress(libuser32, "UnregisterClassW") - openClipboard = MustGetProcAddress(libuser32, "OpenClipboard") - peekMessage = MustGetProcAddress(libuser32, "PeekMessageW") - postMessage = MustGetProcAddress(libuser32, "PostMessageW") - postQuitMessage = MustGetProcAddress(libuser32, "PostQuitMessage") - registerClassEx = MustGetProcAddress(libuser32, "RegisterClassExW") - registerRawInputDevices = MustGetProcAddress(libuser32, "RegisterRawInputDevices") - registerWindowMessage = MustGetProcAddress(libuser32, "RegisterWindowMessageW") - releaseCapture = MustGetProcAddress(libuser32, "ReleaseCapture") - releaseDC = MustGetProcAddress(libuser32, "ReleaseDC") - removeMenu = MustGetProcAddress(libuser32, "RemoveMenu") - screenToClient = MustGetProcAddress(libuser32, "ScreenToClient") - sendDlgItemMessage = MustGetProcAddress(libuser32, "SendDlgItemMessageW") - sendInput = MustGetProcAddress(libuser32, "SendInput") - sendMessage = MustGetProcAddress(libuser32, "SendMessageW") - setActiveWindow = MustGetProcAddress(libuser32, "SetActiveWindow") - setCapture = MustGetProcAddress(libuser32, "SetCapture") - setClipboardData = MustGetProcAddress(libuser32, "SetClipboardData") - setCursor = MustGetProcAddress(libuser32, "SetCursor") - setCursorPos = MustGetProcAddress(libuser32, "SetCursorPos") - setFocus = MustGetProcAddress(libuser32, "SetFocus") - setForegroundWindow = MustGetProcAddress(libuser32, "SetForegroundWindow") - setMenu = MustGetProcAddress(libuser32, "SetMenu") - setMenuInfo = MustGetProcAddress(libuser32, "SetMenuInfo") - setMenuItemInfo = MustGetProcAddress(libuser32, "SetMenuItemInfoW") - setRect = MustGetProcAddress(libuser32, "SetRect") - setParent = MustGetProcAddress(libuser32, "SetParent") - setTimer = MustGetProcAddress(libuser32, "SetTimer") - setWindowLong = MustGetProcAddress(libuser32, "SetWindowLongW") + getWindowPlacement = libuser32.NewProc("GetWindowPlacement") + getWindowRect = libuser32.NewProc("GetWindowRect") + getWindowThreadProcessId = libuser32.NewProc("GetWindowThreadProcessId") + insertMenuItem = libuser32.NewProc("InsertMenuItemW") + invalidateRect = libuser32.NewProc("InvalidateRect") + isChild = libuser32.NewProc("IsChild") + isClipboardFormatAvailable = libuser32.NewProc("IsClipboardFormatAvailable") + isDialogMessage = libuser32.NewProc("IsDialogMessageW") + isIconic = libuser32.NewProc("IsIconic") + isWindowEnabled = libuser32.NewProc("IsWindowEnabled") + isWindowVisible = libuser32.NewProc("IsWindowVisible") + isZoomed = libuser32.NewProc("IsZoomed") + killTimer = libuser32.NewProc("KillTimer") + loadCursor = libuser32.NewProc("LoadCursorW") + loadIcon = libuser32.NewProc("LoadIconW") + loadImage = libuser32.NewProc("LoadImageW") + loadMenu = libuser32.NewProc("LoadMenuW") + loadString = libuser32.NewProc("LoadStringW") + messageBeep = libuser32.NewProc("MessageBeep") + messageBox = libuser32.NewProc("MessageBoxW") + monitorFromWindow = libuser32.NewProc("MonitorFromWindow") + moveWindow = libuser32.NewProc("MoveWindow") + notifyWinEvent = libuser32.NewProc("NotifyWinEvent") + unregisterClass = libuser32.NewProc("UnregisterClassW") + openClipboard = libuser32.NewProc("OpenClipboard") + peekMessage = libuser32.NewProc("PeekMessageW") + postMessage = libuser32.NewProc("PostMessageW") + postQuitMessage = libuser32.NewProc("PostQuitMessage") + redrawWindow = libuser32.NewProc("RedrawWindow") + registerClassEx = libuser32.NewProc("RegisterClassExW") + registerRawInputDevices = libuser32.NewProc("RegisterRawInputDevices") + registerWindowMessage = libuser32.NewProc("RegisterWindowMessageW") + releaseCapture = libuser32.NewProc("ReleaseCapture") + releaseDC = libuser32.NewProc("ReleaseDC") + removeMenu = libuser32.NewProc("RemoveMenu") + screenToClient = libuser32.NewProc("ScreenToClient") + sendDlgItemMessage = libuser32.NewProc("SendDlgItemMessageW") + sendInput = libuser32.NewProc("SendInput") + sendMessage = libuser32.NewProc("SendMessageW") + setActiveWindow = libuser32.NewProc("SetActiveWindow") + setCapture = libuser32.NewProc("SetCapture") + setClipboardData = libuser32.NewProc("SetClipboardData") + setCursor = libuser32.NewProc("SetCursor") + setCursorPos = libuser32.NewProc("SetCursorPos") + setFocus = libuser32.NewProc("SetFocus") + setForegroundWindow = libuser32.NewProc("SetForegroundWindow") + setMenu = libuser32.NewProc("SetMenu") + setMenuDefaultItem = libuser32.NewProc("SetMenuDefaultItem") + setMenuInfo = libuser32.NewProc("SetMenuInfo") + setMenuItemBitmaps = libuser32.NewProc("SetMenuItemBitmaps") + setMenuItemInfo = libuser32.NewProc("SetMenuItemInfoW") + setRect = libuser32.NewProc("SetRect") + setParent = libuser32.NewProc("SetParent") + setScrollInfo = libuser32.NewProc("SetScrollInfo") + setTimer = libuser32.NewProc("SetTimer") + setWinEventHook = libuser32.NewProc("SetWinEventHook") + setWindowLong = libuser32.NewProc("SetWindowLongW") // On 32 bit SetWindowLongPtrW is not available if is64bit { - setWindowLongPtr = MustGetProcAddress(libuser32, "SetWindowLongPtrW") + setWindowLongPtr = libuser32.NewProc("SetWindowLongPtrW") } else { - setWindowLongPtr = MustGetProcAddress(libuser32, "SetWindowLongW") + setWindowLongPtr = libuser32.NewProc("SetWindowLongW") } - setWindowPlacement = MustGetProcAddress(libuser32, "SetWindowPlacement") - setWindowPos = MustGetProcAddress(libuser32, "SetWindowPos") - showWindow = MustGetProcAddress(libuser32, "ShowWindow") - systemParametersInfo = MustGetProcAddress(libuser32, "SystemParametersInfoW") - trackPopupMenuEx = MustGetProcAddress(libuser32, "TrackPopupMenuEx") - translateMessage = MustGetProcAddress(libuser32, "TranslateMessage") - updateWindow = MustGetProcAddress(libuser32, "UpdateWindow") - windowFromPoint = MustGetProcAddress(libuser32, "WindowFromPoint") + setWindowPlacement = libuser32.NewProc("SetWindowPlacement") + setWindowPos = libuser32.NewProc("SetWindowPos") + showWindow = libuser32.NewProc("ShowWindow") + systemParametersInfo = libuser32.NewProc("SystemParametersInfoW") + trackMouseEvent = libuser32.NewProc("TrackMouseEvent") + trackPopupMenu = libuser32.NewProc("TrackPopupMenu") + trackPopupMenuEx = libuser32.NewProc("TrackPopupMenuEx") + translateMessage = libuser32.NewProc("TranslateMessage") + unhookWinEvent = libuser32.NewProc("UnhookWinEvent") + updateWindow = libuser32.NewProc("UpdateWindow") + windowFromDC = libuser32.NewProc("WindowFromDC") + windowFromPoint = libuser32.NewProc("WindowFromPoint") +} + +func AddClipboardFormatListener(hwnd HWND) bool { + if addClipboardFormatListener.Find() != nil { + return false + } + + ret, _, _ := syscall.Syscall(addClipboardFormatListener.Addr(), 1, + uintptr(hwnd), + 0, + 0) + + return ret != 0 } func AdjustWindowRect(lpRect *RECT, dwStyle uint32, bMenu bool) bool { - ret, _, _ := syscall.Syscall(adjustWindowRect, 3, + ret, _, _ := syscall.Syscall(adjustWindowRect.Addr(), 3, uintptr(unsafe.Pointer(lpRect)), uintptr(dwStyle), uintptr(BoolToBOOL(bMenu))) @@ -1664,8 +2081,26 @@ func AdjustWindowRect(lpRect *RECT, dwStyle uint32, bMenu bool) bool { return ret != 0 } +func AttachThreadInput(idAttach int32, idAttachTo int32, fAttach bool) bool { + ret, _, _ := syscall.Syscall(attachThreadInput.Addr(), 3, + uintptr(idAttach), + uintptr(idAttachTo), + uintptr(BoolToBOOL(fAttach))) + + return ret != 0 +} + +func AnimateWindow(hwnd HWND, dwTime, dwFlags uint32) bool { + ret, _, _ := syscall.Syscall(animateWindow.Addr(), 3, + uintptr(hwnd), + uintptr(dwTime), + uintptr(dwFlags)) + + return ret != 0 +} + func BeginDeferWindowPos(nNumWindows int32) HDWP { - ret, _, _ := syscall.Syscall(beginDeferWindowPos, 1, + ret, _, _ := syscall.Syscall(beginDeferWindowPos.Addr(), 1, uintptr(nNumWindows), 0, 0) @@ -1673,8 +2108,17 @@ func BeginDeferWindowPos(nNumWindows int32) HDWP { return HDWP(ret) } +func GetWindowThreadProcessId(hwnd HWND, processId *uint32) uint32 { + ret, _, _ := syscall.Syscall(getWindowThreadProcessId.Addr(), 2, + uintptr(hwnd), + uintptr(unsafe.Pointer(processId)), + 0) + + return uint32(ret) +} + func BeginPaint(hwnd HWND, lpPaint *PAINTSTRUCT) HDC { - ret, _, _ := syscall.Syscall(beginPaint, 2, + ret, _, _ := syscall.Syscall(beginPaint.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(lpPaint)), 0) @@ -1682,8 +2126,16 @@ func BeginPaint(hwnd HWND, lpPaint *PAINTSTRUCT) HDC { return HDC(ret) } +func BringWindowToTop(hwnd HWND) bool { + ret, _, _ := syscall.Syscall(bringWindowToTop.Addr(), 1, + uintptr(hwnd), + 0, + 0) + return ret != 0 +} + func CallWindowProc(lpPrevWndFunc uintptr, hWnd HWND, Msg uint32, wParam, lParam uintptr) uintptr { - ret, _, _ := syscall.Syscall6(callWindowProc, 5, + ret, _, _ := syscall.Syscall6(callWindowProc.Addr(), 5, lpPrevWndFunc, uintptr(hWnd), uintptr(Msg), @@ -1694,8 +2146,31 @@ func CallWindowProc(lpPrevWndFunc uintptr, hWnd HWND, Msg uint32, wParam, lParam return ret } +func ChangeWindowMessageFilterEx(hwnd HWND, msg uint32, action uint32, changeFilterStruct *CHANGEFILTERSTRUCT) bool { + ret, _, _ := syscall.Syscall6(changeWindowMessageFilterEx.Addr(), 4, + uintptr(hwnd), + uintptr(msg), + uintptr(action), + uintptr(unsafe.Pointer(changeFilterStruct)), + 0, + 0) + return ret != 0 +} + +func CheckMenuRadioItem(hmenu HMENU, first, last, check, flags uint32) bool { + ret, _, _ := syscall.Syscall6(checkMenuRadioItem.Addr(), 5, + uintptr(hmenu), + uintptr(first), + uintptr(last), + uintptr(check), + uintptr(flags), + 0) + + return ret != 0 +} + func ClientToScreen(hwnd HWND, lpPoint *POINT) bool { - ret, _, _ := syscall.Syscall(clientToScreen, 2, + ret, _, _ := syscall.Syscall(clientToScreen.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(lpPoint)), 0) @@ -1704,7 +2179,7 @@ func ClientToScreen(hwnd HWND, lpPoint *POINT) bool { } func CloseClipboard() bool { - ret, _, _ := syscall.Syscall(closeClipboard, 0, + ret, _, _ := syscall.Syscall(closeClipboard.Addr(), 0, 0, 0, 0) @@ -1714,7 +2189,7 @@ func CloseClipboard() bool { func CreateDialogParam(instRes HINSTANCE, name *uint16, parent HWND, proc, param uintptr) HWND { - ret, _, _ := syscall.Syscall6(createDialogParam, 5, + ret, _, _ := syscall.Syscall6(createDialogParam.Addr(), 5, uintptr(instRes), uintptr(unsafe.Pointer(name)), uintptr(parent), @@ -1726,7 +2201,7 @@ func CreateDialogParam(instRes HINSTANCE, name *uint16, parent HWND, } func CreateIconIndirect(lpiconinfo *ICONINFO) HICON { - ret, _, _ := syscall.Syscall(createIconIndirect, 1, + ret, _, _ := syscall.Syscall(createIconIndirect.Addr(), 1, uintptr(unsafe.Pointer(lpiconinfo)), 0, 0) @@ -1735,7 +2210,7 @@ func CreateIconIndirect(lpiconinfo *ICONINFO) HICON { } func CreateMenu() HMENU { - ret, _, _ := syscall.Syscall(createMenu, 0, + ret, _, _ := syscall.Syscall(createMenu.Addr(), 0, 0, 0, 0) @@ -1744,7 +2219,7 @@ func CreateMenu() HMENU { } func CreatePopupMenu() HMENU { - ret, _, _ := syscall.Syscall(createPopupMenu, 0, + ret, _, _ := syscall.Syscall(createPopupMenu.Addr(), 0, 0, 0, 0) @@ -1753,7 +2228,7 @@ func CreatePopupMenu() HMENU { } func CreateWindowEx(dwExStyle uint32, lpClassName, lpWindowName *uint16, dwStyle uint32, x, y, nWidth, nHeight int32, hWndParent HWND, hMenu HMENU, hInstance HINSTANCE, lpParam unsafe.Pointer) HWND { - ret, _, _ := syscall.Syscall12(createWindowEx, 12, + ret, _, _ := syscall.Syscall12(createWindowEx.Addr(), 12, uintptr(dwExStyle), uintptr(unsafe.Pointer(lpClassName)), uintptr(unsafe.Pointer(lpWindowName)), @@ -1771,7 +2246,7 @@ func CreateWindowEx(dwExStyle uint32, lpClassName, lpWindowName *uint16, dwStyle } func DeferWindowPos(hWinPosInfo HDWP, hWnd, hWndInsertAfter HWND, x, y, cx, cy int32, uFlags uint32) HDWP { - ret, _, _ := syscall.Syscall9(deferWindowPos, 8, + ret, _, _ := syscall.Syscall9(deferWindowPos.Addr(), 8, uintptr(hWinPosInfo), uintptr(hWnd), uintptr(hWndInsertAfter), @@ -1786,7 +2261,7 @@ func DeferWindowPos(hWinPosInfo HDWP, hWnd, hWndInsertAfter HWND, x, y, cx, cy i } func DefWindowProc(hWnd HWND, Msg uint32, wParam, lParam uintptr) uintptr { - ret, _, _ := syscall.Syscall6(defWindowProc, 4, + ret, _, _ := syscall.Syscall6(defWindowProc.Addr(), 4, uintptr(hWnd), uintptr(Msg), wParam, @@ -1797,8 +2272,17 @@ func DefWindowProc(hWnd HWND, Msg uint32, wParam, lParam uintptr) uintptr { return ret } +func DeleteMenu(hMenu HMENU, uPosition uint32, uFlags uint32) bool { + ret, _, _ := syscall.Syscall(deleteMenu.Addr(), 3, + uintptr(hMenu), + uintptr(uPosition), + uintptr(uFlags)) + + return ret != 0 +} + func DestroyIcon(hIcon HICON) bool { - ret, _, _ := syscall.Syscall(destroyIcon, 1, + ret, _, _ := syscall.Syscall(destroyIcon.Addr(), 1, uintptr(hIcon), 0, 0) @@ -1807,7 +2291,7 @@ func DestroyIcon(hIcon HICON) bool { } func DestroyMenu(hMenu HMENU) bool { - ret, _, _ := syscall.Syscall(destroyMenu, 1, + ret, _, _ := syscall.Syscall(destroyMenu.Addr(), 1, uintptr(hMenu), 0, 0) @@ -1816,7 +2300,7 @@ func DestroyMenu(hMenu HMENU) bool { } func DestroyWindow(hWnd HWND) bool { - ret, _, _ := syscall.Syscall(destroyWindow, 1, + ret, _, _ := syscall.Syscall(destroyWindow.Addr(), 1, uintptr(hWnd), 0, 0) @@ -1825,7 +2309,7 @@ func DestroyWindow(hWnd HWND) bool { } func DialogBoxParam(instRes HINSTANCE, name *uint16, parent HWND, proc, param uintptr) int { - ret, _, _ := syscall.Syscall6(dialogBoxParam, 5, + ret, _, _ := syscall.Syscall6(dialogBoxParam.Addr(), 5, uintptr(instRes), uintptr(unsafe.Pointer(name)), uintptr(parent), @@ -1837,7 +2321,7 @@ func DialogBoxParam(instRes HINSTANCE, name *uint16, parent HWND, proc, param ui } func DispatchMessage(msg *MSG) uintptr { - ret, _, _ := syscall.Syscall(dispatchMessage, 1, + ret, _, _ := syscall.Syscall(dispatchMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0) @@ -1846,7 +2330,7 @@ func DispatchMessage(msg *MSG) uintptr { } func DrawFocusRect(hDC HDC, lprc *RECT) bool { - ret, _, _ := syscall.Syscall(drawFocusRect, 2, + ret, _, _ := syscall.Syscall(drawFocusRect.Addr(), 2, uintptr(hDC), uintptr(unsafe.Pointer(lprc)), 0) @@ -1854,8 +2338,23 @@ func DrawFocusRect(hDC HDC, lprc *RECT) bool { return ret != 0 } +func DrawIconEx(hdc HDC, xLeft, yTop int32, hIcon HICON, cxWidth, cyWidth int32, istepIfAniCur uint32, hbrFlickerFreeDraw HBRUSH, diFlags uint32) bool { + ret, _, _ := syscall.Syscall9(drawIconEx.Addr(), 9, + uintptr(hdc), + uintptr(xLeft), + uintptr(yTop), + uintptr(hIcon), + uintptr(cxWidth), + uintptr(cyWidth), + uintptr(istepIfAniCur), + uintptr(hbrFlickerFreeDraw), + uintptr(diFlags)) + + return ret != 0 +} + func DrawMenuBar(hWnd HWND) bool { - ret, _, _ := syscall.Syscall(drawMenuBar, 1, + ret, _, _ := syscall.Syscall(drawMenuBar.Addr(), 1, uintptr(hWnd), 0, 0) @@ -1864,7 +2363,7 @@ func DrawMenuBar(hWnd HWND) bool { } func DrawTextEx(hdc HDC, lpchText *uint16, cchText int32, lprc *RECT, dwDTFormat uint32, lpDTParams *DRAWTEXTPARAMS) int32 { - ret, _, _ := syscall.Syscall6(drawTextEx, 6, + ret, _, _ := syscall.Syscall6(drawTextEx.Addr(), 6, uintptr(hdc), uintptr(unsafe.Pointer(lpchText)), uintptr(cchText), @@ -1876,7 +2375,7 @@ func DrawTextEx(hdc HDC, lpchText *uint16, cchText int32, lprc *RECT, dwDTFormat } func EmptyClipboard() bool { - ret, _, _ := syscall.Syscall(emptyClipboard, 0, + ret, _, _ := syscall.Syscall(emptyClipboard.Addr(), 0, 0, 0, 0) @@ -1884,8 +2383,17 @@ func EmptyClipboard() bool { return ret != 0 } +func EnableMenuItem(hMenu HMENU, uIDEnableItem uint32, uEnable uint32) bool { + ret, _, _ := syscall.Syscall(enableMenuItem.Addr(), 3, + uintptr(hMenu), + uintptr(uIDEnableItem), + uintptr(uEnable)) + + return ret != 0 +} + func EnableWindow(hWnd HWND, bEnable bool) bool { - ret, _, _ := syscall.Syscall(enableWindow, 2, + ret, _, _ := syscall.Syscall(enableWindow.Addr(), 2, uintptr(hWnd), uintptr(BoolToBOOL(bEnable)), 0) @@ -1894,7 +2402,7 @@ func EnableWindow(hWnd HWND, bEnable bool) bool { } func EndDeferWindowPos(hWinPosInfo HDWP) bool { - ret, _, _ := syscall.Syscall(endDeferWindowPos, 1, + ret, _, _ := syscall.Syscall(endDeferWindowPos.Addr(), 1, uintptr(hWinPosInfo), 0, 0) @@ -1903,7 +2411,7 @@ func EndDeferWindowPos(hWinPosInfo HDWP) bool { } func EndDialog(hwnd HWND, result int) bool { - ret, _, _ := syscall.Syscall(endDialog, 2, + ret, _, _ := syscall.Syscall(endDialog.Addr(), 2, uintptr(hwnd), uintptr(result), 0) @@ -1912,7 +2420,7 @@ func EndDialog(hwnd HWND, result int) bool { } func EndPaint(hwnd HWND, lpPaint *PAINTSTRUCT) bool { - ret, _, _ := syscall.Syscall(endPaint, 2, + ret, _, _ := syscall.Syscall(endPaint.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(lpPaint)), 0) @@ -1921,7 +2429,7 @@ func EndPaint(hwnd HWND, lpPaint *PAINTSTRUCT) bool { } func EnumChildWindows(hWndParent HWND, lpEnumFunc, lParam uintptr) bool { - ret, _, _ := syscall.Syscall(enumChildWindows, 3, + ret, _, _ := syscall.Syscall(enumChildWindows.Addr(), 3, uintptr(hWndParent), lpEnumFunc, lParam) @@ -1930,7 +2438,7 @@ func EnumChildWindows(hWndParent HWND, lpEnumFunc, lParam uintptr) bool { } func FindWindow(lpClassName, lpWindowName *uint16) HWND { - ret, _, _ := syscall.Syscall(findWindow, 2, + ret, _, _ := syscall.Syscall(findWindow.Addr(), 2, uintptr(unsafe.Pointer(lpClassName)), uintptr(unsafe.Pointer(lpWindowName)), 0) @@ -1938,8 +2446,17 @@ func FindWindow(lpClassName, lpWindowName *uint16) HWND { return HWND(ret) } +func GetActiveWindow() HWND { + ret, _, _ := syscall.Syscall(getActiveWindow.Addr(), 0, + 0, + 0, + 0) + + return HWND(ret) +} + func GetAncestor(hWnd HWND, gaFlags uint32) HWND { - ret, _, _ := syscall.Syscall(getAncestor, 2, + ret, _, _ := syscall.Syscall(getAncestor.Addr(), 2, uintptr(hWnd), uintptr(gaFlags), 0) @@ -1948,7 +2465,7 @@ func GetAncestor(hWnd HWND, gaFlags uint32) HWND { } func GetCaretPos(lpPoint *POINT) bool { - ret, _, _ := syscall.Syscall(getCaretPos, 1, + ret, _, _ := syscall.Syscall(getCaretPos.Addr(), 1, uintptr(unsafe.Pointer(lpPoint)), 0, 0) @@ -1956,8 +2473,19 @@ func GetCaretPos(lpPoint *POINT) bool { return ret != 0 } +func GetClassName(hWnd HWND, className *uint16, maxCount int) (int, error) { + ret, _, e := syscall.Syscall(getClassName.Addr(), 3, + uintptr(hWnd), + uintptr(unsafe.Pointer(className)), + uintptr(maxCount)) + if ret == 0 { + return 0, e + } + return int(ret), nil +} + func GetClientRect(hWnd HWND, rect *RECT) bool { - ret, _, _ := syscall.Syscall(getClientRect, 2, + ret, _, _ := syscall.Syscall(getClientRect.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(rect)), 0) @@ -1966,7 +2494,7 @@ func GetClientRect(hWnd HWND, rect *RECT) bool { } func GetClipboardData(uFormat uint32) HANDLE { - ret, _, _ := syscall.Syscall(getClipboardData, 1, + ret, _, _ := syscall.Syscall(getClipboardData.Addr(), 1, uintptr(uFormat), 0, 0) @@ -1975,7 +2503,7 @@ func GetClipboardData(uFormat uint32) HANDLE { } func GetCursorPos(lpPoint *POINT) bool { - ret, _, _ := syscall.Syscall(getCursorPos, 1, + ret, _, _ := syscall.Syscall(getCursorPos.Addr(), 1, uintptr(unsafe.Pointer(lpPoint)), 0, 0) @@ -1983,8 +2511,17 @@ func GetCursorPos(lpPoint *POINT) bool { return ret != 0 } +func GetDesktopWindow() HWND { + ret, _, _ := syscall.Syscall(getDesktopWindow.Addr(), 0, + 0, + 0, + 0) + + return HWND(ret) +} + func GetDC(hWnd HWND) HDC { - ret, _, _ := syscall.Syscall(getDC, 1, + ret, _, _ := syscall.Syscall(getDC.Addr(), 1, uintptr(hWnd), 0, 0) @@ -1992,8 +2529,42 @@ func GetDC(hWnd HWND) HDC { return HDC(ret) } +func GetDlgItem(hDlg HWND, nIDDlgItem int32) HWND { + ret, _, _ := syscall.Syscall(getDlgItem.Addr(), 2, + uintptr(hDlg), + uintptr(nIDDlgItem), + 0) + + return HWND(ret) +} + +func GetDpiForWindow(hwnd HWND) uint32 { + if getDpiForWindow.Find() != nil { + hdc := GetDC(hwnd) + defer ReleaseDC(hwnd, hdc) + + return uint32(GetDeviceCaps(hdc, LOGPIXELSY)) + } + + ret, _, _ := syscall.Syscall(getDpiForWindow.Addr(), 1, + uintptr(hwnd), + 0, + 0) + + return uint32(ret) +} + func GetFocus() HWND { - ret, _, _ := syscall.Syscall(getFocus, 0, + ret, _, _ := syscall.Syscall(getFocus.Addr(), 0, + 0, + 0, + 0) + + return HWND(ret) +} + +func GetForegroundWindow() HWND { + ret, _, _ := syscall.Syscall(getForegroundWindow.Addr(), 0, 0, 0, 0) @@ -2001,8 +2572,17 @@ func GetFocus() HWND { return HWND(ret) } +func GetIconInfo(hicon HICON, piconinfo *ICONINFO) bool { + ret, _, _ := syscall.Syscall(getIconInfo.Addr(), 2, + uintptr(hicon), + uintptr(unsafe.Pointer(piconinfo)), + 0) + + return ret != 0 +} + func GetKeyState(nVirtKey int32) int16 { - ret, _, _ := syscall.Syscall(getKeyState, 1, + ret, _, _ := syscall.Syscall(getKeyState.Addr(), 1, uintptr(nVirtKey), 0, 0) @@ -2010,8 +2590,17 @@ func GetKeyState(nVirtKey int32) int16 { return int16(ret) } +func GetMenuCheckMarkDimensions() int32 { + ret, _, _ := syscall.Syscall(getMenuCheckMarkDimensions.Addr(), 0, + 0, + 0, + 0) + + return int32(ret) +} + func GetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool { - ret, _, _ := syscall.Syscall(getMenuInfo, 2, + ret, _, _ := syscall.Syscall(getMenuInfo.Addr(), 2, uintptr(hmenu), uintptr(unsafe.Pointer(lpcmi)), 0) @@ -2019,8 +2608,38 @@ func GetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool { return ret != 0 } +func GetMenuItemCount(hMenu HMENU) int32 { + ret, _, _ := syscall.Syscall(getMenuItemCount.Addr(), 1, + uintptr(hMenu), + 0, + 0) + + return int32(ret) +} + +func GetMenuItemID(hMenu HMENU, nPos int32) uint32 { + ret, _, _ := syscall.Syscall(getMenuItemID.Addr(), 2, + uintptr(hMenu), + uintptr(nPos), + 0) + + return uint32(ret) +} + +func GetMenuItemInfo(hmenu HMENU, item uint32, fByPosition BOOL, lpmii *MENUITEMINFO) bool { + ret, _, _ := syscall.Syscall6(getMenuItemInfo.Addr(), 4, + uintptr(hmenu), + uintptr(item), + uintptr(fByPosition), + uintptr(unsafe.Pointer(lpmii)), + 0, + 0) + + return ret != 0 +} + func GetMessage(msg *MSG, hWnd HWND, msgFilterMin, msgFilterMax uint32) BOOL { - ret, _, _ := syscall.Syscall6(getMessage, 4, + ret, _, _ := syscall.Syscall6(getMessage.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hWnd), uintptr(msgFilterMin), @@ -2032,7 +2651,7 @@ func GetMessage(msg *MSG, hWnd HWND, msgFilterMin, msgFilterMax uint32) BOOL { } func GetMonitorInfo(hMonitor HMONITOR, lpmi *MONITORINFO) bool { - ret, _, _ := syscall.Syscall(getMonitorInfo, 2, + ret, _, _ := syscall.Syscall(getMonitorInfo.Addr(), 2, uintptr(hMonitor), uintptr(unsafe.Pointer(lpmi)), 0) @@ -2041,7 +2660,7 @@ func GetMonitorInfo(hMonitor HMONITOR, lpmi *MONITORINFO) bool { } func GetParent(hWnd HWND) HWND { - ret, _, _ := syscall.Syscall(getParent, 1, + ret, _, _ := syscall.Syscall(getParent.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2050,7 +2669,7 @@ func GetParent(hWnd HWND) HWND { } func GetRawInputData(hRawInput HRAWINPUT, uiCommand uint32, pData unsafe.Pointer, pcbSize *uint32, cBSizeHeader uint32) uint32 { - ret, _, _ := syscall.Syscall6(getRawInputData, 5, + ret, _, _ := syscall.Syscall6(getRawInputData.Addr(), 5, uintptr(hRawInput), uintptr(uiCommand), uintptr(pData), @@ -2061,8 +2680,26 @@ func GetRawInputData(hRawInput HRAWINPUT, uiCommand uint32, pData unsafe.Pointer return uint32(ret) } +func GetScrollInfo(hwnd HWND, fnBar int32, lpsi *SCROLLINFO) bool { + ret, _, _ := syscall.Syscall(getScrollInfo.Addr(), 3, + uintptr(hwnd), + uintptr(fnBar), + uintptr(unsafe.Pointer(lpsi))) + + return ret != 0 +} + +func GetSubMenu(hMenu HMENU, nPos int32) HMENU { + ret, _, _ := syscall.Syscall(getSubMenu.Addr(), 2, + uintptr(hMenu), + uintptr(nPos), + 0) + + return HMENU(ret) +} + func GetSysColor(nIndex int) uint32 { - ret, _, _ := syscall.Syscall(getSysColor, 1, + ret, _, _ := syscall.Syscall(getSysColor.Addr(), 1, uintptr(nIndex), 0, 0) @@ -2071,7 +2708,7 @@ func GetSysColor(nIndex int) uint32 { } func GetSysColorBrush(nIndex int) HBRUSH { - ret, _, _ := syscall.Syscall(getSysColorBrush, 1, + ret, _, _ := syscall.Syscall(getSysColorBrush.Addr(), 1, uintptr(nIndex), 0, 0) @@ -2079,8 +2716,16 @@ func GetSysColorBrush(nIndex int) HBRUSH { return HBRUSH(ret) } +func GetSystemMenu(hWnd HWND, revert bool) HMENU { + ret, _, _ := syscall.Syscall(getSystemMenu.Addr(), 2, + uintptr(hWnd), + uintptr(BoolToBOOL(revert)), + 0) + return HMENU(ret) +} + func GetSystemMetrics(nIndex int32) int32 { - ret, _, _ := syscall.Syscall(getSystemMetrics, 1, + ret, _, _ := syscall.Syscall(getSystemMetrics.Addr(), 1, uintptr(nIndex), 0, 0) @@ -2088,8 +2733,21 @@ func GetSystemMetrics(nIndex int32) int32 { return int32(ret) } +func GetSystemMetricsForDpi(nIndex int32, dpi uint32) int32 { + if getSystemMetricsForDpi.Find() != nil { + return GetSystemMetrics(nIndex) + } + + ret, _, _ := syscall.Syscall(getSystemMetricsForDpi.Addr(), 2, + uintptr(nIndex), + uintptr(dpi), + 0) + + return int32(ret) +} + func GetWindow(hWnd HWND, uCmd uint32) HWND { - ret, _, _ := syscall.Syscall(getWindow, 2, + ret, _, _ := syscall.Syscall(getWindow.Addr(), 2, uintptr(hWnd), uintptr(uCmd), 0) @@ -2098,7 +2756,7 @@ func GetWindow(hWnd HWND, uCmd uint32) HWND { } func GetWindowLong(hWnd HWND, index int32) int32 { - ret, _, _ := syscall.Syscall(getWindowLong, 2, + ret, _, _ := syscall.Syscall(getWindowLong.Addr(), 2, uintptr(hWnd), uintptr(index), 0) @@ -2107,7 +2765,7 @@ func GetWindowLong(hWnd HWND, index int32) int32 { } func GetWindowLongPtr(hWnd HWND, index int32) uintptr { - ret, _, _ := syscall.Syscall(getWindowLongPtr, 2, + ret, _, _ := syscall.Syscall(getWindowLongPtr.Addr(), 2, uintptr(hWnd), uintptr(index), 0) @@ -2116,7 +2774,7 @@ func GetWindowLongPtr(hWnd HWND, index int32) uintptr { } func GetWindowPlacement(hWnd HWND, lpwndpl *WINDOWPLACEMENT) bool { - ret, _, _ := syscall.Syscall(getWindowPlacement, 2, + ret, _, _ := syscall.Syscall(getWindowPlacement.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(lpwndpl)), 0) @@ -2125,7 +2783,7 @@ func GetWindowPlacement(hWnd HWND, lpwndpl *WINDOWPLACEMENT) bool { } func GetWindowRect(hWnd HWND, rect *RECT) bool { - ret, _, _ := syscall.Syscall(getWindowRect, 2, + ret, _, _ := syscall.Syscall(getWindowRect.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(rect)), 0) @@ -2134,7 +2792,7 @@ func GetWindowRect(hWnd HWND, rect *RECT) bool { } func InsertMenuItem(hMenu HMENU, uItem uint32, fByPosition bool, lpmii *MENUITEMINFO) bool { - ret, _, _ := syscall.Syscall6(insertMenuItem, 4, + ret, _, _ := syscall.Syscall6(insertMenuItem.Addr(), 4, uintptr(hMenu), uintptr(uItem), uintptr(BoolToBOOL(fByPosition)), @@ -2146,7 +2804,7 @@ func InsertMenuItem(hMenu HMENU, uItem uint32, fByPosition bool, lpmii *MENUITEM } func InvalidateRect(hWnd HWND, lpRect *RECT, bErase bool) bool { - ret, _, _ := syscall.Syscall(invalidateRect, 3, + ret, _, _ := syscall.Syscall(invalidateRect.Addr(), 3, uintptr(hWnd), uintptr(unsafe.Pointer(lpRect)), uintptr(BoolToBOOL(bErase))) @@ -2155,7 +2813,7 @@ func InvalidateRect(hWnd HWND, lpRect *RECT, bErase bool) bool { } func IsChild(hWndParent, hWnd HWND) bool { - ret, _, _ := syscall.Syscall(isChild, 2, + ret, _, _ := syscall.Syscall(isChild.Addr(), 2, uintptr(hWndParent), uintptr(hWnd), 0) @@ -2164,7 +2822,7 @@ func IsChild(hWndParent, hWnd HWND) bool { } func IsClipboardFormatAvailable(format uint32) bool { - ret, _, _ := syscall.Syscall(isClipboardFormatAvailable, 1, + ret, _, _ := syscall.Syscall(isClipboardFormatAvailable.Addr(), 1, uintptr(format), 0, 0) @@ -2173,7 +2831,7 @@ func IsClipboardFormatAvailable(format uint32) bool { } func IsDialogMessage(hWnd HWND, msg *MSG) bool { - ret, _, _ := syscall.Syscall(isDialogMessage, 2, + ret, _, _ := syscall.Syscall(isDialogMessage.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(msg)), 0) @@ -2181,8 +2839,17 @@ func IsDialogMessage(hWnd HWND, msg *MSG) bool { return ret != 0 } +func IsIconic(hWnd HWND) bool { + ret, _, _ := syscall.Syscall(isIconic.Addr(), 1, + uintptr(hWnd), + 0, + 0) + + return ret != 0 +} + func IsWindowEnabled(hWnd HWND) bool { - ret, _, _ := syscall.Syscall(isWindowEnabled, 1, + ret, _, _ := syscall.Syscall(isWindowEnabled.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2191,7 +2858,16 @@ func IsWindowEnabled(hWnd HWND) bool { } func IsWindowVisible(hWnd HWND) bool { - ret, _, _ := syscall.Syscall(isWindowVisible, 1, + ret, _, _ := syscall.Syscall(isWindowVisible.Addr(), 1, + uintptr(hWnd), + 0, + 0) + + return ret != 0 +} + +func IsZoomed(hWnd HWND) bool { + ret, _, _ := syscall.Syscall(isZoomed.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2200,7 +2876,7 @@ func IsWindowVisible(hWnd HWND) bool { } func KillTimer(hWnd HWND, uIDEvent uintptr) bool { - ret, _, _ := syscall.Syscall(killTimer, 2, + ret, _, _ := syscall.Syscall(killTimer.Addr(), 2, uintptr(hWnd), uIDEvent, 0) @@ -2209,7 +2885,7 @@ func KillTimer(hWnd HWND, uIDEvent uintptr) bool { } func LoadCursor(hInstance HINSTANCE, lpCursorName *uint16) HCURSOR { - ret, _, _ := syscall.Syscall(loadCursor, 2, + ret, _, _ := syscall.Syscall(loadCursor.Addr(), 2, uintptr(hInstance), uintptr(unsafe.Pointer(lpCursorName)), 0) @@ -2218,7 +2894,7 @@ func LoadCursor(hInstance HINSTANCE, lpCursorName *uint16) HCURSOR { } func LoadIcon(hInstance HINSTANCE, lpIconName *uint16) HICON { - ret, _, _ := syscall.Syscall(loadIcon, 2, + ret, _, _ := syscall.Syscall(loadIcon.Addr(), 2, uintptr(hInstance), uintptr(unsafe.Pointer(lpIconName)), 0) @@ -2227,7 +2903,7 @@ func LoadIcon(hInstance HINSTANCE, lpIconName *uint16) HICON { } func LoadImage(hinst HINSTANCE, lpszName *uint16, uType uint32, cxDesired, cyDesired int32, fuLoad uint32) HANDLE { - ret, _, _ := syscall.Syscall6(loadImage, 6, + ret, _, _ := syscall.Syscall6(loadImage.Addr(), 6, uintptr(hinst), uintptr(unsafe.Pointer(lpszName)), uintptr(uType), @@ -2239,7 +2915,7 @@ func LoadImage(hinst HINSTANCE, lpszName *uint16, uType uint32, cxDesired, cyDes } func LoadMenu(hinst HINSTANCE, name *uint16) HMENU { - ret, _, _ := syscall.Syscall(loadMenu, 2, + ret, _, _ := syscall.Syscall(loadMenu.Addr(), 2, uintptr(hinst), uintptr(unsafe.Pointer(name)), 0) @@ -2248,7 +2924,7 @@ func LoadMenu(hinst HINSTANCE, name *uint16) HMENU { } func LoadString(instRes HINSTANCE, id uint32, buf *uint16, length int32) int32 { - ret, _, _ := syscall.Syscall6(loadString, 4, + ret, _, _ := syscall.Syscall6(loadString.Addr(), 4, uintptr(instRes), uintptr(id), uintptr(unsafe.Pointer(buf)), @@ -2274,7 +2950,7 @@ func LoadString(instRes HINSTANCE, id uint32, buf *uint16, length int32) int32 { // // The function will return true if the function succeeds, false if otherwise. func MessageBeep(uType uint32) bool { - ret, _, _ := syscall.Syscall(messageBeep, 2, + ret, _, _ := syscall.Syscall(messageBeep.Addr(), 2, uintptr(uType), 0, 0) @@ -2283,7 +2959,7 @@ func MessageBeep(uType uint32) bool { } func MessageBox(hWnd HWND, lpText, lpCaption *uint16, uType uint32) int32 { - ret, _, _ := syscall.Syscall6(messageBox, 4, + ret, _, _ := syscall.Syscall6(messageBox.Addr(), 4, uintptr(hWnd), uintptr(unsafe.Pointer(lpText)), uintptr(unsafe.Pointer(lpCaption)), @@ -2295,7 +2971,7 @@ func MessageBox(hWnd HWND, lpText, lpCaption *uint16, uType uint32) int32 { } func MonitorFromWindow(hwnd HWND, dwFlags uint32) HMONITOR { - ret, _, _ := syscall.Syscall(monitorFromWindow, 2, + ret, _, _ := syscall.Syscall(monitorFromWindow.Addr(), 2, uintptr(hwnd), uintptr(dwFlags), 0) @@ -2304,7 +2980,7 @@ func MonitorFromWindow(hwnd HWND, dwFlags uint32) HMONITOR { } func MoveWindow(hWnd HWND, x, y, width, height int32, repaint bool) bool { - ret, _, _ := syscall.Syscall6(moveWindow, 6, + ret, _, _ := syscall.Syscall6(moveWindow.Addr(), 6, uintptr(hWnd), uintptr(x), uintptr(y), @@ -2315,8 +2991,18 @@ func MoveWindow(hWnd HWND, x, y, width, height int32, repaint bool) bool { return ret != 0 } +func NotifyWinEvent(event uint32, hwnd HWND, idObject, idChild int32) { + syscall.Syscall6(notifyWinEvent.Addr(), 4, + uintptr(event), + uintptr(hwnd), + uintptr(idObject), + uintptr(idChild), + 0, + 0) +} + func UnregisterClass(name *uint16) bool { - ret, _, _ := syscall.Syscall(unregisterClass, 1, + ret, _, _ := syscall.Syscall(unregisterClass.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0) @@ -2325,7 +3011,7 @@ func UnregisterClass(name *uint16) bool { } func OpenClipboard(hWndNewOwner HWND) bool { - ret, _, _ := syscall.Syscall(openClipboard, 1, + ret, _, _ := syscall.Syscall(openClipboard.Addr(), 1, uintptr(hWndNewOwner), 0, 0) @@ -2334,7 +3020,7 @@ func OpenClipboard(hWndNewOwner HWND) bool { } func PeekMessage(lpMsg *MSG, hWnd HWND, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) bool { - ret, _, _ := syscall.Syscall6(peekMessage, 5, + ret, _, _ := syscall.Syscall6(peekMessage.Addr(), 5, uintptr(unsafe.Pointer(lpMsg)), uintptr(hWnd), uintptr(wMsgFilterMin), @@ -2346,7 +3032,7 @@ func PeekMessage(lpMsg *MSG, hWnd HWND, wMsgFilterMin, wMsgFilterMax, wRemoveMsg } func PostMessage(hWnd HWND, msg uint32, wParam, lParam uintptr) uintptr { - ret, _, _ := syscall.Syscall6(postMessage, 4, + ret, _, _ := syscall.Syscall6(postMessage.Addr(), 4, uintptr(hWnd), uintptr(msg), wParam, @@ -2358,14 +3044,46 @@ func PostMessage(hWnd HWND, msg uint32, wParam, lParam uintptr) uintptr { } func PostQuitMessage(exitCode int32) { - syscall.Syscall(postQuitMessage, 1, + syscall.Syscall(postQuitMessage.Addr(), 1, uintptr(exitCode), 0, 0) } +const ( + // RedrawWindow() flags + RDW_INVALIDATE = 0x0001 + RDW_INTERNALPAINT = 0x0002 + RDW_ERASE = 0x0004 + + RDW_VALIDATE = 0x0008 + RDW_NOINTERNALPAINT = 0x0010 + RDW_NOERASE = 0x0020 + + RDW_NOCHILDREN = 0x0040 + RDW_ALLCHILDREN = 0x0080 + + RDW_UPDATENOW = 0x0100 + RDW_ERASENOW = 0x0200 + + RDW_FRAME = 0x0400 + RDW_NOFRAME = 0x0800 +) + +func RedrawWindow(hWnd HWND, lprcUpdate *RECT, hrgnUpdate HRGN, flags uint32) bool { + ret, _, _ := syscall.Syscall6(redrawWindow.Addr(), 4, + uintptr(hWnd), + uintptr(unsafe.Pointer(lprcUpdate)), + uintptr(hrgnUpdate), + uintptr(flags), + 0, + 0) + + return ret != 0 +} + func RegisterClassEx(windowClass *WNDCLASSEX) ATOM { - ret, _, _ := syscall.Syscall(registerClassEx, 1, + ret, _, _ := syscall.Syscall(registerClassEx.Addr(), 1, uintptr(unsafe.Pointer(windowClass)), 0, 0) @@ -2374,7 +3092,7 @@ func RegisterClassEx(windowClass *WNDCLASSEX) ATOM { } func RegisterRawInputDevices(pRawInputDevices *RAWINPUTDEVICE, uiNumDevices uint32, cbSize uint32) bool { - ret, _, _ := syscall.Syscall(registerRawInputDevices, 3, + ret, _, _ := syscall.Syscall(registerRawInputDevices.Addr(), 3, uintptr(unsafe.Pointer(pRawInputDevices)), uintptr(uiNumDevices), uintptr(cbSize)) @@ -2383,7 +3101,7 @@ func RegisterRawInputDevices(pRawInputDevices *RAWINPUTDEVICE, uiNumDevices uint } func RegisterWindowMessage(lpString *uint16) uint32 { - ret, _, _ := syscall.Syscall(registerWindowMessage, 1, + ret, _, _ := syscall.Syscall(registerWindowMessage.Addr(), 1, uintptr(unsafe.Pointer(lpString)), 0, 0) @@ -2392,7 +3110,7 @@ func RegisterWindowMessage(lpString *uint16) uint32 { } func ReleaseCapture() bool { - ret, _, _ := syscall.Syscall(releaseCapture, 0, + ret, _, _ := syscall.Syscall(releaseCapture.Addr(), 0, 0, 0, 0) @@ -2401,7 +3119,7 @@ func ReleaseCapture() bool { } func ReleaseDC(hWnd HWND, hDC HDC) bool { - ret, _, _ := syscall.Syscall(releaseDC, 2, + ret, _, _ := syscall.Syscall(releaseDC.Addr(), 2, uintptr(hWnd), uintptr(hDC), 0) @@ -2410,7 +3128,7 @@ func ReleaseDC(hWnd HWND, hDC HDC) bool { } func RemoveMenu(hMenu HMENU, uPosition, uFlags uint32) bool { - ret, _, _ := syscall.Syscall(removeMenu, 3, + ret, _, _ := syscall.Syscall(removeMenu.Addr(), 3, uintptr(hMenu), uintptr(uPosition), uintptr(uFlags)) @@ -2419,7 +3137,7 @@ func RemoveMenu(hMenu HMENU, uPosition, uFlags uint32) bool { } func ScreenToClient(hWnd HWND, point *POINT) bool { - ret, _, _ := syscall.Syscall(screenToClient, 2, + ret, _, _ := syscall.Syscall(screenToClient.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(point)), 0) @@ -2428,7 +3146,7 @@ func ScreenToClient(hWnd HWND, point *POINT) bool { } func SendDlgItemMessage(hWnd HWND, id int32, msg uint32, wParam, lParam uintptr) uintptr { - ret, _, _ := syscall.Syscall6(sendDlgItemMessage, 5, + ret, _, _ := syscall.Syscall6(sendDlgItemMessage.Addr(), 5, uintptr(hWnd), uintptr(id), uintptr(msg), @@ -2439,8 +3157,9 @@ func SendDlgItemMessage(hWnd HWND, id int32, msg uint32, wParam, lParam uintptr) return ret } +// pInputs expects a unsafe.Pointer to a slice of MOUSE_INPUT or KEYBD_INPUT or HARDWARE_INPUT structs. func SendInput(nInputs uint32, pInputs unsafe.Pointer, cbSize int32) uint32 { - ret, _, _ := syscall.Syscall(sendInput, 3, + ret, _, _ := syscall.Syscall(sendInput.Addr(), 3, uintptr(nInputs), uintptr(pInputs), uintptr(cbSize)) @@ -2449,7 +3168,7 @@ func SendInput(nInputs uint32, pInputs unsafe.Pointer, cbSize int32) uint32 { } func SendMessage(hWnd HWND, msg uint32, wParam, lParam uintptr) uintptr { - ret, _, _ := syscall.Syscall6(sendMessage, 4, + ret, _, _ := syscall.Syscall6(sendMessage.Addr(), 4, uintptr(hWnd), uintptr(msg), wParam, @@ -2461,7 +3180,7 @@ func SendMessage(hWnd HWND, msg uint32, wParam, lParam uintptr) uintptr { } func SetActiveWindow(hWnd HWND) HWND { - ret, _, _ := syscall.Syscall(setActiveWindow, 1, + ret, _, _ := syscall.Syscall(setActiveWindow.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2470,7 +3189,7 @@ func SetActiveWindow(hWnd HWND) HWND { } func SetCapture(hWnd HWND) HWND { - ret, _, _ := syscall.Syscall(setCapture, 1, + ret, _, _ := syscall.Syscall(setCapture.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2479,7 +3198,7 @@ func SetCapture(hWnd HWND) HWND { } func SetClipboardData(uFormat uint32, hMem HANDLE) HANDLE { - ret, _, _ := syscall.Syscall(setClipboardData, 2, + ret, _, _ := syscall.Syscall(setClipboardData.Addr(), 2, uintptr(uFormat), uintptr(hMem), 0) @@ -2488,7 +3207,7 @@ func SetClipboardData(uFormat uint32, hMem HANDLE) HANDLE { } func SetCursor(hCursor HCURSOR) HCURSOR { - ret, _, _ := syscall.Syscall(setCursor, 1, + ret, _, _ := syscall.Syscall(setCursor.Addr(), 1, uintptr(hCursor), 0, 0) @@ -2497,7 +3216,7 @@ func SetCursor(hCursor HCURSOR) HCURSOR { } func SetCursorPos(X, Y int32) bool { - ret, _, _ := syscall.Syscall(setCursorPos, 2, + ret, _, _ := syscall.Syscall(setCursorPos.Addr(), 2, uintptr(X), uintptr(Y), 0) @@ -2506,7 +3225,7 @@ func SetCursorPos(X, Y int32) bool { } func SetFocus(hWnd HWND) HWND { - ret, _, _ := syscall.Syscall(setFocus, 1, + ret, _, _ := syscall.Syscall(setFocus.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2515,7 +3234,7 @@ func SetFocus(hWnd HWND) HWND { } func SetForegroundWindow(hWnd HWND) bool { - ret, _, _ := syscall.Syscall(setForegroundWindow, 1, + ret, _, _ := syscall.Syscall(setForegroundWindow.Addr(), 1, uintptr(hWnd), 0, 0) @@ -2524,7 +3243,7 @@ func SetForegroundWindow(hWnd HWND) bool { } func SetMenu(hWnd HWND, hMenu HMENU) bool { - ret, _, _ := syscall.Syscall(setMenu, 2, + ret, _, _ := syscall.Syscall(setMenu.Addr(), 2, uintptr(hWnd), uintptr(hMenu), 0) @@ -2532,8 +3251,17 @@ func SetMenu(hWnd HWND, hMenu HMENU) bool { return ret != 0 } +func SetMenuDefaultItem(hMenu HMENU, uItem uint32, fByPosition bool) bool { + ret, _, _ := syscall.Syscall(setMenuDefaultItem.Addr(), 3, + uintptr(hMenu), + uintptr(uItem), + uintptr(BoolToBOOL(fByPosition))) + + return ret != 0 +} + func SetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool { - ret, _, _ := syscall.Syscall(setMenuInfo, 2, + ret, _, _ := syscall.Syscall(setMenuInfo.Addr(), 2, uintptr(hmenu), uintptr(unsafe.Pointer(lpcmi)), 0) @@ -2541,8 +3269,20 @@ func SetMenuInfo(hmenu HMENU, lpcmi *MENUINFO) bool { return ret != 0 } +func SetMenuItemBitmaps(hMenu HMENU, uPosition uint32, uFlags uint32, hBitmapUnchecked HBITMAP, hBitmapChecked HBITMAP) bool { + ret, _, _ := syscall.Syscall6(setMenuItemBitmaps.Addr(), 5, + uintptr(hMenu), + uintptr(uPosition), + uintptr(uFlags), + uintptr(hBitmapUnchecked), + uintptr(hBitmapChecked), + 0) + + return ret != 0 +} + func SetMenuItemInfo(hMenu HMENU, uItem uint32, fByPosition bool, lpmii *MENUITEMINFO) bool { - ret, _, _ := syscall.Syscall6(setMenuItemInfo, 4, + ret, _, _ := syscall.Syscall6(setMenuItemInfo.Addr(), 4, uintptr(hMenu), uintptr(uItem), uintptr(BoolToBOOL(fByPosition)), @@ -2554,7 +3294,7 @@ func SetMenuItemInfo(hMenu HMENU, uItem uint32, fByPosition bool, lpmii *MENUITE } func SetParent(hWnd HWND, parentHWnd HWND) HWND { - ret, _, _ := syscall.Syscall(setParent, 2, + ret, _, _ := syscall.Syscall(setParent.Addr(), 2, uintptr(hWnd), uintptr(parentHWnd), 0) @@ -2563,7 +3303,7 @@ func SetParent(hWnd HWND, parentHWnd HWND) HWND { } func SetRect(lprc *RECT, xLeft, yTop, xRight, yBottom uint32) BOOL { - ret, _, _ := syscall.Syscall6(setRect, 5, + ret, _, _ := syscall.Syscall6(setRect.Addr(), 5, uintptr(unsafe.Pointer(lprc)), uintptr(xLeft), uintptr(yTop), @@ -2574,8 +3314,20 @@ func SetRect(lprc *RECT, xLeft, yTop, xRight, yBottom uint32) BOOL { return BOOL(ret) } +func SetScrollInfo(hwnd HWND, fnBar int32, lpsi *SCROLLINFO, fRedraw bool) int32 { + ret, _, _ := syscall.Syscall6(setScrollInfo.Addr(), 4, + uintptr(hwnd), + uintptr(fnBar), + uintptr(unsafe.Pointer(lpsi)), + uintptr(BoolToBOOL(fRedraw)), + 0, + 0) + + return int32(ret) +} + func SetTimer(hWnd HWND, nIDEvent uintptr, uElapse uint32, lpTimerFunc uintptr) uintptr { - ret, _, _ := syscall.Syscall6(setTimer, 4, + ret, _, _ := syscall.Syscall6(setTimer.Addr(), 4, uintptr(hWnd), nIDEvent, uintptr(uElapse), @@ -2586,8 +3338,28 @@ func SetTimer(hWnd HWND, nIDEvent uintptr, uElapse uint32, lpTimerFunc uintptr) return ret } +type WINEVENTPROC func(hWinEventHook HWINEVENTHOOK, event uint32, hwnd HWND, idObject int32, idChild int32, idEventThread uint32, dwmsEventTime uint32) uintptr + +func SetWinEventHook(eventMin uint32, eventMax uint32, hmodWinEventProc HMODULE, callbackFunction WINEVENTPROC, idProcess uint32, idThread uint32, dwFlags uint32) (HWINEVENTHOOK, error) { + ret, _, err := syscall.Syscall9(setWinEventHook.Addr(), 7, + uintptr(eventMin), + uintptr(eventMax), + uintptr(hmodWinEventProc), + windows.NewCallback(callbackFunction), + uintptr(idProcess), + uintptr(idThread), + uintptr(dwFlags), + 0, 0) + + if ret == 0 { + return 0, err + } + + return HWINEVENTHOOK(ret), nil +} + func SetWindowLong(hWnd HWND, index, value int32) int32 { - ret, _, _ := syscall.Syscall(setWindowLong, 3, + ret, _, _ := syscall.Syscall(setWindowLong.Addr(), 3, uintptr(hWnd), uintptr(index), uintptr(value)) @@ -2596,7 +3368,7 @@ func SetWindowLong(hWnd HWND, index, value int32) int32 { } func SetWindowLongPtr(hWnd HWND, index int, value uintptr) uintptr { - ret, _, _ := syscall.Syscall(setWindowLongPtr, 3, + ret, _, _ := syscall.Syscall(setWindowLongPtr.Addr(), 3, uintptr(hWnd), uintptr(index), value) @@ -2605,7 +3377,7 @@ func SetWindowLongPtr(hWnd HWND, index int, value uintptr) uintptr { } func SetWindowPlacement(hWnd HWND, lpwndpl *WINDOWPLACEMENT) bool { - ret, _, _ := syscall.Syscall(setWindowPlacement, 2, + ret, _, _ := syscall.Syscall(setWindowPlacement.Addr(), 2, uintptr(hWnd), uintptr(unsafe.Pointer(lpwndpl)), 0) @@ -2614,7 +3386,7 @@ func SetWindowPlacement(hWnd HWND, lpwndpl *WINDOWPLACEMENT) bool { } func SetWindowPos(hWnd, hWndInsertAfter HWND, x, y, width, height int32, flags uint32) bool { - ret, _, _ := syscall.Syscall9(setWindowPos, 7, + ret, _, _ := syscall.Syscall9(setWindowPos.Addr(), 7, uintptr(hWnd), uintptr(hWndInsertAfter), uintptr(x), @@ -2629,7 +3401,7 @@ func SetWindowPos(hWnd, hWndInsertAfter HWND, x, y, width, height int32, flags u } func ShowWindow(hWnd HWND, nCmdShow int32) bool { - ret, _, _ := syscall.Syscall(showWindow, 2, + ret, _, _ := syscall.Syscall(showWindow.Addr(), 2, uintptr(hWnd), uintptr(nCmdShow), 0) @@ -2638,7 +3410,7 @@ func ShowWindow(hWnd HWND, nCmdShow int32) bool { } func SystemParametersInfo(uiAction, uiParam uint32, pvParam unsafe.Pointer, fWinIni uint32) bool { - ret, _, _ := syscall.Syscall6(systemParametersInfo, 4, + ret, _, _ := syscall.Syscall6(systemParametersInfo.Addr(), 4, uintptr(uiAction), uintptr(uiParam), uintptr(pvParam), @@ -2649,8 +3421,32 @@ func SystemParametersInfo(uiAction, uiParam uint32, pvParam unsafe.Pointer, fWin return ret != 0 } +func TrackMouseEvent(lpEventTrack *TRACKMOUSEEVENT) bool { + ret, _, _ := syscall.Syscall(trackMouseEvent.Addr(), 1, + uintptr(unsafe.Pointer(lpEventTrack)), + 0, + 0) + + return ret != 0 +} + +func TrackPopupMenu(hMenu HMENU, uFlags uint32, x, y int32, nReserved int32, hWnd HWND, prcRect *RECT) uint32 { + ret, _, _ := syscall.Syscall9(trackPopupMenu.Addr(), 7, + uintptr(hMenu), + uintptr(uFlags), + uintptr(x), + uintptr(y), + uintptr(nReserved), + uintptr(hWnd), + uintptr(unsafe.Pointer(prcRect)), + 0, + 0) + + return uint32(ret) +} + func TrackPopupMenuEx(hMenu HMENU, fuFlags uint32, x, y int32, hWnd HWND, lptpm *TPMPARAMS) BOOL { - ret, _, _ := syscall.Syscall6(trackPopupMenuEx, 6, + ret, _, _ := syscall.Syscall6(trackPopupMenuEx.Addr(), 6, uintptr(hMenu), uintptr(fuFlags), uintptr(x), @@ -2662,7 +3458,7 @@ func TrackPopupMenuEx(hMenu HMENU, fuFlags uint32, x, y int32, hWnd HWND, lptpm } func TranslateMessage(msg *MSG) bool { - ret, _, _ := syscall.Syscall(translateMessage, 1, + ret, _, _ := syscall.Syscall(translateMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0) @@ -2670,16 +3466,31 @@ func TranslateMessage(msg *MSG) bool { return ret != 0 } +func UnhookWinEvent(hWinHookEvent HWINEVENTHOOK) bool { + ret, _, _ := syscall.Syscall(unhookWinEvent.Addr(), 1, uintptr(hWinHookEvent), 0, 0) + return ret != 0 +} + func UpdateWindow(hwnd HWND) bool { - ret, _, _ := syscall.Syscall(updateWindow, 1, + ret, _, _ := syscall.Syscall(updateWindow.Addr(), 1, uintptr(hwnd), 0, 0) return ret != 0 } + +func WindowFromDC(hDC HDC) HWND { + ret, _, _ := syscall.Syscall(windowFromDC.Addr(), 1, + uintptr(hDC), + 0, + 0) + + return HWND(ret) +} + func WindowFromPoint(Point POINT) HWND { - ret, _, _ := syscall.Syscall(windowFromPoint, 2, + ret, _, _ := syscall.Syscall(windowFromPoint.Addr(), 2, uintptr(Point.X), uintptr(Point.Y), 0) diff --git a/uxtheme.go b/uxtheme.go index a9f4c836..1f24cac9 100644 --- a/uxtheme.go +++ b/uxtheme.go @@ -2,31 +2,617 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( "syscall" "unsafe" + + "golang.org/x/sys/windows" +) + +// TMT property ids +const ( + TMT_RESERVEDLOW = 0 + TMT_RESERVEDHIGH = 7999 + + TMT_DIBDATA = 2 + TMT_GLYPHDIBDATA = 8 + TMT_ENUM = 200 + TMT_STRING = 201 + TMT_INT = 202 + TMT_BOOL = 203 + TMT_COLOR = 204 + TMT_MARGINS = 205 + TMT_FILENAME = 206 + TMT_SIZE = 207 + TMT_POSITION = 208 + TMT_RECT = 209 + TMT_FONT = 210 + TMT_INTLIST = 211 + TMT_HBITMAP = 212 + TMT_DISKSTREAM = 213 + TMT_STREAM = 214 + TMT_BITMAPREF = 215 + TMT_FLOAT = 216 + TMT_FLOATLIST = 217 + TMT_COLORSCHEMES = 401 + TMT_SIZES = 402 + TMT_CHARSET = 403 + TMT_NAME = 600 + TMT_DISPLAYNAME = 601 + TMT_TOOLTIP = 602 + TMT_COMPANY = 603 + TMT_AUTHOR = 604 + TMT_COPYRIGHT = 605 + TMT_URL = 606 + TMT_VERSION = 607 + TMT_DESCRIPTION = 608 + TMT_FIRST_RCSTRING_NAME = TMT_DISPLAYNAME + TMT_LAST_RCSTRING_NAME = TMT_DESCRIPTION + TMT_CAPTIONFONT = 801 + TMT_SMALLCAPTIONFONT = 802 + TMT_MENUFONT = 803 + TMT_STATUSFONT = 804 + TMT_MSGBOXFONT = 805 + TMT_ICONTITLEFONT = 806 + TMT_HEADING1FONT = 807 + TMT_HEADING2FONT = 808 + TMT_BODYFONT = 809 + TMT_FIRSTFONT = TMT_CAPTIONFONT + TMT_LASTFONT = TMT_BODYFONT + TMT_FLATMENUS = 1001 + TMT_FIRSTBOOL = TMT_FLATMENUS + TMT_LASTBOOL = TMT_FLATMENUS + TMT_SIZINGBORDERWIDTH = 1201 + TMT_SCROLLBARWIDTH = 1202 + TMT_SCROLLBARHEIGHT = 1203 + TMT_CAPTIONBARWIDTH = 1204 + TMT_CAPTIONBARHEIGHT = 1205 + TMT_SMCAPTIONBARWIDTH = 1206 + TMT_SMCAPTIONBARHEIGHT = 1207 + TMT_MENUBARWIDTH = 1208 + TMT_MENUBARHEIGHT = 1209 + TMT_PADDEDBORDERWIDTH = 1210 + TMT_FIRSTSIZE = TMT_SIZINGBORDERWIDTH + TMT_LASTSIZE = TMT_PADDEDBORDERWIDTH + TMT_MINCOLORDEPTH = 1301 + TMT_FIRSTINT = TMT_MINCOLORDEPTH + TMT_LASTINT = TMT_MINCOLORDEPTH + TMT_CSSNAME = 1401 + TMT_XMLNAME = 1402 + TMT_LASTUPDATED = 1403 + TMT_ALIAS = 1404 + TMT_FIRSTSTRING = TMT_CSSNAME + TMT_LASTSTRING = TMT_ALIAS + TMT_SCROLLBAR = 1601 + TMT_BACKGROUND = 1602 + TMT_ACTIVECAPTION = 1603 + TMT_INACTIVECAPTION = 1604 + TMT_MENU = 1605 + TMT_WINDOW = 1606 + TMT_WINDOWFRAME = 1607 + TMT_MENUTEXT = 1608 + TMT_WINDOWTEXT = 1609 + TMT_CAPTIONTEXT = 1610 + TMT_ACTIVEBORDER = 1611 + TMT_INACTIVEBORDER = 1612 + TMT_APPWORKSPACE = 1613 + TMT_HIGHLIGHT = 1614 + TMT_HIGHLIGHTTEXT = 1615 + TMT_BTNFACE = 1616 + TMT_BTNSHADOW = 1617 + TMT_GRAYTEXT = 1618 + TMT_BTNTEXT = 1619 + TMT_INACTIVECAPTIONTEXT = 1620 + TMT_BTNHIGHLIGHT = 1621 + TMT_DKSHADOW3D = 1622 + TMT_LIGHT3D = 1623 + TMT_INFOTEXT = 1624 + TMT_INFOBK = 1625 + TMT_BUTTONALTERNATEFACE = 1626 + TMT_HOTTRACKING = 1627 + TMT_GRADIENTACTIVECAPTION = 1628 + TMT_GRADIENTINACTIVECAPTION = 1629 + TMT_MENUHILIGHT = 1630 + TMT_MENUBAR = 1631 + TMT_FIRSTCOLOR = TMT_SCROLLBAR + TMT_LASTCOLOR = TMT_MENUBAR + TMT_FROMHUE1 = 1801 + TMT_FROMHUE2 = 1802 + TMT_FROMHUE3 = 1803 + TMT_FROMHUE4 = 1804 + TMT_FROMHUE5 = 1805 + TMT_TOHUE1 = 1806 + TMT_TOHUE2 = 1807 + TMT_TOHUE3 = 1808 + TMT_TOHUE4 = 1809 + TMT_TOHUE5 = 1810 + TMT_FROMCOLOR1 = 2001 + TMT_FROMCOLOR2 = 2002 + TMT_FROMCOLOR3 = 2003 + TMT_FROMCOLOR4 = 2004 + TMT_FROMCOLOR5 = 2005 + TMT_TOCOLOR1 = 2006 + TMT_TOCOLOR2 = 2007 + TMT_TOCOLOR3 = 2008 + TMT_TOCOLOR4 = 2009 + TMT_TOCOLOR5 = 2010 + TMT_TRANSPARENT = 2201 + TMT_AUTOSIZE = 2202 + TMT_BORDERONLY = 2203 + TMT_COMPOSITED = 2204 + TMT_BGFILL = 2205 + TMT_GLYPHTRANSPARENT = 2206 + TMT_GLYPHONLY = 2207 + TMT_ALWAYSSHOWSIZINGBAR = 2208 + TMT_MIRRORIMAGE = 2209 + TMT_UNIFORMSIZING = 2210 + TMT_INTEGRALSIZING = 2211 + TMT_SOURCEGROW = 2212 + TMT_SOURCESHRINK = 2213 + TMT_DRAWBORDERS = 2214 + TMT_NOETCHEDEFFECT = 2215 + TMT_TEXTAPPLYOVERLAY = 2216 + TMT_TEXTGLOW = 2217 + TMT_TEXTITALIC = 2218 + TMT_COMPOSITEDOPAQUE = 2219 + TMT_LOCALIZEDMIRRORIMAGE = 2220 + TMT_IMAGECOUNT = 2401 + TMT_ALPHALEVEL = 2402 + TMT_BORDERSIZE = 2403 + TMT_ROUNDCORNERWIDTH = 2404 + TMT_ROUNDCORNERHEIGHT = 2405 + TMT_GRADIENTRATIO1 = 2406 + TMT_GRADIENTRATIO2 = 2407 + TMT_GRADIENTRATIO3 = 2408 + TMT_GRADIENTRATIO4 = 2409 + TMT_GRADIENTRATIO5 = 2410 + TMT_PROGRESSCHUNKSIZE = 2411 + TMT_PROGRESSSPACESIZE = 2412 + TMT_SATURATION = 2413 + TMT_TEXTBORDERSIZE = 2414 + TMT_ALPHATHRESHOLD = 2415 + TMT_WIDTH = 2416 + TMT_HEIGHT = 2417 + TMT_GLYPHINDEX = 2418 + TMT_TRUESIZESTRETCHMARK = 2419 + TMT_MINDPI1 = 2420 + TMT_MINDPI2 = 2421 + TMT_MINDPI3 = 2422 + TMT_MINDPI4 = 2423 + TMT_MINDPI5 = 2424 + TMT_TEXTGLOWSIZE = 2425 + TMT_FRAMESPERSECOND = 2426 + TMT_PIXELSPERFRAME = 2427 + TMT_ANIMATIONDELAY = 2428 + TMT_GLOWINTENSITY = 2429 + TMT_OPACITY = 2430 + TMT_COLORIZATIONCOLOR = 2431 + TMT_COLORIZATIONOPACITY = 2432 + TMT_MINDPI6 = 2433 + TMT_MINDPI7 = 2434 + TMT_GLYPHFONT = 2601 + TMT_IMAGEFILE = 3001 + TMT_IMAGEFILE1 = 3002 + TMT_IMAGEFILE2 = 3003 + TMT_IMAGEFILE3 = 3004 + TMT_IMAGEFILE4 = 3005 + TMT_IMAGEFILE5 = 3006 + TMT_GLYPHIMAGEFILE = 3008 + TMT_IMAGEFILE6 = 3009 + TMT_IMAGEFILE7 = 3010 + TMT_TEXT = 3201 + TMT_CLASSICVALUE = 3202 + TMT_OFFSET = 3401 + TMT_TEXTSHADOWOFFSET = 3402 + TMT_MINSIZE = 3403 + TMT_MINSIZE1 = 3404 + TMT_MINSIZE2 = 3405 + TMT_MINSIZE3 = 3406 + TMT_MINSIZE4 = 3407 + TMT_MINSIZE5 = 3408 + TMT_NORMALSIZE = 3409 + TMT_MINSIZE6 = 3410 + TMT_MINSIZE7 = 3411 + TMT_SIZINGMARGINS = 3601 + TMT_CONTENTMARGINS = 3602 + TMT_CAPTIONMARGINS = 3603 + TMT_BORDERCOLOR = 3801 + TMT_FILLCOLOR = 3802 + TMT_TEXTCOLOR = 3803 + TMT_EDGELIGHTCOLOR = 3804 + TMT_EDGEHIGHLIGHTCOLOR = 3805 + TMT_EDGESHADOWCOLOR = 3806 + TMT_EDGEDKSHADOWCOLOR = 3807 + TMT_EDGEFILLCOLOR = 3808 + TMT_TRANSPARENTCOLOR = 3809 + TMT_GRADIENTCOLOR1 = 3810 + TMT_GRADIENTCOLOR2 = 3811 + TMT_GRADIENTCOLOR3 = 3812 + TMT_GRADIENTCOLOR4 = 3813 + TMT_GRADIENTCOLOR5 = 3814 + TMT_SHADOWCOLOR = 3815 + TMT_GLOWCOLOR = 3816 + TMT_TEXTBORDERCOLOR = 3817 + TMT_TEXTSHADOWCOLOR = 3818 + TMT_GLYPHTEXTCOLOR = 3819 + TMT_GLYPHTRANSPARENTCOLOR = 3820 + TMT_FILLCOLORHINT = 3821 + TMT_BORDERCOLORHINT = 3822 + TMT_ACCENTCOLORHINT = 3823 + TMT_TEXTCOLORHINT = 3824 + TMT_HEADING1TEXTCOLOR = 3825 + TMT_HEADING2TEXTCOLOR = 3826 + TMT_BODYTEXTCOLOR = 3827 + TMT_BGTYPE = 4001 + TMT_BORDERTYPE = 4002 + TMT_FILLTYPE = 4003 + TMT_SIZINGTYPE = 4004 + TMT_HALIGN = 4005 + TMT_CONTENTALIGNMENT = 4006 + TMT_VALIGN = 4007 + TMT_OFFSETTYPE = 4008 + TMT_ICONEFFECT = 4009 + TMT_TEXTSHADOWTYPE = 4010 + TMT_IMAGELAYOUT = 4011 + TMT_GLYPHTYPE = 4012 + TMT_IMAGESELECTTYPE = 4013 + TMT_GLYPHFONTSIZINGTYPE = 4014 + TMT_TRUESIZESCALINGTYPE = 4015 + TMT_USERPICTURE = 5001 + TMT_DEFAULTPANESIZE = 5002 + TMT_BLENDCOLOR = 5003 + TMT_CUSTOMSPLITRECT = 5004 + TMT_ANIMATIONBUTTONRECT = 5005 + TMT_ANIMATIONDURATION = 5006 + TMT_TRANSITIONDURATIONS = 6000 + TMT_SCALEDBACKGROUND = 7001 + TMT_ATLASIMAGE = 8000 + TMT_ATLASINPUTIMAGE = 8001 + TMT_ATLASRECT = 8002 +) + +// Button parts +const ( + BP_PUSHBUTTON = 1 + BP_RADIOBUTTON = 2 + BP_CHECKBOX = 3 + BP_GROUPBOX = 4 + BP_USERBUTTON = 5 + BP_COMMANDLINK = 6 + BP_COMMANDLINKGLYPH = 7 +) + +// Push-button states +const ( + PBS_NORMAL = 1 + PBS_HOT = 2 + PBS_PRESSED = 3 + PBS_DISABLED = 4 + PBS_DEFAULTED = 5 + PBS_DEFAULTED_ANIMATING = 6 +) + +// CheckBox states +const ( + CBS_UNCHECKEDNORMAL = 1 + CBS_UNCHECKEDHOT = 2 + CBS_UNCHECKEDPRESSED = 3 + CBS_UNCHECKEDDISABLED = 4 + CBS_CHECKEDNORMAL = 5 + CBS_CHECKEDHOT = 6 + CBS_CHECKEDPRESSED = 7 + CBS_CHECKEDDISABLED = 8 + CBS_MIXEDNORMAL = 9 + CBS_MIXEDHOT = 10 + CBS_MIXEDPRESSED = 11 + CBS_MIXEDDISABLED = 12 + CBS_IMPLICITNORMAL = 13 + CBS_IMPLICITHOT = 14 + CBS_IMPLICITPRESSED = 15 + CBS_IMPLICITDISABLED = 16 + CBS_EXCLUDEDNORMAL = 17 + CBS_EXCLUDEDHOT = 18 + CBS_EXCLUDEDPRESSED = 19 + CBS_EXCLUDEDDISABLED = 20 +) + +// ListBox parts +const ( + LBCP_ITEM = 5 +) + +// LBCP_ITEM states +const ( + LBPSI_HOT = 1 + LBPSI_HOTSELECTED = 2 + LBPSI_SELECTED = 3 + LBPSI_SELECTEDNOTFOCUS = 4 +) + +// LISTVIEW parts +const ( + LVP_LISTITEM = 1 + LVP_LISTGROUP = 2 + LVP_LISTDETAIL = 3 + LVP_LISTSORTEDDETAIL = 4 + LVP_EMPTYTEXT = 5 + LVP_GROUPHEADER = 6 + LVP_GROUPHEADERLINE = 7 + LVP_EXPANDBUTTON = 8 + LVP_COLLAPSEBUTTON = 9 + LVP_COLUMNDETAIL = 10 +) + +// LVP_LISTITEM states +const ( + LISS_NORMAL = 1 + LISS_HOT = 2 + LISS_SELECTED = 3 + LISS_DISABLED = 4 + LISS_SELECTEDNOTFOCUS = 5 + LISS_HOTSELECTED = 6 +) + +// PROGRESS parts +const ( + PP_BAR = 1 + PP_BARVERT = 2 + PP_CHUNK = 3 + PP_CHUNKVERT = 4 + PP_FILL = 5 + PP_FILLVERT = 6 + PP_PULSEOVERLAY = 7 + PP_MOVEOVERLAY = 8 + PP_PULSEOVERLAYVERT = 9 + PP_MOVEOVERLAYVERT = 10 + PP_TRANSPARENTBAR = 11 + PP_TRANSPARENTBARVERT = 12 +) + +// PP_FILL states +const ( + PBFS_NORMAL = 1 + PBFS_ERROR = 2 + PBFS_PAUSED = 3 + PBFS_PARTIAL = 4 +) + +// PP_FILLVERT states +const ( + PBFVS_NORMAL = 1 + PBFVS_ERROR = 2 + PBFVS_PAUSED = 3 + PBFVS_PARTIAL = 4 +) + +// TAB parts +const ( + TABP_TABITEM = 1 +) + +// TABP_TABITEM states +const ( + TIS_NORMAL = 1 + TIS_HOT = 2 + TIS_SELECTED = 3 + TIS_DISABLED = 4 + TIS_FOCUSED = 5 +) + +// TREEVIEW parts +const ( + TVP_TREEITEM = 1 + TVP_GLYPH = 2 + TVP_BRANCH = 3 + TVP_HOTGLYPH = 4 +) + +// TVP_TREEITEM states +const ( + TREIS_NORMAL = 1 + TREIS_HOT = 2 + TREIS_SELECTED = 3 + TREIS_DISABLED = 4 + TREIS_SELECTEDNOTFOCUS = 5 + TREIS_HOTSELECTED = 6 +) + +// DTTOPTS flags +const ( + DTT_TEXTCOLOR = 1 << 0 + DTT_BORDERCOLOR = 1 << 1 + DTT_SHADOWCOLOR = 1 << 2 + DTT_SHADOWTYPE = 1 << 3 + DTT_SHADOWOFFSET = 1 << 4 + DTT_BORDERSIZE = 1 << 5 + DTT_FONTPROP = 1 << 6 + DTT_COLORPROP = 1 << 7 + DTT_STATEID = 1 << 8 + DTT_CALCRECT = 1 << 9 + DTT_APPLYOVERLAY = 1 << 10 + DTT_GLOWSIZE = 1 << 11 + DTT_CALLBACK = 1 << 12 + DTT_COMPOSITED = 1 << 13 + DTT_VALIDBITS = DTT_TEXTCOLOR | + DTT_BORDERCOLOR | + DTT_SHADOWCOLOR | + DTT_SHADOWTYPE | + DTT_SHADOWOFFSET | + DTT_BORDERSIZE | + DTT_FONTPROP | + DTT_COLORPROP | + DTT_STATEID | + DTT_CALCRECT | + DTT_APPLYOVERLAY | + DTT_GLOWSIZE | + DTT_COMPOSITED +) + +type HTHEME HANDLE + +type THEMESIZE int + +const ( + TS_MIN THEMESIZE = iota + TS_TRUE + TS_DRAW ) +type DTTOPTS struct { + DwSize uint32 + DwFlags uint32 + CrText COLORREF + CrBorder COLORREF + CrShadow COLORREF + ITextShadowType int32 + PtShadowOffset POINT + IBorderSize int32 + IFontPropId int32 + IColorPropId int32 + IStateId int32 + FApplyOverlay BOOL + IGlowSize int32 + PfnDrawTextCallback uintptr + LParam uintptr +} + var ( // Library - libuxtheme uintptr + libuxtheme *windows.LazyDLL // Functions - setWindowTheme uintptr + closeThemeData *windows.LazyProc + drawThemeBackground *windows.LazyProc + drawThemeTextEx *windows.LazyProc + getThemeColor *windows.LazyProc + getThemePartSize *windows.LazyProc + getThemeTextExtent *windows.LazyProc + isAppThemed *windows.LazyProc + openThemeData *windows.LazyProc + setWindowTheme *windows.LazyProc ) func init() { // Library - libuxtheme = MustLoadLibrary("uxtheme.dll") + libuxtheme = windows.NewLazySystemDLL("uxtheme.dll") // Functions - setWindowTheme = MustGetProcAddress(libuxtheme, "SetWindowTheme") + closeThemeData = libuxtheme.NewProc("CloseThemeData") + drawThemeBackground = libuxtheme.NewProc("DrawThemeBackground") + drawThemeTextEx = libuxtheme.NewProc("DrawThemeTextEx") + getThemeColor = libuxtheme.NewProc("GetThemeColor") + getThemePartSize = libuxtheme.NewProc("GetThemePartSize") + getThemeTextExtent = libuxtheme.NewProc("GetThemeTextExtent") + isAppThemed = libuxtheme.NewProc("IsAppThemed") + openThemeData = libuxtheme.NewProc("OpenThemeData") + setWindowTheme = libuxtheme.NewProc("SetWindowTheme") +} + +func CloseThemeData(hTheme HTHEME) HRESULT { + ret, _, _ := syscall.Syscall(closeThemeData.Addr(), 1, + uintptr(hTheme), + 0, + 0) + + return HRESULT(ret) +} + +func DrawThemeBackground(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pRect, pClipRect *RECT) HRESULT { + ret, _, _ := syscall.Syscall6(drawThemeBackground.Addr(), 6, + uintptr(hTheme), + uintptr(hdc), + uintptr(iPartId), + uintptr(iStateId), + uintptr(unsafe.Pointer(pRect)), + uintptr(unsafe.Pointer(pClipRect))) + + return HRESULT(ret) +} + +func DrawThemeTextEx(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwFlags uint32, pRect *RECT, pOptions *DTTOPTS) HRESULT { + if drawThemeTextEx.Find() != nil { + return HRESULT(0) + } + ret, _, _ := syscall.Syscall9(drawThemeTextEx.Addr(), 9, + uintptr(hTheme), + uintptr(hdc), + uintptr(iPartId), + uintptr(iStateId), + uintptr(unsafe.Pointer(pszText)), + uintptr(iCharCount), + uintptr(dwFlags), + uintptr(unsafe.Pointer(pRect)), + uintptr(unsafe.Pointer(pOptions))) + + return HRESULT(ret) +} + +func GetThemeColor(hTheme HTHEME, iPartId, iStateId, iPropId int32, pColor *COLORREF) HRESULT { + ret, _, _ := syscall.Syscall6(getThemeColor.Addr(), 5, + uintptr(hTheme), + uintptr(iPartId), + uintptr(iStateId), + uintptr(iPropId), + uintptr(unsafe.Pointer(pColor)), + 0) + + return HRESULT(ret) +} + +func GetThemePartSize(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, prc *RECT, eSize THEMESIZE, psz *SIZE) HRESULT { + ret, _, _ := syscall.Syscall9(getThemePartSize.Addr(), 7, + uintptr(hTheme), + uintptr(hdc), + uintptr(iPartId), + uintptr(iStateId), + uintptr(unsafe.Pointer(prc)), + uintptr(eSize), + uintptr(unsafe.Pointer(psz)), + 0, + 0) + + return HRESULT(ret) +} + +func GetThemeTextExtent(hTheme HTHEME, hdc HDC, iPartId, iStateId int32, pszText *uint16, iCharCount int32, dwTextFlags uint32, pBoundingRect, pExtentRect *RECT) HRESULT { + ret, _, _ := syscall.Syscall9(getThemeTextExtent.Addr(), 9, + uintptr(hTheme), + uintptr(hdc), + uintptr(iPartId), + uintptr(iStateId), + uintptr(unsafe.Pointer(pszText)), + uintptr(iCharCount), + uintptr(dwTextFlags), + uintptr(unsafe.Pointer(pBoundingRect)), + uintptr(unsafe.Pointer(pExtentRect))) + + return HRESULT(ret) +} + +func IsAppThemed() bool { + ret, _, _ := syscall.Syscall(isAppThemed.Addr(), 0, + 0, + 0, + 0) + + return ret != 0 +} + +func OpenThemeData(hwnd HWND, pszClassList *uint16) HTHEME { + ret, _, _ := syscall.Syscall(openThemeData.Addr(), 2, + uintptr(hwnd), + uintptr(unsafe.Pointer(pszClassList)), + 0) + + return HTHEME(ret) } func SetWindowTheme(hwnd HWND, pszSubAppName, pszSubIdList *uint16) HRESULT { - ret, _, _ := syscall.Syscall(setWindowTheme, 3, + ret, _, _ := syscall.Syscall(setWindowTheme.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(pszSubAppName)), uintptr(unsafe.Pointer(pszSubIdList))) diff --git a/win.go b/win.go index f5d660af..b8f00cd6 100644 --- a/win.go +++ b/win.go @@ -2,17 +2,15 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( - "runtime" - "syscall" "unsafe" -) -func init() { - runtime.LockOSThread() -} + "golang.org/x/sys/windows" +) const ( S_OK = 0x00000000 @@ -40,31 +38,6 @@ type ( HRESULT int32 ) -type GUID struct { - Data1 uint32 - Data2 uint16 - Data3 uint16 - Data4 [8]byte -} - -func MustLoadLibrary(name string) uintptr { - lib, err := syscall.LoadLibrary(name) - if err != nil { - panic(err) - } - - return uintptr(lib) -} - -func MustGetProcAddress(lib uintptr, name string) uintptr { - addr, err := syscall.GetProcAddress(syscall.Handle(lib), name) - if err != nil { - panic(err) - } - - return uintptr(addr) -} - func SUCCEEDED(hr HRESULT) bool { return hr >= 0 } @@ -98,10 +71,7 @@ func HIWORD(dw uint32) uint16 { } func UTF16PtrToString(s *uint16) string { - if s == nil { - return "" - } - return syscall.UTF16ToString((*[1 << 29]uint16)(unsafe.Pointer(s))[0:]) + return windows.UTF16PtrToString(s) } func MAKEINTRESOURCE(id uintptr) *uint16 { diff --git a/winnls.go b/winnls.go new file mode 100644 index 00000000..13845962 --- /dev/null +++ b/winnls.go @@ -0,0 +1,20 @@ +// Copyright 2010 The win Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package win + +const ( + // Code Page Default Values. + // Please Use Unicode, either UTF-16 (as in WCHAR) or UTF-8 (code page CP_ACP) + CP_ACP = 0 // default to ANSI code page + CP_OEMCP = 1 // default to OEM code page + CP_MACCP = 2 // default to MAC code page + CP_THREAD_ACP = 3 // current thread's ANSI code page + CP_SYMBOL = 42 // SYMBOL translations + + CP_UTF7 = 65000 // UTF-7 translation + CP_UTF8 = 65001 // UTF-8 translation +) diff --git a/winspool.go b/winspool.go index 153b7cb7..4ee34eff 100644 --- a/winspool.go +++ b/winspool.go @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package win import ( + "golang.org/x/sys/windows" "syscall" "unsafe" ) @@ -29,28 +32,28 @@ type PRINTER_INFO_4 struct { var ( // Library - libwinspool uintptr + libwinspool *windows.LazyDLL // Functions - deviceCapabilities uintptr - documentProperties uintptr - enumPrinters uintptr - getDefaultPrinter uintptr + deviceCapabilities *windows.LazyProc + documentProperties *windows.LazyProc + enumPrinters *windows.LazyProc + getDefaultPrinter *windows.LazyProc ) func init() { // Library - libwinspool = MustLoadLibrary("winspool.drv") + libwinspool = windows.NewLazySystemDLL("winspool.drv") // Functions - deviceCapabilities = MustGetProcAddress(libwinspool, "DeviceCapabilitiesW") - documentProperties = MustGetProcAddress(libwinspool, "DocumentPropertiesW") - enumPrinters = MustGetProcAddress(libwinspool, "EnumPrintersW") - getDefaultPrinter = MustGetProcAddress(libwinspool, "GetDefaultPrinterW") + deviceCapabilities = libwinspool.NewProc("DeviceCapabilitiesW") + documentProperties = libwinspool.NewProc("DocumentPropertiesW") + enumPrinters = libwinspool.NewProc("EnumPrintersW") + getDefaultPrinter = libwinspool.NewProc("GetDefaultPrinterW") } func DeviceCapabilities(pDevice, pPort *uint16, fwCapability uint16, pOutput *uint16, pDevMode *DEVMODE) uint32 { - ret, _, _ := syscall.Syscall6(deviceCapabilities, 5, + ret, _, _ := syscall.Syscall6(deviceCapabilities.Addr(), 5, uintptr(unsafe.Pointer(pDevice)), uintptr(unsafe.Pointer(pPort)), uintptr(fwCapability), @@ -62,7 +65,7 @@ func DeviceCapabilities(pDevice, pPort *uint16, fwCapability uint16, pOutput *ui } func DocumentProperties(hWnd HWND, hPrinter HANDLE, pDeviceName *uint16, pDevModeOutput, pDevModeInput *DEVMODE, fMode uint32) int32 { - ret, _, _ := syscall.Syscall6(documentProperties, 6, + ret, _, _ := syscall.Syscall6(documentProperties.Addr(), 6, uintptr(hWnd), uintptr(hPrinter), uintptr(unsafe.Pointer(pDeviceName)), @@ -74,7 +77,7 @@ func DocumentProperties(hWnd HWND, hPrinter HANDLE, pDeviceName *uint16, pDevMod } func EnumPrinters(Flags uint32, Name *uint16, Level uint32, pPrinterEnum *byte, cbBuf uint32, pcbNeeded, pcReturned *uint32) bool { - ret, _, _ := syscall.Syscall9(enumPrinters, 7, + ret, _, _ := syscall.Syscall9(enumPrinters.Addr(), 7, uintptr(Flags), uintptr(unsafe.Pointer(Name)), uintptr(Level), @@ -89,7 +92,7 @@ func EnumPrinters(Flags uint32, Name *uint16, Level uint32, pPrinterEnum *byte, } func GetDefaultPrinter(pszBuffer *uint16, pcchBuffer *uint32) bool { - ret, _, _ := syscall.Syscall(getDefaultPrinter, 2, + ret, _, _ := syscall.Syscall(getDefaultPrinter.Addr(), 2, uintptr(unsafe.Pointer(pszBuffer)), uintptr(unsafe.Pointer(pcchBuffer)), 0)