Hello, I have a problem with bitblt, it draw a plain black square as described in the thread title. I haven't been able to find a problem and I hope that someone here can, thanks in advance. Below you can find my code.
Public Class frmMain
Dim recx As Integer = 0
Dim recy As Integer = 0
Dim angle As Integer = 0
Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Enum Raster As UInteger
'''dest = source
SRCCOPY = &HCC0020
'''dest = source OR dest
SRCPAINT = &HEE0086
'''dest = source AND dest
SRCAND = &H8800C6
'''dest = source XOR dest
SRCINVERT = &H660046
'''dest = source AND (NOT dest)
SRCERASE = &H440328
'''dest = (NOT source)
NOTSRCCOPY = &H330008
'''dest = (NOT src) AND (NOT dest)
NOTSRCERASE = &H1100A6
'''dest = (source AND pattern)
MERGECOPY = &HC000CA
'''dest = (NOT source) OR dest
MERGEPAINT = &HBB0226
'''dest = pattern
PATCOPY = &HF00021
'''dest = DPSnoo
PATPAINT = &HFB0A09
'''dest = pattern XOR dest
PATINVERT = &H5A0049
'''dest = (NOT dest)
DSTINVERT = &H550009
'''dest = BLACK
BLACKNESS = &H42
'''dest = WHITE
WHITENESS = &HFF0062
''' Capture window as seen on screen. This includes layered windows
''' such as WPF windows with AllowsTransparency="true"
CAPTUREBLT = &H40000000
End Enum
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
'MsgBox(e.KeyCode)
Select Case e.KeyCode
Case 37 'left
recx -= 5
Case 38 'top
recy -= 5
Case 39 'right
recx += 5
Case 40 'down
recy += 5
Case 32
angle += 1
If angle > 359 Then
angle -= 360
End If
End Select
End Sub
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
End Sub
Private Sub tmr_MainLoop_Tick(sender As Object, e As EventArgs) Handles tmr_MainLoop.Tick
Dim IMG As New Bitmap(Application.StartupPath & "\img.bmp")
Dim gIMG As Graphics = Graphics.FromImage(IMG)
Dim dcIMG As IntPtr = gIMG.GetHdc
Dim g As Graphics = Me.CreateGraphics()
Dim dcMainForm As IntPtr = g.GetHdc
BitBlt(dcMainForm, 0, 0, Me.Width, Me.Height, dcIMG, 0, 0, Raster.SRCCOPY)
'gIMG.TranslateTransform(CSng(tempIMG.Width) / 2, CSng(tempIMG.Height) / 2)
'gIMG.RotateTransform(angle)
'gIMG.TranslateTransform(-CSng(tempIMG.Width) / 2, -CSng(tempIMG.Height) / 2)
'gIMG.DrawImage(My.Resources.tankBar, 0, 0)
'g.FillRectangle(Brushes.White, 0, 0, Me.Width, Me.Height)
'g.DrawImage(IMG, New Point(recx, recy))
g.ReleaseHdc(dcMainForm)
g.Dispose()
gIMG.ReleaseHdc(dcIMG)
gIMG.Dispose()
IMG.Dispose()
End Sub
End Class
Public Class frmMain
Dim recx As Integer = 0
Dim recy As Integer = 0
Dim angle As Integer = 0
Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _
ByVal nYDest As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
ByVal dwRop As Int32) As Boolean
Enum Raster As UInteger
'''dest = source
SRCCOPY = &HCC0020
'''dest = source OR dest
SRCPAINT = &HEE0086
'''dest = source AND dest
SRCAND = &H8800C6
'''dest = source XOR dest
SRCINVERT = &H660046
'''dest = source AND (NOT dest)
SRCERASE = &H440328
'''dest = (NOT source)
NOTSRCCOPY = &H330008
'''dest = (NOT src) AND (NOT dest)
NOTSRCERASE = &H1100A6
'''dest = (source AND pattern)
MERGECOPY = &HC000CA
'''dest = (NOT source) OR dest
MERGEPAINT = &HBB0226
'''dest = pattern
PATCOPY = &HF00021
'''dest = DPSnoo
PATPAINT = &HFB0A09
'''dest = pattern XOR dest
PATINVERT = &H5A0049
'''dest = (NOT dest)
DSTINVERT = &H550009
'''dest = BLACK
BLACKNESS = &H42
'''dest = WHITE
WHITENESS = &HFF0062
''' Capture window as seen on screen. This includes layered windows
''' such as WPF windows with AllowsTransparency="true"
CAPTUREBLT = &H40000000
End Enum
Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
'MsgBox(e.KeyCode)
Select Case e.KeyCode
Case 37 'left
recx -= 5
Case 38 'top
recy -= 5
Case 39 'right
recx += 5
Case 40 'down
recy += 5
Case 32
angle += 1
If angle > 359 Then
angle -= 360
End If
End Select
End Sub
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
End Sub
Private Sub tmr_MainLoop_Tick(sender As Object, e As EventArgs) Handles tmr_MainLoop.Tick
Dim IMG As New Bitmap(Application.StartupPath & "\img.bmp")
Dim gIMG As Graphics = Graphics.FromImage(IMG)
Dim dcIMG As IntPtr = gIMG.GetHdc
Dim g As Graphics = Me.CreateGraphics()
Dim dcMainForm As IntPtr = g.GetHdc
BitBlt(dcMainForm, 0, 0, Me.Width, Me.Height, dcIMG, 0, 0, Raster.SRCCOPY)
'gIMG.TranslateTransform(CSng(tempIMG.Width) / 2, CSng(tempIMG.Height) / 2)
'gIMG.RotateTransform(angle)
'gIMG.TranslateTransform(-CSng(tempIMG.Width) / 2, -CSng(tempIMG.Height) / 2)
'gIMG.DrawImage(My.Resources.tankBar, 0, 0)
'g.FillRectangle(Brushes.White, 0, 0, Me.Width, Me.Height)
'g.DrawImage(IMG, New Point(recx, recy))
g.ReleaseHdc(dcMainForm)
g.Dispose()
gIMG.ReleaseHdc(dcIMG)
gIMG.Dispose()
IMG.Dispose()
End Sub
End Class