go-tg-screenshot-bot
224 строки · 5.1 Кб
1// Copyright 2010 The win Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build windows
6
7package win8
9import (10"golang.org/x/sys/windows"11"syscall"12"unsafe"13)
14
15type GpStatus int3216
17const (18Ok GpStatus = 019GenericError GpStatus = 120InvalidParameter GpStatus = 221OutOfMemory GpStatus = 322ObjectBusy GpStatus = 423InsufficientBuffer GpStatus = 524NotImplemented GpStatus = 625Win32Error GpStatus = 726WrongState GpStatus = 827Aborted GpStatus = 928FileNotFound GpStatus = 1029ValueOverflow GpStatus = 1130AccessDenied GpStatus = 1231UnknownImageFormat GpStatus = 1332FontFamilyNotFound GpStatus = 1433FontStyleNotFound GpStatus = 1534NotTrueTypeFont GpStatus = 1635UnsupportedGdiplusVersion GpStatus = 1736GdiplusNotInitialized GpStatus = 1837PropertyNotFound GpStatus = 1938PropertyNotSupported GpStatus = 2039ProfileNotFound GpStatus = 2140)
41
42func (s GpStatus) String() string {43switch s {44case Ok:45return "Ok"46
47case GenericError:48return "GenericError"49
50case InvalidParameter:51return "InvalidParameter"52
53case OutOfMemory:54return "OutOfMemory"55
56case ObjectBusy:57return "ObjectBusy"58
59case InsufficientBuffer:60return "InsufficientBuffer"61
62case NotImplemented:63return "NotImplemented"64
65case Win32Error:66return "Win32Error"67
68case WrongState:69return "WrongState"70
71case Aborted:72return "Aborted"73
74case FileNotFound:75return "FileNotFound"76
77case ValueOverflow:78return "ValueOverflow"79
80case AccessDenied:81return "AccessDenied"82
83case UnknownImageFormat:84return "UnknownImageFormat"85
86case FontFamilyNotFound:87return "FontFamilyNotFound"88
89case FontStyleNotFound:90return "FontStyleNotFound"91
92case NotTrueTypeFont:93return "NotTrueTypeFont"94
95case UnsupportedGdiplusVersion:96return "UnsupportedGdiplusVersion"97
98case GdiplusNotInitialized:99return "GdiplusNotInitialized"100
101case PropertyNotFound:102return "PropertyNotFound"103
104case PropertyNotSupported:105return "PropertyNotSupported"106
107case ProfileNotFound:108return "ProfileNotFound"109}110
111return "Unknown Status Value"112}
113
114type GdiplusStartupInput struct {115GdiplusVersion uint32116DebugEventCallback uintptr117SuppressBackgroundThread BOOL
118SuppressExternalCodecs BOOL
119}
120
121type GdiplusStartupOutput struct {122NotificationHook uintptr123NotificationUnhook uintptr124}
125
126type GpImage struct{}127
128type GpBitmap GpImage129
130type ARGB uint32131
132var (133// Library134libgdiplus *windows.LazyDLL135
136// Functions137gdipCreateBitmapFromFile *windows.LazyProc138gdipCreateBitmapFromHBITMAP *windows.LazyProc139gdipCreateHBITMAPFromBitmap *windows.LazyProc140gdipDisposeImage *windows.LazyProc141gdiplusShutdown *windows.LazyProc142gdiplusStartup *windows.LazyProc143)
144
145var (146token uintptr147)
148
149func init() {150// Library151libgdiplus = windows.NewLazySystemDLL("gdiplus.dll")152
153// Functions154gdipCreateBitmapFromFile = libgdiplus.NewProc("GdipCreateBitmapFromFile")155gdipCreateBitmapFromHBITMAP = libgdiplus.NewProc("GdipCreateBitmapFromHBITMAP")156gdipCreateHBITMAPFromBitmap = libgdiplus.NewProc("GdipCreateHBITMAPFromBitmap")157gdipDisposeImage = libgdiplus.NewProc("GdipDisposeImage")158gdiplusShutdown = libgdiplus.NewProc("GdiplusShutdown")159gdiplusStartup = libgdiplus.NewProc("GdiplusStartup")160}
161
162func GdipCreateBitmapFromFile(filename *uint16, bitmap **GpBitmap) GpStatus {163ret, _, _ := syscall.Syscall(gdipCreateBitmapFromFile.Addr(), 2,164uintptr(unsafe.Pointer(filename)),165uintptr(unsafe.Pointer(bitmap)),1660)167
168return GpStatus(ret)169}
170
171func GdipCreateBitmapFromHBITMAP(hbm HBITMAP, hpal HPALETTE, bitmap **GpBitmap) GpStatus {172ret, _, _ := syscall.Syscall(gdipCreateBitmapFromHBITMAP.Addr(), 3,173uintptr(hbm),174uintptr(hpal),175uintptr(unsafe.Pointer(bitmap)))176
177return GpStatus(ret)178}
179
180func GdipCreateHBITMAPFromBitmap(bitmap *GpBitmap, hbmReturn *HBITMAP, background ARGB) GpStatus {181ret, _, _ := syscall.Syscall(gdipCreateHBITMAPFromBitmap.Addr(), 3,182uintptr(unsafe.Pointer(bitmap)),183uintptr(unsafe.Pointer(hbmReturn)),184uintptr(background))185
186return GpStatus(ret)187}
188
189func GdipDisposeImage(image *GpImage) GpStatus {190ret, _, _ := syscall.Syscall(gdipDisposeImage.Addr(), 1,191uintptr(unsafe.Pointer(image)),1920,1930)194
195return GpStatus(ret)196}
197
198func GdiplusShutdown() {199syscall.Syscall(gdiplusShutdown.Addr(), 1,200token,2010,2020)203}
204
205func GdiplusStartup(input *GdiplusStartupInput, output *GdiplusStartupOutput) GpStatus {206ret, _, _ := syscall.Syscall(gdiplusStartup.Addr(), 3,207uintptr(unsafe.Pointer(&token)),208uintptr(unsafe.Pointer(input)),209uintptr(unsafe.Pointer(output)))210
211return GpStatus(ret)212}
213
214/*GdipSaveImageToFile(image *GpImage, filename *uint16, clsidEncoder *CLSID, encoderParams *EncoderParameters) GpStatus {
215ret, _, _ := syscall.Syscall6(gdipSaveImageToFile.Addr(), 4,
216uintptr(unsafe.Pointer(image)),
217uintptr(unsafe.Pointer(filename)),
218uintptr(unsafe.Pointer(clsidEncoder)),
219uintptr(unsafe.Pointer(encoderParams)),
2200,
2210)
222
223return GpStatus(ret)
224}*/
225