Solved

Drawing on the desktop

Posted on 2001-08-06
23
410 Views
Last Modified: 2013-12-03
Hi all,

I wanted to know how one would draw on the desktop. I have:


case WM_PAINT :
hdc = BeginPaint (GetDesktopWindow(), &ps) ;
GetClientRect (GetDesktopWindow(), &rect) ;
DrawText (hdc, szStartMsg, -1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (GetDesktopWindow(), &ps) ;
return 0 ;


which obviously doesn't work...

Thanks in advance for your time.
Vorlon
0
Comment
Question by:vorlon
  • 8
  • 5
  • 4
  • +3
23 Comments
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
You can create a  DC for the desktop to draw to using the function CreateDC like this
hdc = CreateDC("DISPLAY", NULL, NULL, NULL);

~Lockias
0
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
Also you can obtain a dc for the entire screen bt calling GetDC with a NULL argument.

~Lockias
0
 
LVL 2

Author Comment

by:vorlon
Comment Utility
lockias,

I've modified the code (see below) but it still doesn't work... No drawing on the desktop...

case WM_PAINT :
hdc = CreateDC(NULL,NULL,NULL,NULL);
GetClientRect (GetDesktopWindow(), &rect) ;
DrawText (hdc, szStartMsg, -1, &rect,DT_SINGLELINE |   DT_CENTER | DT_VCENTER) ;
DeleteDC (hdc);
return 0 ;



Vorlon
0
 
LVL 2

Accepted Solution

by:
Lockias earned 50 total points
Comment Utility
Your CreateDC line is not quite right (re-read my first comment).

Either
 hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
-OR-
 hdc = GetDC(NULL);

~Lockias
0
 
LVL 2

Author Comment

by:vorlon
Comment Utility
lockias,

I accidentally refreshed the page which reposted my earlier message... sorry.

Anyway, CreateDC(NULL) is illegal since CreateDC takes 4 parameters. However, I changed the CreateDC call to CreateDC("DISPLAY",NULL,NULL,NULL).

Now I can paint on the screen/display but not on the desktop. The difference is that if after painting on the CreatedDC("DISPLAY") device, I can press F5 on the desktop (click on the desktop and then press F5), the desktop re-paints itself and erases what I've drawn. This is not what I was looking for.

I think I might have to sub-class the desktop window but I think you can't do that with Win9x. What do you think?

Thanks for you time,
Vorlon
0
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
>> Anyway, CreateDC(NULL) is illegal
Read what I wrote!
----------------------------
   Either
    //CreateDC has 4 Parameters
    hdc = CreateDC("DISPLAY", NULL, NULL, NULL);
   -OR-
    // but GetDC has only 1
    hdc = GetDC(NULL);
----------------------------

Yes, you would have to subclass the desktop window to achieve the affect you are looking for.

Or, I think, you could create a full-screen app that is completely transparent except for what you are trying to draw.

~Lockias
0
 
LVL 2

Author Comment

by:vorlon
Comment Utility
lockias,

I'm sorry, you're right: I'm not reading the messages like I should... That's what happens when you're doing 10 things at the same time....

How would I go about making a transparent app/window?

Thanks,
Vorlon
0
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
That's a whole other question, but I am not sure how well it would work.  I think you would be opening a big can of worms.  

What are you trying to do here?  Perhaps there is a better way altogether.  This does not seem very user friendly.

~Lockias
0
 
LVL 9

Assisted Solution

by:ShaunWilde
ShaunWilde earned 50 total points
Comment Utility
HWND hWnd= :: GetDesktopWindow();

HDC hDC = ::GetDC(hWnd);

use hDC to draw on the window - remember this will be overwritten when the screen refreshes - onless it is updated


::ReleaseDC(hDC);

0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
by the way you shuld only be respondin to WM_PAINT messages for painting on your window - if your app is invisible it will probbly miss out on these or will only issue them when necessary
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:Lockias
Comment Utility
ShaunWilde:
  Did you read everything thus far?  You are just restating.
0
 
LVL 6

Expert Comment

by:MichaelS
Comment Utility
What's about background picture. May be you can use such an aproach? Drow something on the bitmap, than put it like it's a desktop background :)

What are you trying to archive?
0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
> Did you read everything thus far?  You are just restating

yes - and no I wasn't just restating - you are all creating DC based on the screen DC whereas I was getting the HDC using the HWND of the desktop - there is a difference
0
 
LVL 9

Expert Comment

by:Pacman
Comment Utility
simply subclass it, like stated above ;-)
0
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
ShaunWilde:
  Is that just a different way of doing it, or do you get a different effect?

~Lockias
0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
actually I am not sure it works on 95 onwards as we have these .hta etc on the desktop and the desktop is now explorer - hmm maybe vorlon can explain what he wants to do and we could think of a different way to achieve it
0
 
LVL 2

Author Comment

by:vorlon
Comment Utility
Pacman,
I don't think there's a way to subclass in Win9x as mentioned above. If you know of a way please tell us.

ShaunWilde,
Your suggestion implemented as:
dw  =GetDesktopWindow();
hdc =GetDC(dw);
GetClientRect (GetDesktopWindow(), &rect) ;
DrawText (hdc, szStartMsg, -1, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;              
ReleaseDC(dw,hdc);

does not work...



All,

What I want to do is create a small app that simply draws a calendar on the desktop on startup. This way, by simply minimizing all of the windows you can easily look at the calendar. That's it. Nothing more...

I want this done as an external app instead of drawing on the background picture as suggested by MichaelS. The reason is that I want the user to be able to pick any background picture he/she likes at any time. If I draw on the bitmap, then I'll have to make a backup copy of it (instead of writing on the image and then have to worry about erasing it for the next month's calendar...) This approach could get messy...

Any other ideas?

Thanks all...
Vorlon

0
 
LVL 9

Expert Comment

by:ShaunWilde
Comment Utility
0
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
See-through calendar application.  Details to come...

BTW:  Painting to the desktop window is definetly NOT the way to go.
0
 

Expert Comment

by:AKRover
Comment Utility
u should sublclass the desktop and i'm almost sure u can do it on win98 also but remember that u have to be on the same context as exoplorer and for that u need to use SHLoadInProc...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

11 Experts available now in Live!

Get 1:1 Help Now