Drawing on the desktop

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
LVL 2
vorlonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

~Lockias
LockiasCommented:
Also you can obtain a dc for the entire screen bt calling GetDC with a NULL argument.

~Lockias
vorlonAuthor Commented:
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
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

LockiasCommented:
Your CreateDC line is not quite right (re-read my first comment).

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

~Lockias

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vorlonAuthor Commented:
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
LockiasCommented:
>> 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
vorlonAuthor Commented:
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
LockiasCommented:
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
ShaunWildeCommented:
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);

ShaunWildeCommented:
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
LockiasCommented:
ShaunWilde:
  Did you read everything thus far?  You are just restating.
MichaelSCommented:
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?
ShaunWildeCommented:
> 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
PacmanCommented:
simply subclass it, like stated above ;-)
LockiasCommented:
ShaunWilde:
  Is that just a different way of doing it, or do you get a different effect?

~Lockias
ShaunWildeCommented:
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
vorlonAuthor Commented:
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

ShaunWildeCommented:
LockiasCommented:
See-through calendar application.  Details to come...

BTW:  Painting to the desktop window is definetly NOT the way to go.
AKRoverCommented:
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...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.