Create a new VB project and in the decleration section of the form (at the top, before any functions or sub-routines) add the BitBlt decleration: 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
Now add another form, and fill it with a picture box. Name the new form 'frmPic' and the picture box 'pbxPic'. Make this new form and picture box larger than the first form.
Add a picture of your choice to the picture box and return to the code of the first form.
In the Form_Load event of the first form, add: frmPic.Show
Me.Refresh
Then in the Form_Paint
event (to get the form paint event, select 'Form' from the drop-down menu on the top left of the code window and then 'Paint' from the drop-down menu on the right of the code window.) add this:
BitBlt Me.hDC, 0, 0, Me.Width * Screen.TwipsPerPixelX, Me.Height * Screen.TwipsPerPixelY, frmPic.pbxPic.hDC, 0, 0, vbSrcCopy
(We multiply the width by the twips per pixel to convert the twips value from the form to the pixel value that BitBlt accepts.)
Lastly, add the Form_MouseDown
event and put this code into it:
Me.Refresh
You can now run the program. For best results put both forms apart on the screen and click on the first form. The image should be painted to the first form.
Comments