Solved

Drawing on the desktop

Posted on 2001-08-06
23
417 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
[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
  • 8
  • 5
  • 4
  • +3
23 Comments
 
LVL 2

Expert Comment

by:Lockias
ID: 6356392
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
ID: 6356396
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
ID: 6356553
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 2

Accepted Solution

by:
Lockias earned 50 total points
ID: 6356577
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
ID: 6356725
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
ID: 6356746
>> 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
ID: 6357112
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
ID: 6357286
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
ID: 6357320
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
ID: 6357328
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
 
LVL 2

Expert Comment

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

Expert Comment

by:MichaelS
ID: 6358459
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
ID: 6358488
> 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
ID: 6358996
simply subclass it, like stated above ;-)
0
 
LVL 2

Expert Comment

by:Lockias
ID: 6359856
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
ID: 6360137
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
ID: 6360198
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
ID: 6360356
0
 
LVL 2

Expert Comment

by:Lockias
ID: 6360359
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
ID: 6372646
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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