github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/windows/winc/w32/gdi32.go (about) 1 //go:build windows 2 3 /* 4 * Copyright (C) 2019 The Winc Authors. All Rights Reserved. 5 * Copyright (C) 2010-2012 The W32 Authors. All Rights Reserved. 6 */ 7 package w32 8 9 import ( 10 "syscall" 11 "unsafe" 12 ) 13 14 var ( 15 modgdi32 = syscall.NewLazyDLL("gdi32.dll") 16 17 procGetDeviceCaps = modgdi32.NewProc("GetDeviceCaps") 18 procDeleteObject = modgdi32.NewProc("DeleteObject") 19 procCreateFontIndirect = modgdi32.NewProc("CreateFontIndirectW") 20 procAbortDoc = modgdi32.NewProc("AbortDoc") 21 procBitBlt = modgdi32.NewProc("BitBlt") 22 procPatBlt = modgdi32.NewProc("PatBlt") 23 procCloseEnhMetaFile = modgdi32.NewProc("CloseEnhMetaFile") 24 procCopyEnhMetaFile = modgdi32.NewProc("CopyEnhMetaFileW") 25 procCreateBrushIndirect = modgdi32.NewProc("CreateBrushIndirect") 26 procCreateCompatibleDC = modgdi32.NewProc("CreateCompatibleDC") 27 procCreateDC = modgdi32.NewProc("CreateDCW") 28 procCreateDIBSection = modgdi32.NewProc("CreateDIBSection") 29 procCreateEnhMetaFile = modgdi32.NewProc("CreateEnhMetaFileW") 30 procCreateIC = modgdi32.NewProc("CreateICW") 31 procDeleteDC = modgdi32.NewProc("DeleteDC") 32 procDeleteEnhMetaFile = modgdi32.NewProc("DeleteEnhMetaFile") 33 procEllipse = modgdi32.NewProc("Ellipse") 34 procEndDoc = modgdi32.NewProc("EndDoc") 35 procEndPage = modgdi32.NewProc("EndPage") 36 procExtCreatePen = modgdi32.NewProc("ExtCreatePen") 37 procGetEnhMetaFile = modgdi32.NewProc("GetEnhMetaFileW") 38 procGetEnhMetaFileHeader = modgdi32.NewProc("GetEnhMetaFileHeader") 39 procGetObject = modgdi32.NewProc("GetObjectW") 40 procGetStockObject = modgdi32.NewProc("GetStockObject") 41 procGetTextExtentExPoint = modgdi32.NewProc("GetTextExtentExPointW") 42 procGetTextExtentPoint32 = modgdi32.NewProc("GetTextExtentPoint32W") 43 procGetTextMetrics = modgdi32.NewProc("GetTextMetricsW") 44 procLineTo = modgdi32.NewProc("LineTo") 45 procMoveToEx = modgdi32.NewProc("MoveToEx") 46 procPlayEnhMetaFile = modgdi32.NewProc("PlayEnhMetaFile") 47 procRectangle = modgdi32.NewProc("Rectangle") 48 procResetDC = modgdi32.NewProc("ResetDCW") 49 procSelectObject = modgdi32.NewProc("SelectObject") 50 procSetBkMode = modgdi32.NewProc("SetBkMode") 51 procSetBrushOrgEx = modgdi32.NewProc("SetBrushOrgEx") 52 procSetStretchBltMode = modgdi32.NewProc("SetStretchBltMode") 53 procSetTextColor = modgdi32.NewProc("SetTextColor") 54 procSetBkColor = modgdi32.NewProc("SetBkColor") 55 procStartDoc = modgdi32.NewProc("StartDocW") 56 procStartPage = modgdi32.NewProc("StartPage") 57 procStretchBlt = modgdi32.NewProc("StretchBlt") 58 procSetDIBitsToDevice = modgdi32.NewProc("SetDIBitsToDevice") 59 procChoosePixelFormat = modgdi32.NewProc("ChoosePixelFormat") 60 procDescribePixelFormat = modgdi32.NewProc("DescribePixelFormat") 61 procGetEnhMetaFilePixelFormat = modgdi32.NewProc("GetEnhMetaFilePixelFormat") 62 procGetPixelFormat = modgdi32.NewProc("GetPixelFormat") 63 procSetPixelFormat = modgdi32.NewProc("SetPixelFormat") 64 procSwapBuffers = modgdi32.NewProc("SwapBuffers") 65 ) 66 67 func GetDeviceCaps(hdc HDC, index int) int { 68 ret, _, _ := procGetDeviceCaps.Call( 69 uintptr(hdc), 70 uintptr(index)) 71 72 return int(ret) 73 } 74 75 func DeleteObject(hObject HGDIOBJ) bool { 76 ret, _, _ := procDeleteObject.Call( 77 uintptr(hObject)) 78 79 return ret != 0 80 } 81 82 func CreateFontIndirect(logFont *LOGFONT) HFONT { 83 ret, _, _ := procCreateFontIndirect.Call( 84 uintptr(unsafe.Pointer(logFont))) 85 86 return HFONT(ret) 87 } 88 89 func AbortDoc(hdc HDC) int { 90 ret, _, _ := procAbortDoc.Call( 91 uintptr(hdc)) 92 93 return int(ret) 94 } 95 96 func BitBlt(hdcDest HDC, nXDest, nYDest, nWidth, nHeight int, hdcSrc HDC, nXSrc, nYSrc int, dwRop uint) { 97 ret, _, _ := procBitBlt.Call( 98 uintptr(hdcDest), 99 uintptr(nXDest), 100 uintptr(nYDest), 101 uintptr(nWidth), 102 uintptr(nHeight), 103 uintptr(hdcSrc), 104 uintptr(nXSrc), 105 uintptr(nYSrc), 106 uintptr(dwRop)) 107 108 if ret == 0 { 109 panic("BitBlt failed") 110 } 111 } 112 113 func PatBlt(hdc HDC, nXLeft, nYLeft, nWidth, nHeight int, dwRop uint) { 114 ret, _, _ := procPatBlt.Call( 115 uintptr(hdc), 116 uintptr(nXLeft), 117 uintptr(nYLeft), 118 uintptr(nWidth), 119 uintptr(nHeight), 120 uintptr(dwRop)) 121 122 if ret == 0 { 123 panic("PatBlt failed") 124 } 125 } 126 127 func CloseEnhMetaFile(hdc HDC) HENHMETAFILE { 128 ret, _, _ := procCloseEnhMetaFile.Call( 129 uintptr(hdc)) 130 131 return HENHMETAFILE(ret) 132 } 133 134 func CopyEnhMetaFile(hemfSrc HENHMETAFILE, lpszFile *uint16) HENHMETAFILE { 135 ret, _, _ := procCopyEnhMetaFile.Call( 136 uintptr(hemfSrc), 137 uintptr(unsafe.Pointer(lpszFile))) 138 139 return HENHMETAFILE(ret) 140 } 141 142 func CreateBrushIndirect(lplb *LOGBRUSH) HBRUSH { 143 ret, _, _ := procCreateBrushIndirect.Call( 144 uintptr(unsafe.Pointer(lplb))) 145 146 return HBRUSH(ret) 147 } 148 149 func CreateCompatibleDC(hdc HDC) HDC { 150 ret, _, _ := procCreateCompatibleDC.Call( 151 uintptr(hdc)) 152 153 if ret == 0 { 154 panic("Create compatible DC failed") 155 } 156 157 return HDC(ret) 158 } 159 160 func CreateDC(lpszDriver, lpszDevice, lpszOutput *uint16, lpInitData *DEVMODE) HDC { 161 ret, _, _ := procCreateDC.Call( 162 uintptr(unsafe.Pointer(lpszDriver)), 163 uintptr(unsafe.Pointer(lpszDevice)), 164 uintptr(unsafe.Pointer(lpszOutput)), 165 uintptr(unsafe.Pointer(lpInitData))) 166 167 return HDC(ret) 168 } 169 170 func CreateDIBSection(hdc HDC, pbmi *BITMAPINFO, iUsage uint, ppvBits *unsafe.Pointer, hSection HANDLE, dwOffset uint) HBITMAP { 171 ret, _, _ := procCreateDIBSection.Call( 172 uintptr(hdc), 173 uintptr(unsafe.Pointer(pbmi)), 174 uintptr(iUsage), 175 uintptr(unsafe.Pointer(ppvBits)), 176 uintptr(hSection), 177 uintptr(dwOffset)) 178 179 return HBITMAP(ret) 180 } 181 182 func CreateEnhMetaFile(hdcRef HDC, lpFilename *uint16, lpRect *RECT, lpDescription *uint16) HDC { 183 ret, _, _ := procCreateEnhMetaFile.Call( 184 uintptr(hdcRef), 185 uintptr(unsafe.Pointer(lpFilename)), 186 uintptr(unsafe.Pointer(lpRect)), 187 uintptr(unsafe.Pointer(lpDescription))) 188 189 return HDC(ret) 190 } 191 192 func CreateIC(lpszDriver, lpszDevice, lpszOutput *uint16, lpdvmInit *DEVMODE) HDC { 193 ret, _, _ := procCreateIC.Call( 194 uintptr(unsafe.Pointer(lpszDriver)), 195 uintptr(unsafe.Pointer(lpszDevice)), 196 uintptr(unsafe.Pointer(lpszOutput)), 197 uintptr(unsafe.Pointer(lpdvmInit))) 198 199 return HDC(ret) 200 } 201 202 func DeleteDC(hdc HDC) bool { 203 ret, _, _ := procDeleteDC.Call( 204 uintptr(hdc)) 205 206 return ret != 0 207 } 208 209 func DeleteEnhMetaFile(hemf HENHMETAFILE) bool { 210 ret, _, _ := procDeleteEnhMetaFile.Call( 211 uintptr(hemf)) 212 213 return ret != 0 214 } 215 216 func Ellipse(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) bool { 217 ret, _, _ := procEllipse.Call( 218 uintptr(hdc), 219 uintptr(nLeftRect), 220 uintptr(nTopRect), 221 uintptr(nRightRect), 222 uintptr(nBottomRect)) 223 224 return ret != 0 225 } 226 227 func EndDoc(hdc HDC) int { 228 ret, _, _ := procEndDoc.Call( 229 uintptr(hdc)) 230 231 return int(ret) 232 } 233 234 func EndPage(hdc HDC) int { 235 ret, _, _ := procEndPage.Call( 236 uintptr(hdc)) 237 238 return int(ret) 239 } 240 241 func ExtCreatePen(dwPenStyle, dwWidth uint, lplb *LOGBRUSH, dwStyleCount uint, lpStyle *uint) HPEN { 242 ret, _, _ := procExtCreatePen.Call( 243 uintptr(dwPenStyle), 244 uintptr(dwWidth), 245 uintptr(unsafe.Pointer(lplb)), 246 uintptr(dwStyleCount), 247 uintptr(unsafe.Pointer(lpStyle))) 248 249 return HPEN(ret) 250 } 251 252 func GetEnhMetaFile(lpszMetaFile *uint16) HENHMETAFILE { 253 ret, _, _ := procGetEnhMetaFile.Call( 254 uintptr(unsafe.Pointer(lpszMetaFile))) 255 256 return HENHMETAFILE(ret) 257 } 258 259 func GetEnhMetaFileHeader(hemf HENHMETAFILE, cbBuffer uint, lpemh *ENHMETAHEADER) uint { 260 ret, _, _ := procGetEnhMetaFileHeader.Call( 261 uintptr(hemf), 262 uintptr(cbBuffer), 263 uintptr(unsafe.Pointer(lpemh))) 264 265 return uint(ret) 266 } 267 268 func GetObject(hgdiobj HGDIOBJ, cbBuffer uintptr, lpvObject unsafe.Pointer) int { 269 ret, _, _ := procGetObject.Call( 270 uintptr(hgdiobj), 271 uintptr(cbBuffer), 272 uintptr(lpvObject)) 273 274 return int(ret) 275 } 276 277 func GetStockObject(fnObject int) HGDIOBJ { 278 ret, _, _ := procGetDeviceCaps.Call( 279 uintptr(fnObject)) 280 281 return HGDIOBJ(ret) 282 } 283 284 func GetTextExtentExPoint(hdc HDC, lpszStr *uint16, cchString, nMaxExtent int, lpnFit, alpDx *int, lpSize *SIZE) bool { 285 ret, _, _ := procGetTextExtentExPoint.Call( 286 uintptr(hdc), 287 uintptr(unsafe.Pointer(lpszStr)), 288 uintptr(cchString), 289 uintptr(nMaxExtent), 290 uintptr(unsafe.Pointer(lpnFit)), 291 uintptr(unsafe.Pointer(alpDx)), 292 uintptr(unsafe.Pointer(lpSize))) 293 294 return ret != 0 295 } 296 297 func GetTextExtentPoint32(hdc HDC, lpString *uint16, c int, lpSize *SIZE) bool { 298 ret, _, _ := procGetTextExtentPoint32.Call( 299 uintptr(hdc), 300 uintptr(unsafe.Pointer(lpString)), 301 uintptr(c), 302 uintptr(unsafe.Pointer(lpSize))) 303 304 return ret != 0 305 } 306 307 func GetTextMetrics(hdc HDC, lptm *TEXTMETRIC) bool { 308 ret, _, _ := procGetTextMetrics.Call( 309 uintptr(hdc), 310 uintptr(unsafe.Pointer(lptm))) 311 312 return ret != 0 313 } 314 315 func LineTo(hdc HDC, nXEnd, nYEnd int32) bool { 316 ret, _, _ := procLineTo.Call( 317 uintptr(hdc), 318 uintptr(nXEnd), 319 uintptr(nYEnd)) 320 321 return ret != 0 322 } 323 324 func MoveToEx(hdc HDC, x, y int, lpPoint *POINT) bool { 325 ret, _, _ := procMoveToEx.Call( 326 uintptr(hdc), 327 uintptr(x), 328 uintptr(y), 329 uintptr(unsafe.Pointer(lpPoint))) 330 331 return ret != 0 332 } 333 334 func PlayEnhMetaFile(hdc HDC, hemf HENHMETAFILE, lpRect *RECT) bool { 335 ret, _, _ := procPlayEnhMetaFile.Call( 336 uintptr(hdc), 337 uintptr(hemf), 338 uintptr(unsafe.Pointer(lpRect))) 339 340 return ret != 0 341 } 342 343 func Rectangle(hdc HDC, nLeftRect, nTopRect, nRightRect, nBottomRect int32) bool { 344 ret, _, _ := procRectangle.Call( 345 uintptr(hdc), 346 uintptr(nLeftRect), 347 uintptr(nTopRect), 348 uintptr(nRightRect), 349 uintptr(nBottomRect)) 350 351 return ret != 0 352 } 353 354 func ResetDC(hdc HDC, lpInitData *DEVMODE) HDC { 355 ret, _, _ := procResetDC.Call( 356 uintptr(hdc), 357 uintptr(unsafe.Pointer(lpInitData))) 358 359 return HDC(ret) 360 } 361 362 func SelectObject(hdc HDC, hgdiobj HGDIOBJ) HGDIOBJ { 363 ret, _, _ := procSelectObject.Call( 364 uintptr(hdc), 365 uintptr(hgdiobj)) 366 367 if ret == 0 { 368 panic("SelectObject failed") 369 } 370 371 return HGDIOBJ(ret) 372 } 373 374 func SetBkMode(hdc HDC, iBkMode int) int { 375 ret, _, _ := procSetBkMode.Call( 376 uintptr(hdc), 377 uintptr(iBkMode)) 378 379 if ret == 0 { 380 panic("SetBkMode failed") 381 } 382 383 return int(ret) 384 } 385 386 func SetBrushOrgEx(hdc HDC, nXOrg, nYOrg int, lppt *POINT) bool { 387 ret, _, _ := procSetBrushOrgEx.Call( 388 uintptr(hdc), 389 uintptr(nXOrg), 390 uintptr(nYOrg), 391 uintptr(unsafe.Pointer(lppt))) 392 393 return ret != 0 394 } 395 396 func SetStretchBltMode(hdc HDC, iStretchMode int) int { 397 ret, _, _ := procSetStretchBltMode.Call( 398 uintptr(hdc), 399 uintptr(iStretchMode)) 400 401 return int(ret) 402 } 403 404 func SetTextColor(hdc HDC, crColor COLORREF) COLORREF { 405 ret, _, _ := procSetTextColor.Call( 406 uintptr(hdc), 407 uintptr(crColor)) 408 409 if ret == CLR_INVALID { 410 panic("SetTextColor failed") 411 } 412 413 return COLORREF(ret) 414 } 415 416 func SetBkColor(hdc HDC, crColor COLORREF) COLORREF { 417 ret, _, _ := procSetBkColor.Call( 418 uintptr(hdc), 419 uintptr(crColor)) 420 421 if ret == CLR_INVALID { 422 panic("SetBkColor failed") 423 } 424 425 return COLORREF(ret) 426 } 427 428 func StartDoc(hdc HDC, lpdi *DOCINFO) int { 429 ret, _, _ := procStartDoc.Call( 430 uintptr(hdc), 431 uintptr(unsafe.Pointer(lpdi))) 432 433 return int(ret) 434 } 435 436 func StartPage(hdc HDC) int { 437 ret, _, _ := procStartPage.Call( 438 uintptr(hdc)) 439 440 return int(ret) 441 } 442 443 func StretchBlt(hdcDest HDC, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest int, hdcSrc HDC, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc int, dwRop uint) { 444 ret, _, _ := procStretchBlt.Call( 445 uintptr(hdcDest), 446 uintptr(nXOriginDest), 447 uintptr(nYOriginDest), 448 uintptr(nWidthDest), 449 uintptr(nHeightDest), 450 uintptr(hdcSrc), 451 uintptr(nXOriginSrc), 452 uintptr(nYOriginSrc), 453 uintptr(nWidthSrc), 454 uintptr(nHeightSrc), 455 uintptr(dwRop)) 456 457 if ret == 0 { 458 panic("StretchBlt failed") 459 } 460 } 461 462 func SetDIBitsToDevice(hdc HDC, xDest, yDest, dwWidth, dwHeight, xSrc, ySrc int, uStartScan, cScanLines uint, lpvBits []byte, lpbmi *BITMAPINFO, fuColorUse uint) int { 463 ret, _, _ := procSetDIBitsToDevice.Call( 464 uintptr(hdc), 465 uintptr(xDest), 466 uintptr(yDest), 467 uintptr(dwWidth), 468 uintptr(dwHeight), 469 uintptr(xSrc), 470 uintptr(ySrc), 471 uintptr(uStartScan), 472 uintptr(cScanLines), 473 uintptr(unsafe.Pointer(&lpvBits[0])), 474 uintptr(unsafe.Pointer(lpbmi)), 475 uintptr(fuColorUse)) 476 477 return int(ret) 478 } 479 480 func ChoosePixelFormat(hdc HDC, pfd *PIXELFORMATDESCRIPTOR) int { 481 ret, _, _ := procChoosePixelFormat.Call( 482 uintptr(hdc), 483 uintptr(unsafe.Pointer(pfd)), 484 ) 485 return int(ret) 486 } 487 488 func DescribePixelFormat(hdc HDC, iPixelFormat int, nBytes uint, pfd *PIXELFORMATDESCRIPTOR) int { 489 ret, _, _ := procDescribePixelFormat.Call( 490 uintptr(hdc), 491 uintptr(iPixelFormat), 492 uintptr(nBytes), 493 uintptr(unsafe.Pointer(pfd)), 494 ) 495 return int(ret) 496 } 497 498 func GetEnhMetaFilePixelFormat(hemf HENHMETAFILE, cbBuffer uint32, pfd *PIXELFORMATDESCRIPTOR) uint { 499 ret, _, _ := procGetEnhMetaFilePixelFormat.Call( 500 uintptr(hemf), 501 uintptr(cbBuffer), 502 uintptr(unsafe.Pointer(pfd)), 503 ) 504 return uint(ret) 505 } 506 507 func GetPixelFormat(hdc HDC) int { 508 ret, _, _ := procGetPixelFormat.Call( 509 uintptr(hdc), 510 ) 511 return int(ret) 512 } 513 514 func SetPixelFormat(hdc HDC, iPixelFormat int, pfd *PIXELFORMATDESCRIPTOR) bool { 515 ret, _, _ := procSetPixelFormat.Call( 516 uintptr(hdc), 517 uintptr(iPixelFormat), 518 uintptr(unsafe.Pointer(pfd)), 519 ) 520 return ret == TRUE 521 } 522 523 func SwapBuffers(hdc HDC) bool { 524 ret, _, _ := procSwapBuffers.Call(uintptr(hdc)) 525 return ret == TRUE 526 }