SetBkMode
VB.Net
Imports System.Runtime.InteropServices
Module SetBKMode
Const GDI32_DLL As String = "gdi32.dll"
<DllImport(GDI32_DLL, EntryPoint:="SetBkMode")>
Private Function setbkmode(hdc As IntPtr, bgmode As Integer) As Integer
End Function
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Integer) As Integer
<DllImport("user32.dll", EntryPoint:="GetDC")>
Public Function GetDC(ByVal ptr As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")>
Private Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Boolean
End Function
Sub SetBKMode_Main()
' Create a device context (DC)
''Dim hdc As IntPtr = CreateCompatibleDC(IntPtr.Zero)
' Set the background mode to transparent
''setbkmode(hdc, 1) ' 1 = TRANSPARENT
' ...
Dim srcBmp As New Bitmap(Image.FromFile("asciipad.png"))
Dim hbm As IntPtr = srcBmp.GetHbitmap()
Dim sdc As IntPtr = GetDC(IntPtr.Zero)
Dim hdc As IntPtr = CreateCompatibleDC(sdc)
ReleaseDC(IntPtr.Zero, sdc)
End Sub
End Module