透過転送テスト(GdiTransparentBlt)          <TOP>


TransParentBltによる透過転送と同じです。Windows2000以降(Windows98/Meはサポート外)

GdiTransparentBlt 透明色を指定してビットマップをコピー

 

参照

TransparentBltによる透過転送

 

'================================================================
'= 透過転送テスト(GdiTransparentBlt)
'=    (GdiTransparentBlt.bas)
'================================================================
#include "Windows.bi"

' 透明色を指定してビットマップをコピー
Declare Function Api_GdiTransparentBlt& Lib "gdi32" Alias "GdiTransparentBlt" (ByVal hDC&, ByVal x&, ByVal y&, ByVal nWidth&, ByVal nHeight&, ByVal hSrcDC&, ByVal xSrc&, ByVal ySrc&, ByVal nSrcWidth&, ByVal nSrcHeight&, ByVal crTransparent&)

' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)

Var Shared Bitmap As Object
Var Shared Mainform As Object
Var Shared Picture1 As Object
Var Shared Picture2 As Object
Var Shared Picture3 As Object

Mainform.Attach GethWnd
Picture1.Attach GetDlgItem("Picture1")
Picture2.Attach GetDlgItem("Picture2")
Picture3.Attach GetDlgItem("Picture3")
BitmapObject Bitmap

Var Shared RGBColor As Long '透明色
Var Shared hDC0 As Long
Var Shared hDC1 As Long
Var Shared hDC2 As Long
Var Shared hDC3 As Long
Var Shared xPos As Integer

'================================================================
'=
'================================================================
Declare Sub Mainform_Start edecl ()
Sub Mainform_Start()

    Bitmap.LoadFile "BackColor2.bmp"
    Picture1.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject

    Bitmap.LoadFile "bike1.bmp"
    Picture2.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject

    Bitmap.LoadFile "bike5.bmp"
    Picture3.DrawBitmap Bitmap, 0, 0
    Bitmap.DeleteObject

    hDC1 = Api_GetDC(Picture1.GethWnd)
End Sub

'================================================================
'=
'================================================================
Declare Sub Tensou_dsp edecl ()
Sub Tensou_dsp()
    Var Ret As Long

    Ret = Api_GdiTransparentBlt(hDC1, xPos, 10, 56, 52, hDC0, 0, 0, 56, 52, RGBColor)
End Sub

'================================================================
'= 透明色を白
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    RGBColor = RGB(255, 255, 255)
    hDC2 = Api_GetDC(Picture2.GethWnd)
    hDC0 = hDC2
    xPos = 150
    Tensou_dsp
End Sub

'================================================================
'= 透明色を黒
'================================================================
Declare Sub Button2_on edecl ()
Sub Button2_on()
    RGBColor = RGB(0, 0, 0)
    hDC3 = Api_GetDC(Picture3.GethWnd)
    hDC0 = hDC3
    xPos = 250
    Tensou_dsp
End Sub

'================================================================
'= 
'================================================================
Declare Sub Mainform_QueryClose edecl (Cancel%, ByVal Mode%)
Sub Mainform_QueryClose(Cancel%, ByVal Mode%)
    Var Ret As Long
    If Cancel% = 0 Then
        Ret = Api_ReleaseDC(Picture1.GethWnd, hDC1)
        Ret = Api_ReleaseDC(Picture2.GethWnd, hDC2)
        Ret = Api_ReleaseDC(Picture3.GethWnd, hDC3)
        End
    End If
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End