Solved

Drawing on the desktop

Posted on 2001-08-06
23
413 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
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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