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
209 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
Comment Utility
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
Comment Utility
Thanks a lot.  Works perfectly!!
0
 
LVL 7

Author Comment

by:stelth240
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now