Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing direct on the desktop 1

Status
Not open for further replies.

IWarez

Programmer
Dec 10, 2002
26
NL
Is it possible to draw direct on the desktop using subclassing or other kind of tricks while maintaining the wallpaper and icons? I can draw on the desktop but I draw over the icons :( I've seen a program called desktop plant that seems to do just what I want and I want to be able to do that too. Keep in mind that I want the icons to function normal. Anyone who can help?
 
My way of doing this....

'==========================================================
Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Const IMAGE_ICON = 1
Const LR_LOADFROMFILE = &H10

Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal dwImageType As Long, ByVal dwDesiredWidth As Long, ByVal dwDesiredHeight As Long, ByVal dwFlags As Long) As Long

Private return2 As Long
Private strPic As String
Private hBitmap As Long

Private Sub CmdDraw_Click()
DrawIcon GetWindowDC(0), 100, 100, return2&
End Sub

Private Sub Form_Load()
strPic = app.path & "\icon.ico"
hBitmap = LoadImage(App.hInstance, strPic, IMAGE_ICON, 32, 32, LR_LOADFROMFILE)
return2 = hBitmap
End Sub

'========================================================== All the Best
Praveen Menon
pcmin@rediffmail.com
 
Oh, you mean like those Word 2000 characters <paper clip, the cat, albert, etc>.

I remember coming across some code elsewhere for making them appear, query the user, and close...I'm pretty certain they use MS Agent for the object calls, just not 100% sure. You can try surfing and see what comes up.
 
No, you both don't get what I really wanted. When you see your desktop (with all the icons, wallpaper, and so on) there is lots of space left for me to put some useful information like a calendar, a better clock, messages, etc... I don't want a form always on top showing me this. So I thought it would be a good idea to embed my form (or a bitmap) into the desktop's listview. Offcourse I could grab the wallpaper, draw my stuff on it and replace the wallpaper with the original picture + my additions. But that's slow and non-professional. I want to draw at the listviews' hdc without flickering and without drawing over the icons... Is that possible?
 
Yes, it is possible - but it is difficult to avoid a little flicker
 
Ok, I'll go for a little bit of flickering. Any idea's for this? I tried subclassing the desktop but I think I did it wrong 'cause I was never able to let the icons draw above my picture. So a little code sample would be great.
 
It sounds like you want to use the desktop space as a container. Interesting... Usually, what you see are things floating above, but you want your application to effectively run underneith the icons... am I right?

Geez, I hate it when someone gives me an idea like this and now I'll be up all night trying to pull it off!

We'll keep this thread going... this sounds fun.

Tuna
 
It is fun... It's actually meant to be fun but I get frustrated as it doesn't seem to be possible. I will try again with a global system hook. If you get it running I would sure like a piece of code.
 
I haven't tried anyting with this yet, but I'm thinking...

You should have to get the handle of the window (in this case the desktop).

Declare Function GetDeskTopWindow& lib &quot;user32&quot;()

Once you have the handle of the desktop, paint your form there, if it kills your icons, there should be an API to repaint the icons to that window...

Oh the possibilities!

Tuna
 
I think you won't get there with GetDesktopWindow. The desktop window controls some other windows including the SysListView32 which does include the wallpaper image. So a little FindWindowEx is also needed. Once found I think I must force the listview to draw the wallpaper with my graphics embedded. I searched a bit more and I think I need the CTLCOLOREDIT (or something like that) message. Now the real problem is implementing the subclassing...
 
Do you have Dan Applemans Guide to the Win32 API?

I've never really read it, just use it as a reference like he says NOT to do... anyway... I'm reading those chapters about this stuff, and I know it can be done. You're right though, it's not going to be as simple as I thought.

Tuna
 
Unfortunately, that won't work because of the way the ListView repaints itself(as IWarez points out, he knows how to draw to the desktop). Nor does it work if you paint into the ListView; again, the LV's repaint method causes problems.

There's a line of attack using a background image - but that has to be loaded from a file (and would interfere with any wallpaper you have set, since this is also rendered using the ListViews background image functions, which can only support one image at a time)

Another alternative is to render turn your picture into a bitmap and select it into the genuine Desktop (i.e. behind the Listview), then set the background colour of the listview to transparent (CLR_NONE). I suspect that this will also muck up wallpaper, and also makes the ListView slower to redraw.

The third possibility is to make the ListView ownerdraw, and subclass it...
 
- The background image I reject instantly. It's unprofessional :)
- Making the wallpaper transparent and showing my picture through is worth a try.
- Making the listview ownerdrawn... mmm, ok, but a little bit tricky to test with the desktop. I guess I'll go for a simple listview in my own window first and then trying to let it do it my way. After that I'll try to do the same with the desktop window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top