Skinning (BitBlt Introduction)

Example

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.

You might also like...

Comments

About the author

Marc Pritchard

Marc Pritchard United States

Apart from my school work I put most of my effort into running my joke site, I'd like to think that it makes someone smile each day. For about 1/2 a year I've been programming more and more in s...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It works on my machine.” - Anonymous