Skip to content

Commit cd28d43

Browse files
committed
Add some region functions + TransparentBlt
1 parent 248bf3f commit cd28d43

File tree

1 file changed

+88
-1
lines changed

1 file changed

+88
-1
lines changed

gdi32.go

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,23 @@ const (
731731
GRADIENT_FILL_TRIANGLE = 0x02
732732
)
733733

734+
// Region Combine Modes
735+
const (
736+
RGN_AND = 1
737+
RGN_OR = 2
738+
RGN_XOR = 3
739+
RGN_DIFF = 4
740+
RGN_COPY = 5
741+
)
742+
743+
// Region Types
744+
const (
745+
REGIONERROR = 0
746+
NULLREGION = 1
747+
SIMPLEREGION = 2
748+
COMPLEXREGION = 3
749+
)
750+
734751
type (
735752
COLORREF uint32
736753
HBITMAP HGDIOBJ
@@ -741,7 +758,7 @@ type (
741758
HENHMETAFILE HANDLE
742759
HPALETTE HGDIOBJ
743760
HPEN HGDIOBJ
744-
HREGION HGDIOBJ
761+
HRGN HGDIOBJ
745762
)
746763

747764
type PIXELFORMATDESCRIPTOR struct {
@@ -1001,6 +1018,7 @@ var (
10011018
bitBlt uintptr
10021019
choosePixelFormat uintptr
10031020
closeEnhMetaFile uintptr
1021+
combineRgn uintptr
10041022
copyEnhMetaFile uintptr
10051023
createBitmap uintptr
10061024
createCompatibleBitmap uintptr
@@ -1012,6 +1030,7 @@ var (
10121030
createEnhMetaFile uintptr
10131031
createIC uintptr
10141032
createPatternBrush uintptr
1033+
createRectRgn uintptr
10151034
deleteDC uintptr
10161035
deleteEnhMetaFile uintptr
10171036
deleteObject uintptr
@@ -1020,12 +1039,14 @@ var (
10201039
endPage uintptr
10211040
excludeClipRect uintptr
10221041
extCreatePen uintptr
1042+
fillRgn uintptr
10231043
getDeviceCaps uintptr
10241044
getDIBits uintptr
10251045
getEnhMetaFile uintptr
10261046
getEnhMetaFileHeader uintptr
10271047
getObject uintptr
10281048
getPixel uintptr
1049+
getRgnBox uintptr
10291050
getStockObject uintptr
10301051
getTextExtentExPoint uintptr
10311052
getTextExtentPoint32 uintptr
@@ -1055,6 +1076,7 @@ var (
10551076
stretchBlt uintptr
10561077
swapBuffers uintptr
10571078
textOut uintptr
1079+
transparentBlt uintptr
10581080
)
10591081

10601082
func init() {
@@ -1067,6 +1089,7 @@ func init() {
10671089
bitBlt = MustGetProcAddress(libgdi32, "BitBlt")
10681090
choosePixelFormat = MustGetProcAddress(libgdi32, "ChoosePixelFormat")
10691091
closeEnhMetaFile = MustGetProcAddress(libgdi32, "CloseEnhMetaFile")
1092+
combineRgn = MustGetProcAddress(libgdi32, "CombineRgn")
10701093
copyEnhMetaFile = MustGetProcAddress(libgdi32, "CopyEnhMetaFileW")
10711094
createBitmap = MustGetProcAddress(libgdi32, "CreateBitmap")
10721095
createCompatibleBitmap = MustGetProcAddress(libgdi32, "CreateCompatibleBitmap")
@@ -1078,6 +1101,7 @@ func init() {
10781101
createFontIndirect = MustGetProcAddress(libgdi32, "CreateFontIndirectW")
10791102
createIC = MustGetProcAddress(libgdi32, "CreateICW")
10801103
createPatternBrush = MustGetProcAddress(libgdi32, "CreatePatternBrush")
1104+
createRectRgn = MustGetProcAddress(libgdi32, "CreateRectRgn")
10811105
deleteDC = MustGetProcAddress(libgdi32, "DeleteDC")
10821106
deleteEnhMetaFile = MustGetProcAddress(libgdi32, "DeleteEnhMetaFile")
10831107
deleteObject = MustGetProcAddress(libgdi32, "DeleteObject")
@@ -1086,12 +1110,14 @@ func init() {
10861110
endPage = MustGetProcAddress(libgdi32, "EndPage")
10871111
excludeClipRect = MustGetProcAddress(libgdi32, "ExcludeClipRect")
10881112
extCreatePen = MustGetProcAddress(libgdi32, "ExtCreatePen")
1113+
fillRgn = MustGetProcAddress(libgdi32, "FillRgn")
10891114
getDeviceCaps = MustGetProcAddress(libgdi32, "GetDeviceCaps")
10901115
getDIBits = MustGetProcAddress(libgdi32, "GetDIBits")
10911116
getEnhMetaFile = MustGetProcAddress(libgdi32, "GetEnhMetaFileW")
10921117
getEnhMetaFileHeader = MustGetProcAddress(libgdi32, "GetEnhMetaFileHeader")
10931118
getObject = MustGetProcAddress(libgdi32, "GetObjectW")
10941119
getPixel = MustGetProcAddress(libgdi32, "GetPixel")
1120+
getRgnBox = MustGetProcAddress(libgdi32, "GetRgnBox")
10951121
getStockObject = MustGetProcAddress(libgdi32, "GetStockObject")
10961122
getTextExtentExPoint = MustGetProcAddress(libgdi32, "GetTextExtentExPointW")
10971123
getTextExtentPoint32 = MustGetProcAddress(libgdi32, "GetTextExtentPoint32W")
@@ -1122,6 +1148,7 @@ func init() {
11221148
textOut = MustGetProcAddress(libgdi32, "TextOutW")
11231149

11241150
gradientFill = MustGetProcAddress(libmsimg32, "GradientFill")
1151+
transparentBlt = MustGetProcAddress(libmsimg32, "TransparentBlt")
11251152
}
11261153

11271154
func AbortDoc(hdc HDC) int32 {
@@ -1166,6 +1193,18 @@ func CloseEnhMetaFile(hdc HDC) HENHMETAFILE {
11661193
return HENHMETAFILE(ret)
11671194
}
11681195

1196+
func CombineRgn(hrgnDest, hrgnSrc1, hrgnSrc2 HRGN, fnCombineMode int32) int32 {
1197+
ret, _, _ := syscall.Syscall6(combineRgn, 4,
1198+
uintptr(hrgnDest),
1199+
uintptr(hrgnSrc1),
1200+
uintptr(hrgnSrc2),
1201+
uintptr(fnCombineMode),
1202+
0,
1203+
0)
1204+
1205+
return int32(ret)
1206+
}
1207+
11691208
func CopyEnhMetaFile(hemfSrc HENHMETAFILE, lpszFile *uint16) HENHMETAFILE {
11701209
ret, _, _ := syscall.Syscall(copyEnhMetaFile, 2,
11711210
uintptr(hemfSrc),
@@ -1280,6 +1319,18 @@ func CreatePatternBrush(hbmp HBITMAP) HBRUSH {
12801319
return HBRUSH(ret)
12811320
}
12821321

1322+
func CreateRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect int32) HRGN {
1323+
ret, _, _ := syscall.Syscall6(createRectRgn, 4,
1324+
uintptr(nLeftRect),
1325+
uintptr(nTopRect),
1326+
uintptr(nRightRect),
1327+
uintptr(nBottomRect),
1328+
0,
1329+
0)
1330+
1331+
return HRGN(ret)
1332+
}
1333+
12831334
func DeleteDC(hdc HDC) bool {
12841335
ret, _, _ := syscall.Syscall(deleteDC, 1,
12851336
uintptr(hdc),
@@ -1361,6 +1412,15 @@ func ExtCreatePen(dwPenStyle, dwWidth uint32, lplb *LOGBRUSH, dwStyleCount uint3
13611412
return HPEN(ret)
13621413
}
13631414

1415+
func FillRgn(hdc HDC, hrgn HRGN, hbr HBRUSH) bool {
1416+
ret, _, _ := syscall.Syscall(fillRgn, 3,
1417+
uintptr(hdc),
1418+
uintptr(hrgn),
1419+
uintptr(hbr))
1420+
1421+
return ret != 0
1422+
}
1423+
13641424
func GetDeviceCaps(hdc HDC, nIndex int32) int32 {
13651425
ret, _, _ := syscall.Syscall(getDeviceCaps, 2,
13661426
uintptr(hdc),
@@ -1420,6 +1480,15 @@ func GetPixel(hdc HDC, nXPos, nYPos int32) COLORREF {
14201480
return COLORREF(ret)
14211481
}
14221482

1483+
func GetRgnBox(hrgn HRGN, lprc *RECT) int32 {
1484+
ret, _, _ := syscall.Syscall(getRgnBox, 2,
1485+
uintptr(hrgn),
1486+
uintptr(unsafe.Pointer(lprc)),
1487+
0)
1488+
1489+
return int32(ret)
1490+
}
1491+
14231492
func GetStockObject(fnObject int32) HGDIOBJ {
14241493
ret, _, _ := syscall.Syscall(getStockObject, 1,
14251494
uintptr(fnObject),
@@ -1719,3 +1788,21 @@ func TextOut(hdc HDC, nXStart, nYStart int32, lpString *uint16, cchString int32)
17191788
0)
17201789
return ret != 0
17211790
}
1791+
1792+
func TransparentBlt(hdcDest HDC, xoriginDest, yoriginDest, wDest, hDest int32, hdcSrc HDC, xoriginSrc, yoriginSrc, wSrc, hSrc int32, crTransparent uint32) bool {
1793+
ret, _, _ := syscall.Syscall12(transparentBlt, 11,
1794+
uintptr(hdcDest),
1795+
uintptr(xoriginDest),
1796+
uintptr(yoriginDest),
1797+
uintptr(wDest),
1798+
uintptr(hDest),
1799+
uintptr(hdcSrc),
1800+
uintptr(xoriginSrc),
1801+
uintptr(yoriginSrc),
1802+
uintptr(wSrc),
1803+
uintptr(hSrc),
1804+
uintptr(crTransparent),
1805+
0)
1806+
1807+
return ret != 0
1808+
}

0 commit comments

Comments
 (0)