?
Solved

How to bit blit to the desktop and erase (also, if worth the points, a quick explanation of form bit blitting)

Posted on 2001-06-15
3
Medium Priority
?
239 Views
Last Modified: 2012-06-21
I have been trying this for a little while and was unsuccessful.  I would like to be able to blit a picture to the desktop, and erase it again.  Like you see with microsoft agent, a lot of those deskmate characters, and other things like that.  I would like to know how to blit to it, and also how to erase the picture.  Also, I do not want to use an invisible form, or anything like that.  Just a regular bit blit.

Also, if this is worth the 50 points, I would also like to know if I could get a quick tutorial on bit blitting to a form or picturebox.  I can bit blit fine on a form, but when I use a picturebox for the source image, i can't make the picturebox invisible or the picture won't blit, and I can't draw the picture over the hidden picturebox or I get a different image.

If someone could help with the top one, and if possible, the bottom one also, i'd appreciate it.  Thanks
0
Comment
Question by:stelth240
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
andyclap earned 200 total points
ID: 6197923
Desktop blitting -
get a handle to the desktop window, and then you can get its Device context and draw on it to your heart's content. You can grab what's originally there to enable you to erase what you've just drawn.
Note, however, I think this technique may run into problems on NT.

Quick example, just plonks out a 200x200 pixel chunk of picture1 to the desktop at 100,100

Private Declare Function GetDesktopWindow Lib "user32" () As Long
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 Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Private Const SRCCOPY = &HCC0020

Private Sub Command1_Click()

    Dim lHDesktop As Long
    Dim lHDC As Long
   
    lHDesktop = GetDesktopWindow
    lHDC = GetWindowDC(lHDesktop)
   
    BitBlt lHDC, 100, 100, 200, 200, Picture1.hdc, 0, 0, SRCCOPY
   
    ReleaseDC lHDesktop, lHDC
   
   
End Sub


An alternative to the above for doing things like little agent characters walking around, is to use a windows region to make an irrecularly shaped form. This will help no end with keeping the screen up to date properly. Have a search around in ee for some samples involving the SetWindowRgn API call.


Your last point about pictureboxes not painting is probably because the picture box doesn't have a picture to display (because it's not shown). Setting Autoredraw=true for the picture will create an buffer which will store the picture even when not shown, solving your problem.
0
 
LVL 7

Author Comment

by:stelth240
ID: 6198317
Thanks a lot.  Works perfectly!!
0
 
LVL 7

Author Comment

by:stelth240
ID: 6200879
I have one quick question on this topic.  I hope you receive this.  When I blit the desktop to a storage buffer, and blit my image to the desktop, the desktop won't refresh when I try to blit the storage back to the desktop.  Can you help me?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 19 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question