-
Simple BitBlt question
This may sound stupid but, why does my BitBlt call not work under any Sub or Function other than a Command Button??? I'm totally stumped!
If I put the code under the Command Button, the image will be blitted just fine, but under no other circumstances will it work.
:(
-
BitBlt should work from pretty much anywhere in the code. Where are you declaring it? If you are declaring it in the form module as private it can't be called out side the form. You can put the declaration into a code module and make it public. You should then be able to call it from anywhere.
If you have all of this covered then and say you want to blt from a code module to picBackGround.hdc make sure that you include the form that it is from. So as the destination (or source) you should use Form1.picBackGround.hdc. This will direct it to the proper place.
Does this help? If not I don't know what the problem is, sorry.
Drewski
-
Code:
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As
Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long,
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long,
ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
BitBlt Front.hDC, 32, 32, 32, 32, LinkSprite.hDC, 32, 32, vbSrcCopy
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
BitBlt Front.hDC, 32, 32, 32, 32, LinkSprite.hDC, 32, 32, vbSrcCopy
End If
End Sub
Private Sub Form_Load()
BitBlt Front.hDC, 32, 32, 32, 32, LinkSprite.hDC, 32, 32, vbSrcCopy
End Sub
This is the code for my form. (This was just a test app, so there's not much in it.) The code for the command button will display the image in the picture box Front on the form. But the other code won't work. Even if I put the BitBlt call in my own Sub, it won't work unless that Sub is called from inside the Command Button Sub. :(
-
is the KeyPreview property on the form set to = True?
-
OK. I set the key preview to True and now the KeyDown works fine. But I still can't BitBlt from the Form routine or from my own Sub routines called from the Form_Load().
The other weird thing is: if I delete the Command button from the form, and just call the BitBlt from the Form_Load(), the entire form will disappear altogether. :confused: