Skip to content

Commit ea789f6

Browse files
committed
Add transparency for containers lacking windowless controls support
1 parent 8d49985 commit ea789f6

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/AlphaBlendImage.ctl

+12-17
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVa
104104
Private Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal hdcDest As Long, ptDst As Any, pSize As Any, ByVal hdcSrc As Long, ptSrc As Any, ByVal crKey As Long, pBlend As Any, ByVal dwFlags As Long) As Long
105105
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
106106
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hDC As Long) As Long
107-
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As Any) As Long
107+
Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As Any) As Long
108+
Private Declare Function MapWindowPoints Lib "user32" (ByVal hWndFrom As Long, ByVal hWndTo As Long, lppt As Any, ByVal cPoints As Long) As Long
109+
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
108110
'--- clipboard support
109111
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
110112
Private Declare Function CloseClipboard Lib "user32" () As Long
@@ -245,13 +247,6 @@ Private Type BITMAPV5HEADER
245247
bV5Reserved As Long
246248
End Type
247249

248-
Private Type BLENDFUNCTION
249-
BlendOp As Byte
250-
BlendFlags As Byte
251-
SourceConstantAlpha As Byte
252-
AlphaFormat As Byte
253-
End Type
254-
255250
Private Type POINTAPI
256251
X As Long
257252
Y As Long
@@ -675,7 +670,6 @@ Public Function GdipUpdateLayeredWindow(ByVal hWnd As Long) As Boolean
675670
Dim hMemDC As Long
676671
Dim hBmp As Long
677672
Dim hPrevBmp As Long
678-
Dim uBlend As BLENDFUNCTION
679673
Dim uRect(0 To 1) As POINTAPI
680674
Dim ptSrc As POINTAPI
681675

@@ -699,18 +693,14 @@ Public Function GdipUpdateLayeredWindow(ByVal hWnd As Long) As Boolean
699693
If hPrevBmp = 0 Then
700694
GoTo QH
701695
End If
702-
Call GetWindowRect(hWnd, uRect(0))
696+
Call GetClientRect(hWnd, uRect(0))
697+
Call MapWindowPoints(hWnd, GetParent(hWnd), uRect(0), 2)
703698
With uRect(1)
704699
.X = .X - uRect(0).X
705700
.Y = .Y - uRect(0).Y
706701
End With
707-
With uBlend
708-
.BlendOp = AC_SRC_OVER
709-
.BlendFlags = 0
710-
.SourceConstantAlpha = 255 * m_sngOpacity
711-
.AlphaFormat = AC_SRC_ALPHA
712-
End With
713-
Call UpdateLayeredWindow(hWnd, hScreenDC, uRect(0), uRect(1), hMemDC, ptSrc, 0, uBlend, ULW_ALPHA)
702+
Call UpdateLayeredWindow(hWnd, hScreenDC, uRect(0), uRect(1), hMemDC, ptSrc, 0, _
703+
AC_SRC_ALPHA * &H1000000 + CByte(255 * m_sngOpacity) * &H10000 + AC_SRC_OVER, ULW_ALPHA)
714704
'--- success
715705
GdipUpdateLayeredWindow = True
716706
QH:
@@ -1493,6 +1483,9 @@ DefPaint:
14931483
End If
14941484
Line (0, 0)-(ScaleWidth - 1, ScaleHeight - 1), vbBlack, B
14951485
End If
1486+
If hWnd <> 0 Then
1487+
GdipUpdateLayeredWindow hWnd
1488+
End If
14961489
If (GetWindowLong(ContainerHwnd, GWL_EXSTYLE) And WS_EX_LAYERED) <> 0 Then
14971490
GdipUpdateLayeredWindow ContainerHwnd
14981491
End If
@@ -1514,6 +1507,7 @@ Private Sub UserControl_InitProperties()
15141507

15151508
On Error GoTo EH
15161509
m_eContainerScaleMode = ToScaleMode(Ambient.ScaleUnits)
1510+
BackStyle = IIf(hWnd = 0, vbTransparent, 1)
15171511
AutoRedraw = DEF_AUTOREDRAW
15181512
Opacity = DEF_OPACITY
15191513
Rotation = DEF_ROTATION
@@ -1530,6 +1524,7 @@ Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
15301524

15311525
On Error GoTo EH
15321526
m_eContainerScaleMode = ToScaleMode(Ambient.ScaleUnits)
1527+
BackStyle = IIf(hWnd = 0, vbTransparent, 1)
15331528
With PropBag
15341529
m_bAutoRedraw = .ReadProperty("AutoRedraw", DEF_AUTOREDRAW)
15351530
m_sngOpacity = .ReadProperty("Opacity", DEF_OPACITY)

0 commit comments

Comments
 (0)