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
211 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now