VB6之阴影图层
要是能创建半透明的刷子就好了,就不必像这样以图层的方式实现透明阴影效果。
代码:
1 'code by lichmama@cnblogs.com 2 '绘制阴影图层 3 Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, _ 4 ByVal nHeight As Long) As Long 5 Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long 6 Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _ 7 ByVal hObject As Long) As Long 8 Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long 9 Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long 10 Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long 11 Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, _ 12 ByVal X1 As Long, _ 13 ByVal Y1 As Long, _ 14 ByVal X2 As Long, _ 15 ByVal Y2 As Long) As Long 16 Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, _ 17 ByVal nWidth As Long, _ 18 ByVal crColor As Long) As Long 19 Private Declare Function AlphaBlend Lib "msimg32.dll" (ByVal hdc As Long, _ 20 ByVal tx As Long, _ 21 ByVal ty As Long, _ 22 ByVal Tw As Long, _ 23 ByVal Th As Long, _ 24 ByVal hdc As Long, _ 25 ByVal sx As Long, _ 26 ByVal sy As Long, _ 27 ByVal sw As Long, _ 28 ByVal sh As Long, _ 29 ByVal BLENDFUNCT As Long) As Long 30 Private Const PS_SOLID = 0 31 32 Private Sub Command1_Click() 33 Dim hMemdc As Long 34 Dim hBmp As Long 35 Dim hBrush As Long 36 Dim hPen As Long 37 Dim w As Long 38 Dim h As Long 39 40 w = 202& 41 h = 202& 42 43 hMemdc = CreateCompatibleDC(0&) 44 hBmp = CreateCompatibleBitmap(Me.hdc, w, h) 45 Call SelectObject(hMemdc, hBmp) 46 47 hBrush = CreateSolidBrush(RGB(200, 64, 37)) 48 Call SelectObject(hMemdc, hBrush) 49 50 hPen = CreatePen(PS_SOLID, 1&, RGB(200, 64, 37)) 51 Call SelectObject(hMemdc, hPen) 52 53 Call Rectangle(hMemdc, 0&, 0&, w, h) 54 Call AlphaBlend(Picture2.hdc, 0&, 0&, w, h, hMemdc, 0&, 0&, w, h, &H10000 * 100) 55 56 Call DeleteObject(hBrush) 57 Call DeleteObject(hPen) 58 Call DeleteObject(hBmp) 59 Call DeleteObject(hMemdc) 60 End Sub
贴张图: