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
216 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
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

856 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