go-tg-screenshot-bot

Форк
0
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

7
package win
8

9
import (
10
	"golang.org/x/sys/windows"
11
	"syscall"
12
	"unsafe"
13
)
14

15
type GpStatus int32
16

17
const (
18
	Ok                        GpStatus = 0
19
	GenericError              GpStatus = 1
20
	InvalidParameter          GpStatus = 2
21
	OutOfMemory               GpStatus = 3
22
	ObjectBusy                GpStatus = 4
23
	InsufficientBuffer        GpStatus = 5
24
	NotImplemented            GpStatus = 6
25
	Win32Error                GpStatus = 7
26
	WrongState                GpStatus = 8
27
	Aborted                   GpStatus = 9
28
	FileNotFound              GpStatus = 10
29
	ValueOverflow             GpStatus = 11
30
	AccessDenied              GpStatus = 12
31
	UnknownImageFormat        GpStatus = 13
32
	FontFamilyNotFound        GpStatus = 14
33
	FontStyleNotFound         GpStatus = 15
34
	NotTrueTypeFont           GpStatus = 16
35
	UnsupportedGdiplusVersion GpStatus = 17
36
	GdiplusNotInitialized     GpStatus = 18
37
	PropertyNotFound          GpStatus = 19
38
	PropertyNotSupported      GpStatus = 20
39
	ProfileNotFound           GpStatus = 21
40
)
41

42
func (s GpStatus) String() string {
43
	switch s {
44
	case Ok:
45
		return "Ok"
46

47
	case GenericError:
48
		return "GenericError"
49

50
	case InvalidParameter:
51
		return "InvalidParameter"
52

53
	case OutOfMemory:
54
		return "OutOfMemory"
55

56
	case ObjectBusy:
57
		return "ObjectBusy"
58

59
	case InsufficientBuffer:
60
		return "InsufficientBuffer"
61

62
	case NotImplemented:
63
		return "NotImplemented"
64

65
	case Win32Error:
66
		return "Win32Error"
67

68
	case WrongState:
69
		return "WrongState"
70

71
	case Aborted:
72
		return "Aborted"
73

74
	case FileNotFound:
75
		return "FileNotFound"
76

77
	case ValueOverflow:
78
		return "ValueOverflow"
79

80
	case AccessDenied:
81
		return "AccessDenied"
82

83
	case UnknownImageFormat:
84
		return "UnknownImageFormat"
85

86
	case FontFamilyNotFound:
87
		return "FontFamilyNotFound"
88

89
	case FontStyleNotFound:
90
		return "FontStyleNotFound"
91

92
	case NotTrueTypeFont:
93
		return "NotTrueTypeFont"
94

95
	case UnsupportedGdiplusVersion:
96
		return "UnsupportedGdiplusVersion"
97

98
	case GdiplusNotInitialized:
99
		return "GdiplusNotInitialized"
100

101
	case PropertyNotFound:
102
		return "PropertyNotFound"
103

104
	case PropertyNotSupported:
105
		return "PropertyNotSupported"
106

107
	case ProfileNotFound:
108
		return "ProfileNotFound"
109
	}
110

111
	return "Unknown Status Value"
112
}
113

114
type GdiplusStartupInput struct {
115
	GdiplusVersion           uint32
116
	DebugEventCallback       uintptr
117
	SuppressBackgroundThread BOOL
118
	SuppressExternalCodecs   BOOL
119
}
120

121
type GdiplusStartupOutput struct {
122
	NotificationHook   uintptr
123
	NotificationUnhook uintptr
124
}
125

126
type GpImage struct{}
127

128
type GpBitmap GpImage
129

130
type ARGB uint32
131

132
var (
133
	// Library
134
	libgdiplus *windows.LazyDLL
135

136
	// Functions
137
	gdipCreateBitmapFromFile    *windows.LazyProc
138
	gdipCreateBitmapFromHBITMAP *windows.LazyProc
139
	gdipCreateHBITMAPFromBitmap *windows.LazyProc
140
	gdipDisposeImage            *windows.LazyProc
141
	gdiplusShutdown             *windows.LazyProc
142
	gdiplusStartup              *windows.LazyProc
143
)
144

