Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Paint the MDI Form with the desktop using PaintDesktop API in VB6

Posted on 2006-06-29
10
Medium Priority
?
1,232 Views
Last Modified: 2012-06-27
Hello,

I am using the following code to paint a normal form and it works.

    PaintDesktop Me.hdc

In the standard module i have the declaration for PaintDesktop

Public Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As
Long

Now I am not able to get the Me.hdc for the MDI Form. So I used the
following additional API calls.

Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

Now in the MDI Form I use the code:

Dim lngLong As Long, hdc As Long

hdc = GetDC(GetDesktopWindow())
   
lngLong = PaintDesktop(hdc)

the result in lngLong is 1 but the MDIForm is not painted with the
desktop.

Please help.

Thanks,

Pradeep Varma
0
Comment
Question by:pradeepvarma
[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
  • 6
  • 4
10 Comments
 

Author Comment

by:pradeepvarma
ID: 17016228
Hello,

I used the following code which worked in the form click for a normal form.

Dim hdc as long

hdc=GetDC(Me.Hwnd)

PaintDesktop hdc

The same code does not work in an MDiForm click.

Thanks,

Pradeep Varma
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17016944

what you could do, is draw on a hidden picturebox, and then set the mdi form's picture object to the picture of the hidden picturebox


see this for more info:
http://www.vb-helper.com/howto_mdi_background_draw.html
0
 

Author Comment

by:pradeepvarma
ID: 17017155
Hello Mark,

I appreciate your quick response in this regard.

I further researched the issue and found that using the SystemParametersInfo
API we can get the wallpaper that is used by the desktop. So I used the
following peice of code:

    SystemParametersInfo 115, Len(strFileInfo), ByVal strFileInfo, 0
   
    mdiMain.Picture = LoadPicture(strFileInfo)

It is setting the active desktop wall paper as the MDI form's background but
not the entire form. Still there is some area which  has the default form
colour.

Has it got something to do with the size parameter of LoadPicture?

Please Suggest!!!

Thanks,

Pradeep.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pradeepvarma
ID: 17017386
Hello Mark,

I think it is an issue related to the screen resolution.

I am attempting to see that the MDIForm displays picture in the same irrespective of the screen resolution chosen.

Any Ideas???

Thanks,

Pradeep
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 1000 total points
ID: 17017920

got it!



place a timer on your mdi form, (Timer1)

set it's interval to somthing nice like 50 ms (test to see what is the best value)


then use this code:

Option Explicit
Private Declare Function PaintDesktop Lib "user32" (ByVal hdc As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Dim clientHwnd As Long
Dim clientDC As Long

Private Sub MDIForm_Load()
   clientHwnd = FindWindowEx(Me.hwnd, 0, "MDIClient", vbNullString)
   clientDC = GetDC(clientHwnd)
End Sub

Private Sub Timer1_Timer()
   PaintDesktop clientDC
End Sub
0
 

Author Comment

by:pradeepvarma
ID: 17023468
Mark,
I tried your solution and it is working. Thanks for your efforts.

I would like to ask you one question. It is:

As i mentioned in my previous note, I could successfully get the desktop
wall paper and set it to the MDI Form using the LoadPicture. It is working
but for the window is not covering the entire MDI Form. If i set the screen
resolution to 600/800 everything looks good. But the screen resolution that
the users have is different.

I am just looking at dispalying the picture such that it covers the entire
MDI Form.

Any help would be highly appreciated.

I am using Visual Basic 6.0

The Code that I am using is:

SystemParametersInfo 115, Len(strFileInfo), ByVal strFileInfo, 0

mdiMain.Picture = LoadPicture(strFileInfo,VbLPLarge))

Thanks and Regards,

Pradeep
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17023654

ok, try this:
put an picture control on your form,
and an image control in it

(leave the names default)


then use this code:

Private Sub MDIForm_Resize()
   Picture1.BorderStyle = 0
   Image1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
   Picture1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
   Image1.Stretch = True
   Image1.Picture = LoadPicture("your picture here")
   Picture1.AutoRedraw = True
   Picture1.PaintPicture Image1.Picture, 0, 0, Me.ScaleWidth, Me.ScaleHeight
   Me.Picture = Picture1.Image
   Picture1.Visible = False
End Sub
0
 

Author Comment

by:pradeepvarma
ID: 17026415
Fantastic,

Thanks Mark,

Now I uderstand that we cannot do this without placing controls like Picture box and Image. I was trying to see if i can make the picture set to picture property of the MDIForm expand to the full size.

I understood both of your methods, but the first one seems to be better. So I will go ahead and Implement it.

Thanks once again Mark!!

Regards,

Pradeep
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 17026523

thanks for the points, and happy coding!


the first method is indeed somewhat better,
but it gives a somewhat different output:
the first paints the desktop on the form that would be visible when the form is "see- trough"
so if you have a small form, only the piece of the desktop underneath is visible


the second loads the picture, and stretches it so it fits exactly on the form
0
 

Author Comment

by:pradeepvarma
ID: 17026972
Thanks for the suggestions.

I am in the process of desgining an MDI application and using MDI Form. I intend to provide this feature only for the MDI form. So, No issues.

Thanks,

Pradeep
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

618 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