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
219 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 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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