145
var (
146
	token uintptr
147
)
148

149
func init() {
150
	// Library
151
	libgdiplus = windows.NewLazySystemDLL("gdiplus.dll")
152

153
	// Functions
154
	gdipCreateBitmapFromFile = libgdiplus.NewProc("GdipCreateBitmapFromFile")
155
	gdipCreateBitmapFromHBITMAP = libgdiplus.NewProc("GdipCreateBitmapFromHBITMAP")
156
	gdipCreateHBITMAPFromBitmap = libgdiplus.NewProc("GdipCreateHBITMAPFromBitmap")
157
	gdipDisposeImage = libgdiplus.NewProc("GdipDisposeImage")
158
	gdiplusShutdown = libgdiplus.NewProc("GdiplusShutdown")
159
	gdiplusStartup = libgdiplus.NewProc("GdiplusStartup")
160
}
161

162
func GdipCreateBitmapFromFile(filename *uint16, bitmap **GpBitmap) GpStatus {
163
	ret, _, _ := syscall.Syscall(gdipCreateBitmapFromFile.Addr(), 2,
164
		uintptr(unsafe.Pointer(filename)),
165
		uintptr(unsafe.Pointer(bitmap)),
166
		0)
167

168
	return GpStatus(ret)
169
}
170

171
func GdipCreateBitmapFromHBITMAP(hbm HBITMAP, hpal HPALETTE, bitmap **GpBitmap) GpStatus {
172
	ret, _, _ := syscall.Syscall(gdipCreateBitmapFromHBITMAP.Addr(), 3,
173
		uintptr(hbm),
174
		uintptr(hpal),
175
		uintptr(unsafe.Pointer(bitmap)))
176

177
	return GpStatus(ret)
178
}
179

180
func GdipCreateHBITMAPFromBitmap(bitmap *GpBitmap, hbmReturn *HBITMAP, background ARGB) GpStatus {
181
	ret, _, _ := syscall.Syscall(gdipCreateHBITMAPFromBitmap.Addr(), 3,
182
		uintptr(unsafe.Pointer(bitmap)),
183
		uintptr(unsafe.Pointer(hbmReturn)),
184
		uintptr(background))
185

186
	return GpStatus(ret)
187
}
188

189
func GdipDisposeImage(image *GpImage) GpStatus {
190
	ret, _, _ := syscall.Syscall(gdipDisposeImage.Addr(), 1,
191
		uintptr(unsafe.Pointer(image)),
192
		0,
193
		0)
194

195
	return GpStatus(ret)
196
}
197

198
func GdiplusShutdown() {
199
	syscall.Syscall(gdiplusShutdown.Addr(), 1,
200
		token,
201
		0,
202
		0)
203
}
204

205
func GdiplusStartup(input *GdiplusStartupInput, output *GdiplusStartupOutput) GpStatus {
206
	ret, _, _ := syscall.Syscall(gdiplusStartup.Addr(), 3,
207
		uintptr(unsafe.Pointer(&token)),
208
		uintptr(unsafe.Pointer(input)),
209
		uintptr(unsafe.Pointer(output)))
210

211
	return GpStatus(ret)
212
}
213

214
/*GdipSaveImageToFile(image *GpImage, filename *uint16, clsidEncoder *CLSID, encoderParams *EncoderParameters) GpStatus {
215
	ret, _, _ := syscall.Syscall6(gdipSaveImageToFile.Addr(), 4,
216
		uintptr(unsafe.Pointer(image)),
217
		uintptr(unsafe.Pointer(filename)),
218
		uintptr(unsafe.Pointer(clsidEncoder)),
219
		uintptr(unsafe.Pointer(encoderParams)),
220
		0,
221
		0)
222

223
	return GpStatus(ret)
224
}*/
225

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.