• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Loading WallPaper Into a Form For Transparency

I need to load the background wall paper into a form. The difficulty here
is when I move the form, I want what ever screen area  behind the form to be loaded into the form in a synchronized manner. That is the new location of the
form needs to be computed, the region
should be captured as a bitmap and loaded into the form for a transparent

Can someone give me pointers to do this rather than simply telling me to BitBlt.
I am half way thru and am not able to figure out how to capture the screen area and load into to the form while moving it.

Sorry I dont have more points. Any help will be greatly appreciated.

  • 3
  • 2
  • 2
1 Solution
set the form's AutoRedraw property to TRUE.
set a picture as the form's picture property.

 then, the Form Resize event should be like this :

Private Sub Form_Resize()
   With Form1
     .PaintPicture .Picture, 0, 0, .Width, .Height
   End With
End Sub

srirambmAuthor Commented:
Dear Sir,

You have not understood the question.
I want to paint the desktop into my form
and synchronise the areas under the form
into the form for a transparent effect.

I will only need to load portions of the
wallpaper into the form.

I hope you understand.

Thank you for answering
you are right. i have not read the Q carefully. sorry.
now, you want a lot ot things which demand a long API codes.
now suppose an expert gives you 200 lines API code that answers just a part of your problems ?
that's why i'm not even start to get involved when there is more then one Q in a Q.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

If you know how to read the registry you can read the values of:

Wallpaper File:

HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper


HKEY_CURRENT_USER\Control Panel\Desktop\TileWallpaper

If you do not know how to read the registry search EE, I am sure there are lots of questions regarding that, and I want to answer your question here.

Load the wallpaper file into a picture box that is the same size as the screen and is the farthest back control on your form.  If TileWallpaper is not 0 you need to tile it. Or if it is smaller then the screen you need to center it.  For either of these tasks you can use the picturebox's paintpicture method.  Then set the picturebox's left and top properties to the negitive of the form's top and left properties.  You will have to make adjustments for the height of the titlebar (if you are displaying one). The draw back to this method is that any icons, toolbars, or taskbars will not be displayed (just the picture).  If you want these things displayed in your background, you are going to have to use BitBlt to capture the screen.
srirambmAuthor Commented:
I dont mind I f I need to bitblt anything. Is there any sample I can try?

I know how to get the wallpaper from the
registry et al. All I need is to get the
transparent effect. When I move my form,
the background (Whatever that is behind should show thru) should show thru.

Thanks for answering
Have bkgpic as a picturebox that is the farthest back control on the form.  Then try:

'Declarations section

Private Const SRCCOPY = &HCC0020

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 CreateDC Lib "gdi32" Alias "CreateDCA" _
   (ByVal lpDriverName As String, ByVal lpDeviceName As String, _
   ByVal lpOutput As Long, ByVal lpInitData As Long) As Long

Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long

Sub Form_Load()
    Dim picdc&
    With bkgPic
        .AutoRedraw = True
        picdc& = CreateDC("DISPLAY", "", "", 0&)
        tmp& = BitBlt(.hdc, 0, 0, scw!, sch!, picdc&, 0, 0, SRCCOPY)
        tmp& = DeleteDC(picdc&)
        .top= (-1) * me.top
        .left= (-1) * me.left
        .AutoRedraw = False
    End with
End Sub

then when you move the form make sure you reset the top and left of the bkgPic picturebox
srirambmAuthor Commented:
Good Technique, Thanks.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now