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 Wrapper for gdi32.dll in ctypes.
33 """
34
35 __revision__ = "$Id: gdi32.py 1299 2013-12-20 09:30:55Z qvasimodo $"
36
37 from defines import *
38 from kernel32 import GetLastError, SetLastError
39
40
41
42 _all = None
43 _all = set(vars().keys())
44
45
46
47
48
49
50
51
52
53 OBJ_PEN = 1
54 OBJ_BRUSH = 2
55 OBJ_DC = 3
56 OBJ_METADC = 4
57 OBJ_PAL = 5
58 OBJ_FONT = 6
59 OBJ_BITMAP = 7
60 OBJ_REGION = 8
61 OBJ_METAFILE = 9
62 OBJ_MEMDC = 10
63 OBJ_EXTPEN = 11
64 OBJ_ENHMETADC = 12
65 OBJ_ENHMETAFILE = 13
66 OBJ_COLORSPACE = 14
67 GDI_OBJ_LAST = OBJ_COLORSPACE
68
69
70 SRCCOPY = 0x00CC0020
71 SRCPAINT = 0x00EE0086
72 SRCAND = 0x008800C6
73 SRCINVERT = 0x00660046
74 SRCERASE = 0x00440328
75 NOTSRCCOPY = 0x00330008
76 NOTSRCERASE = 0x001100A6
77 MERGECOPY = 0x00C000CA
78 MERGEPAINT = 0x00BB0226
79 PATCOPY = 0x00F00021
80 PATPAINT = 0x00FB0A09
81 PATINVERT = 0x005A0049
82 DSTINVERT = 0x00550009
83 BLACKNESS = 0x00000042
84 WHITENESS = 0x00FF0062
85 NOMIRRORBITMAP = 0x80000000
86 CAPTUREBLT = 0x40000000
87
88
89 ERROR = 0
90 NULLREGION = 1
91 SIMPLEREGION = 2
92 COMPLEXREGION = 3
93 RGN_ERROR = ERROR
94
95
96 RGN_AND = 1
97 RGN_OR = 2
98 RGN_XOR = 3
99 RGN_DIFF = 4
100 RGN_COPY = 5
101 RGN_MIN = RGN_AND
102 RGN_MAX = RGN_COPY
103
104
105 BLACKONWHITE = 1
106 WHITEONBLACK = 2
107 COLORONCOLOR = 3
108 HALFTONE = 4
109 MAXSTRETCHBLTMODE = 4
110 STRETCH_ANDSCANS = BLACKONWHITE
111 STRETCH_ORSCANS = WHITEONBLACK
112 STRETCH_DELETESCANS = COLORONCOLOR
113 STRETCH_HALFTONE = HALFTONE
114
115
116 ALTERNATE = 1
117 WINDING = 2
118 POLYFILL_LAST = 2
119
120
121 LAYOUT_RTL = 0x00000001
122 LAYOUT_BTT = 0x00000002
123 LAYOUT_VBH = 0x00000004
124 LAYOUT_ORIENTATIONMASK = LAYOUT_RTL + LAYOUT_BTT + LAYOUT_VBH
125 LAYOUT_BITMAPORIENTATIONPRESERVED = 0x00000008
126
127
128 WHITE_BRUSH = 0
129 LTGRAY_BRUSH = 1
130 GRAY_BRUSH = 2
131 DKGRAY_BRUSH = 3
132 BLACK_BRUSH = 4
133 NULL_BRUSH = 5
134 HOLLOW_BRUSH = NULL_BRUSH
135 WHITE_PEN = 6
136 BLACK_PEN = 7
137 NULL_PEN = 8
138 OEM_FIXED_FONT = 10
139 ANSI_FIXED_FONT = 11
140 ANSI_VAR_FONT = 12
141 SYSTEM_FONT = 13
142 DEVICE_DEFAULT_FONT = 14
143 DEFAULT_PALETTE = 15
144 SYSTEM_FIXED_FONT = 16
145
146
147 META_SETBKCOLOR = 0x0201
148 META_SETBKMODE = 0x0102
149 META_SETMAPMODE = 0x0103
150 META_SETROP2 = 0x0104
151 META_SETRELABS = 0x0105
152 META_SETPOLYFILLMODE = 0x0106
153 META_SETSTRETCHBLTMODE = 0x0107
154 META_SETTEXTCHAREXTRA = 0x0108
155 META_SETTEXTCOLOR = 0x0209
156 META_SETTEXTJUSTIFICATION = 0x020A
157 META_SETWINDOWORG = 0x020B
158 META_SETWINDOWEXT = 0x020C
159 META_SETVIEWPORTORG = 0x020D
160 META_SETVIEWPORTEXT = 0x020E
161 META_OFFSETWINDOWORG = 0x020F
162 META_SCALEWINDOWEXT = 0x0410
163 META_OFFSETVIEWPORTORG = 0x0211
164 META_SCALEVIEWPORTEXT = 0x0412
165 META_LINETO = 0x0213
166 META_MOVETO = 0x0214
167 META_EXCLUDECLIPRECT = 0x0415
168 META_INTERSECTCLIPRECT = 0x0416
169 META_ARC = 0x0817
170 META_ELLIPSE = 0x0418
171 META_FLOODFILL = 0x0419
172 META_PIE = 0x081A
173 META_RECTANGLE = 0x041B
174 META_ROUNDRECT = 0x061C
175 META_PATBLT = 0x061D
176 META_SAVEDC = 0x001E
177 META_SETPIXEL = 0x041F
178 META_OFFSETCLIPRGN = 0x0220
179 META_TEXTOUT = 0x0521
180 META_BITBLT = 0x0922
181 META_STRETCHBLT = 0x0B23
182 META_POLYGON = 0x0324
183 META_POLYLINE = 0x0325
184 META_ESCAPE = 0x0626
185 META_RESTOREDC = 0x0127
186 META_FILLREGION = 0x0228
187 META_FRAMEREGION = 0x0429
188 META_INVERTREGION = 0x012A
189 META_PAINTREGION = 0x012B
190 META_SELECTCLIPREGION = 0x012C
191 META_SELECTOBJECT = 0x012D
192 META_SETTEXTALIGN = 0x012E
193 META_CHORD = 0x0830
194 META_SETMAPPERFLAGS = 0x0231
195 META_EXTTEXTOUT = 0x0a32
196 META_SETDIBTODEV = 0x0d33
197 META_SELECTPALETTE = 0x0234
198 META_REALIZEPALETTE = 0x0035
199 META_ANIMATEPALETTE = 0x0436
200 META_SETPALENTRIES = 0x0037
201 META_POLYPOLYGON = 0x0538
202 META_RESIZEPALETTE = 0x0139
203 META_DIBBITBLT = 0x0940
204 META_DIBSTRETCHBLT = 0x0b41
205 META_DIBCREATEPATTERNBRUSH = 0x0142
206 META_STRETCHDIB = 0x0f43
207 META_EXTFLOODFILL = 0x0548
208 META_SETLAYOUT = 0x0149
209 META_DELETEOBJECT = 0x01f0
210 META_CREATEPALETTE = 0x00f7
211 META_CREATEPATTERNBRUSH = 0x01F9
212 META_CREATEPENINDIRECT = 0x02FA
213 META_CREATEFONTINDIRECT = 0x02FB
214 META_CREATEBRUSHINDIRECT = 0x02FC
215 META_CREATEREGION = 0x06FF
216
217
218 NEWFRAME = 1
219 ABORTDOC = 2
220 NEXTBAND = 3
221 SETCOLORTABLE = 4
222 GETCOLORTABLE = 5
223 FLUSHOUTPUT = 6
224 DRAFTMODE = 7
225 QUERYESCSUPPORT = 8
226 SETABORTPROC = 9
227 STARTDOC = 10
228 ENDDOC = 11
229 GETPHYSPAGESIZE = 12
230 GETPRINTINGOFFSET = 13
231 GETSCALINGFACTOR = 14
232 MFCOMMENT = 15
233 GETPENWIDTH = 16
234 SETCOPYCOUNT = 17
235 SELECTPAPERSOURCE = 18
236 DEVICEDATA = 19
237 PASSTHROUGH = 19
238 GETTECHNOLGY = 20
239 GETTECHNOLOGY = 20
240 SETLINECAP = 21
241 SETLINEJOIN = 22
242 SETMITERLIMIT = 23
243 BANDINFO = 24
244 DRAWPATTERNRECT = 25
245 GETVECTORPENSIZE = 26
246 GETVECTORBRUSHSIZE = 27
247 ENABLEDUPLEX = 28
248 GETSETPAPERBINS = 29
249 GETSETPRINTORIENT = 30
250 ENUMPAPERBINS = 31
251 SETDIBSCALING = 32
252 EPSPRINTING = 33
253 ENUMPAPERMETRICS = 34
254 GETSETPAPERMETRICS = 35
255 POSTSCRIPT_DATA = 37
256 POSTSCRIPT_IGNORE = 38
257 MOUSETRAILS = 39
258 GETDEVICEUNITS = 42
259 GETEXTENDEDTEXTMETRICS = 256
260 GETEXTENTTABLE = 257
261 GETPAIRKERNTABLE = 258
262 GETTRACKKERNTABLE = 259
263 EXTTEXTOUT = 512
264 GETFACENAME = 513
265 DOWNLOADFACE = 514
266 ENABLERELATIVEWIDTHS = 768
267 ENABLEPAIRKERNING = 769
268 SETKERNTRACK = 770
269 SETALLJUSTVALUES = 771
270 SETCHARSET = 772
271 STRETCHBLT = 2048
272 METAFILE_DRIVER = 2049
273 GETSETSCREENPARAMS = 3072
274 QUERYDIBSUPPORT = 3073
275 BEGIN_PATH = 4096
276 CLIP_TO_PATH = 4097
277 END_PATH = 4098
278 EXT_DEVICE_CAPS = 4099
279 RESTORE_CTM = 4100
280 SAVE_CTM = 4101
281 SET_ARC_DIRECTION = 4102
282 SET_BACKGROUND_COLOR = 4103
283 SET_POLY_MODE = 4104
284 SET_SCREEN_ANGLE = 4105
285 SET_SPREAD = 4106
286 TRANSFORM_CTM = 4107
287 SET_CLIP_BOX = 4108
288 SET_BOUNDS = 4109
289 SET_MIRROR_MODE = 4110
290 OPENCHANNEL = 4110
291 DOWNLOADHEADER = 4111
292 CLOSECHANNEL = 4112
293 POSTSCRIPT_PASSTHROUGH = 4115
294 ENCAPSULATED_POSTSCRIPT = 4116
295 POSTSCRIPT_IDENTIFY = 4117
296 POSTSCRIPT_INJECTION = 4118
297 CHECKJPEGFORMAT = 4119
298 CHECKPNGFORMAT = 4120
299 GET_PS_FEATURESETTING = 4121
300 GDIPLUS_TS_QUERYVER = 4122
301 GDIPLUS_TS_RECORD = 4123
302 SPCLPASSTHROUGH2 = 4568
303
304
305
306
307
308
309
310
311
312 -class RECT(Structure):
313 _fields_ = [
314 ('left', LONG),
315 ('top', LONG),
316 ('right', LONG),
317 ('bottom', LONG),
318 ]
319 PRECT = POINTER(RECT)
320 LPRECT = PRECT
321
322
323
324
325
327 _fields_ = [
328 ('x', LONG),
329 ('y', LONG),
330 ]
331 PPOINT = POINTER(POINT)
332 LPPOINT = PPOINT
333
334
335
336
337
338
339
340
341
342
344 _fields_ = [
345 ("bmType", LONG),
346 ("bmWidth", LONG),
347 ("bmHeight", LONG),
348 ("bmWidthBytes", LONG),
349 ("bmPlanes", WORD),
350 ("bmBitsPixel", WORD),
351 ("bmBits", LPVOID),
352 ]
353 PBITMAP = POINTER(BITMAP)
354 LPBITMAP = PBITMAP
355
356
357
358
359
360
361
362
369
370
371
372
379
380
381
382
383
385 _ReleaseDC = windll.gdi32.ReleaseDC
386 _ReleaseDC.argtypes = [HWND, HDC]
387 _ReleaseDC.restype = ctypes.c_int
388 _ReleaseDC.errcheck = RaiseIfZero
389 _ReleaseDC(hWnd, hDC)
390
391
392
393
394
396 _SelectObject = windll.gdi32.SelectObject
397 _SelectObject.argtypes = [HDC, HGDIOBJ]
398 _SelectObject.restype = HGDIOBJ
399 _SelectObject.errcheck = RaiseIfZero
400 return _SelectObject(hdc, hgdiobj)
401
402
403
404
406 _GetStockObject = windll.gdi32.GetStockObject
407 _GetStockObject.argtypes = [ctypes.c_int]
408 _GetStockObject.restype = HGDIOBJ
409 _GetStockObject.errcheck = RaiseIfZero
410 return _GetStockObject(fnObject)
411
412
413
414
416 _GetObjectType = windll.gdi32.GetObjectType
417 _GetObjectType.argtypes = [HGDIOBJ]
418 _GetObjectType.restype = DWORD
419 _GetObjectType.errcheck = RaiseIfZero
420 return _GetObjectType(h)
421
422
423
424
425
426
427 -def GetObject(hgdiobj, cbBuffer = None, lpvObject = None):
428 _GetObject = windll.gdi32.GetObject
429 _GetObject.argtypes = [HGDIOBJ, ctypes.c_int, LPVOID]
430 _GetObject.restype = ctypes.c_int
431 _GetObject.errcheck = RaiseIfZero
432
433
434
435
436
437
438 if cbBuffer is not None:
439 if lpvObject is None:
440 lpvObject = ctypes.create_string_buffer("", cbBuffer)
441 elif lpvObject is not None:
442 cbBuffer = sizeof(lpvObject)
443 else:
444 t = GetObjectType(hgdiobj)
445 if t == OBJ_PEN:
446 cbBuffer = sizeof(LOGPEN)
447 lpvObject = LOGPEN()
448 elif t == OBJ_BRUSH:
449 cbBuffer = sizeof(LOGBRUSH)
450 lpvObject = LOGBRUSH()
451 elif t == OBJ_PAL:
452 cbBuffer = _GetObject(hgdiobj, 0, None)
453 lpvObject = (WORD * (cbBuffer // sizeof(WORD)))()
454 elif t == OBJ_FONT:
455 cbBuffer = sizeof(LOGFONT)
456 lpvObject = LOGFONT()
457 elif t == OBJ_BITMAP:
458 cbBuffer = sizeof(DIBSECTION)
459 lpvObject = DIBSECTION()
460 try:
461 _GetObject(hgdiobj, cbBuffer, byref(lpvObject))
462 return lpvObject
463 except WindowsError:
464 cbBuffer = sizeof(BITMAP)
465 lpvObject = BITMAP()
466 elif t == OBJ_EXTPEN:
467 cbBuffer = sizeof(LOGEXTPEN)
468 lpvObject = LOGEXTPEN()
469 else:
470 cbBuffer = _GetObject(hgdiobj, 0, None)
471 lpvObject = ctypes.create_string_buffer("", cbBuffer)
472 _GetObject(hgdiobj, cbBuffer, byref(lpvObject))
473 return lpvObject
474
475
476
477
478
479
481 _GetBitmapBits = windll.gdi32.GetBitmapBits
482 _GetBitmapBits.argtypes = [HBITMAP, LONG, LPVOID]
483 _GetBitmapBits.restype = LONG
484 _GetBitmapBits.errcheck = RaiseIfZero
485
486 bitmap = GetObject(hbmp, lpvObject = BITMAP())
487 cbBuffer = bitmap.bmWidthBytes * bitmap.bmHeight
488 lpvBits = ctypes.create_string_buffer("", cbBuffer)
489 _GetBitmapBits(hbmp, cbBuffer, byref(lpvBits))
490 return lpvBits.raw
491
492
493
494
501
502
503
504 _all = set(vars().keys()).difference(_all)
505 __all__ = [_x for _x in _all if not _x.startswith('_')]
506 __all__.sort()
507
508