-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdll_gdi32_windows.go
323 lines (294 loc) · 11.3 KB
/
dll_gdi32_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// -----------------------------------------------------------------------------
// ZR Library: Windows 32 API zr-win/[dll_gdi32_windows.go]
// (c) [email protected] License: MIT
// -----------------------------------------------------------------------------
package win
import (
"syscall"
"unicode/utf8"
"unsafe"
"github.com/balacode/zr"
)
var (
gdi32 = syscall.NewLazyDLL("gdi32.dll")
gdiBitBlt = gdi32.NewProc("BitBlt")
gdiCreateCompatibleBitmap = gdi32.NewProc("CreateCompatibleBitmap")
gdiCreateCompatibleDC = gdi32.NewProc("CreateCompatibleDC")
gdiCreateFontIndirectW = gdi32.NewProc("CreateFontIndirectW")
gdiCreateFontW = gdi32.NewProc("CreateFontW")
gdiCreateRectRgn = gdi32.NewProc("CreateRectRgn")
gdiCreateSolidBrush = gdi32.NewProc("CreateSolidBrush")
gdiDeleteDC = gdi32.NewProc("DeleteDC")
gdiDeleteObject = gdi32.NewProc("DeleteObject")
gdiGetDeviceCaps = gdi32.NewProc("GetDeviceCaps")
gdiGetTextExtentPoint32W = gdi32.NewProc("GetTextExtentPoint32W")
gdiGetTextMetricsW = gdi32.NewProc("GetTextMetricsW")
gdiSelectClipRgn = gdi32.NewProc("SelectClipRgn")
gdiSelectObject = gdi32.NewProc("SelectObject")
gdiSetBkColor = gdi32.NewProc("SetBkColor")
gdiSetMapMode = gdi32.NewProc("SetMapMode")
gdiSetTextColor = gdi32.NewProc("SetTextColor")
gdiSetWindowOrgEx = gdi32.NewProc("SetWindowOrgEx")
gdiTextOutW = gdi32.NewProc("TextOutW")
// not used:
// gdiGetStockObject = gdi32.NewProc("GetStockObject")
// gdiIntersectClipRect = gdi32.NewProc("IntersectClipRect")
// gdiSetDCBrushColor = gdi32.NewProc("SetDCBrushColor")
)
// BitBlt library: gdi32.dll
func BitBlt(
hdcDest HDC,
nXDest INT,
nYDest INT,
nWidth INT,
nHeight INT,
hdcSrc HDC,
nXSrc INT,
nYSrc INT,
dwRop DWORD,
) BOOL {
ret, _, _ := gdiBitBlt.Call(
uintptr(hdcDest), // handle to destination DC
uintptr(nXDest), // x-coord of destination upper-left corner
uintptr(nYDest), // y-coord of destination upper-left corner
uintptr(nWidth), // width of destination rectangle
uintptr(nHeight), // height of destination rectangle
uintptr(hdcSrc), // handle to source DC
uintptr(nXSrc), // x-coordinate of source upper-left corner
uintptr(nYSrc), // y-coordinate of source upper-left corner
uintptr(dwRop), // raster operation code
)
return BOOLResult(ret)
} // BitBlt
// CreateCompatibleBitmap library: gdi32.dll
func CreateCompatibleBitmap(hDC HDC, cx, cy INT) HBITMAP {
ret, _, _ := gdiCreateCompatibleBitmap.Call(
uintptr(hDC), // HDC: handle to DC
uintptr(cx), // int: width of bitmap, in pixels
uintptr(cy), // int: height of bitmap, in pixels
)
return HBITMAP(ret)
} // CreateCompatibleBitmap
// CreateCompatibleDC library: gdi32.dll
func CreateCompatibleDC(hDC HDC) HDC {
ret, _, _ := gdiCreateCompatibleDC.Call(uintptr(hDC)) // HDC:handle to DC
return HDC(ret)
} // CreateCompatibleDC
// CreateFont library: gdi32.dll
func CreateFont(
cHeight INT,
cWidth INT,
cEscapement INT,
cOrientation INT,
cWeight INT,
bItalic DWORD,
bUnderline DWORD,
bStrikeOut DWORD,
iCharSet DWORD,
iOutPrecision DWORD,
iClipPrecision DWORD,
iQuality DWORD,
iPitchAndFamily DWORD,
pszFaceName string,
) HFONT {
ret, _, _ := gdiCreateFontW.Call(
uintptr(cHeight), // int: height of font
uintptr(cWidth), // int: average character width
uintptr(cEscapement), // int: angle of escapement
uintptr(cOrientation), // int: base-line orientation angle
uintptr(cWeight), // int: font weight
uintptr(bItalic), // DWORD: italic attribute option
uintptr(bUnderline), // DWORD: underline attribute option
uintptr(bStrikeOut), // DWORD: strikeout attribute option
uintptr(iCharSet), // DWORD: character set identifier
uintptr(iOutPrecision), // DWORD: output precision
uintptr(iClipPrecision), // DWORD: clipping precision
uintptr(iQuality), // DWORD: output quality
uintptr(iPitchAndFamily), // DWORD: pitch and family
UintptrFromString(&pszFaceName), // LPCTSTR: typeface name
)
return HFONT(ret)
} // CreateFont
// CreateFontIndirect library: gdi32.dll
func CreateFontIndirect(lplf *LOGFONT) HFONT {
ret, _, _ := gdiCreateFontIndirectW.Call(uintptr(unsafe.Pointer(lplf)))
return HFONT(ret)
} // CreateFontIndirect
// CreateRectRgn library: gdi32.dll
func CreateRectRgn(
nLeftRect INT,
nTopRect INT,
nRightRect INT,
nBottomRect INT,
) HRGN {
ret, _, _ := gdiCreateRectRgn.Call(
uintptr(nLeftRect), // x-coord of upper-left corner
uintptr(nTopRect), // y-coord of upper-left corner
uintptr(nRightRect), // x-coord of lower-right corner
uintptr(nBottomRect), // y-coord of lower-right corner
)
return HRGN(ret)
} // CreateRectRgn
// CreateSolidBrush library: gdi32.dll
func CreateSolidBrush(color COLORREF) HBRUSH {
ret, _, _ := gdiCreateSolidBrush.Call(uintptr(color))
return HBRUSH(ret)
} // CreateSolidBrush
// DeleteDC library: gdi32.dll
func DeleteDC(hDC HDC) BOOL {
ret, _, _ := gdiDeleteDC.Call(uintptr(hDC))
return BOOLResult(ret)
} // DeleteDC
// DeleteObject library: gdi32.dll
func DeleteObject(hObj HGDIOBJ) BOOL {
ret, _, _ := gdiDeleteObject.Call(uintptr(hObj))
return BOOLResult(ret)
} // DeleteObject
// GetDeviceCaps library: gdi32.dll
func GetDeviceCaps(
hDC HDC, // handle to DC
nIndex INT, // index of capability
) INT {
ret, _, _ := gdiGetDeviceCaps.Call(uintptr(hDC), uintptr(nIndex))
return INT(ret)
} // GetDeviceCaps
// UNUSED
// // GetStockObject library: gdi32.dll
// func GetStockObject(fnObject INT) HGDIOBJ {
// ret, _, _ := gdiGetStockObject.Call(
// uintptr(fnObject)) // int: stock object type
// )
// return HGDIOBJ(ret)
// } // GetStockObject
// GetTextExtentPoint32 library: gdi32.dll
func GetTextExtentPoint32(
hDC HDC, // handle to DC
Text string, // text string
c INT, // number of characters in string
lpSize *SIZE, // string size
) BOOL {
blankStr := c == 0 || len(Text) == 0
if blankStr {
Text, c = " ", 1
}
charCount := utf8.RuneCountInString(Text)
if charCount != int(c) {
zr.Error("GetTextExtentPoint32() has inconsistent arguments:",
"runes in text", charCount, "!= c ", c)
c = INT(charCount)
}
ret, _, _ := gdiGetTextExtentPoint32W.Call(
uintptr(hDC),
UintptrFromString(&Text),
uintptr(c),
uintptr(unsafe.Pointer(lpSize)),
)
if blankStr {
(*lpSize).Cx = 0
}
return BOOLResult(ret)
} // GetTextExtentPoint32
// GetTextMetrics library: gdi32.dll
func GetTextMetrics(
hDC HDC, // handle to DC
lptm *TEXTMETRIC, // text metrics
) BOOL {
ret, _, _ := gdiGetTextMetricsW.Call(
uintptr(hDC),
uintptr(unsafe.Pointer(lptm)),
)
return BOOLResult(ret)
} // GetTextMetrics
// // IntersectClipRect library: gdi32.dll
// func IntersectClipRect(
// hDC HDC,
// nLeftRect INT,
// nTopRect INT,
// nRightRect INT,
// nBottomRect INT,
// ) INT {
// ret, _, _ := gdiIntersectClipRect.Call(
// uintptr(hDC), // handle to DC
// uintptr(nLeftRect), // x-coord of upper-left corner
// uintptr(nTopRect), // y-coord of upper-left corner
// uintptr(nRightRect), // x-coord of lower-right corner
// uintptr(nBottomRect), // y-coord of lower-right corner
// )
// return INT(ret)
// } // IntersectClipRect
// SelectClipRgn library: gdi32.dll
func SelectClipRgn(hDC HDC, hRgn HRGN) INT {
ret, _, _ := gdiSelectClipRgn.Call(
uintptr(hDC), // handle to DC
uintptr(hRgn), // handle to region
)
return INT(ret)
} // SelectClipRgn
// SelectObject library: gdi32.dll
func SelectObject(hDC HDC, hGdiObj HGDIOBJ) HGDIOBJ {
ret, _, _ := gdiSelectObject.Call(
uintptr(hDC), // HDC: handle to DC
uintptr(hGdiObj), // HGDIOBJ: handle to object
)
return HGDIOBJ(ret)
} // SelectObject
// SetBkColor library: gdi32.dll
func SetBkColor(hDC HDC, color COLORREF) COLORREF {
ret, _, _ := gdiSetBkColor.Call(
uintptr(hDC), // HDC: handle to DC
uintptr(color), // COLORREF: background color value
)
return COLORREF(ret)
} // SetBkColor
// UNUSED
// // SetDCBrushColor library: gdi32.dll
// func SetDCBrushColor(hDC HDC, crColor COLORREF) COLORREF {
// ret, _, _ := gdiSetDCBrushColor.Call(
// uintptr(hDC), // HDC: handle to DC
// uintptr(crColor), // COLORREF: new brush color
// )
// return COLORREF(ret)
// } // SetDCBrushColor
// SetMapMode library: gdi32.dll
func SetMapMode(hDC HDC, fnMapMode INT) INT {
ret, _, _ := gdiSetMapMode.Call(
uintptr(hDC), // HDC: handle to device context
uintptr(fnMapMode), // int: new mapping mode
)
return INT(ret)
} // SetMapMode
// SetTextColor library: gdi32.dll
func SetTextColor(hDC HDC, color COLORREF) COLORREF {
ret, _, _ := gdiSetTextColor.Call(
uintptr(hDC), // HDC: handle to DC
uintptr(color), // COLORREF: text color
)
return COLORREF(ret)
} // SetTextColor
// SetWindowOrgEx library: gdi32.dll
func SetWindowOrgEx(
hDC HDC,
X INT,
Y INT,
lpPoint *POINT,
) BOOL {
ret, _, _ := gdiSetWindowOrgEx.Call(
uintptr(hDC), // HDC: handle to device context
uintptr(X), // int: new x-coord of window origin
uintptr(Y), // int: new y-coord of window origin
uintptr(unsafe.Pointer(lpPoint)), // LPPOINT : original window origin
)
return BOOLResult(ret)
} // SetWindowOrgEx
// TextOut library: gdi32.dll
func TextOut(hDC HDC, x, y INT, Text string, c INT) BOOL {
ret, _, _ := gdiTextOutW.Call(
uintptr(hDC), // HDC: handle to DC
uintptr(x), // int: x-coordinate of starting position
uintptr(y), // int: y-coordinate of starting position
UintptrFromString(&Text), // LPCTSTR: character string
uintptr(c), // int: number of characters
)
return BOOLResult(ret)
} // TextOut
// end