Link to home
Start Free TrialLog in
Avatar of vorlon
vorlon

asked on

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
Avatar of Lockias
Lockias

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

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

~Lockias
Avatar of vorlon

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Lockias
Lockias

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vorlon

ASKER

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
>> 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
Avatar of vorlon

ASKER

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
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
ShaunWilde:
  Did you read everything thus far?  You are just restating.
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?
> 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
simply subclass it, like stated above ;-)
ShaunWilde:
  Is that just a different way of doing it, or do you get a different effect?

~Lockias
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
Avatar of vorlon

ASKER

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

See-through calendar application.  Details to come...

BTW:  Painting to the desktop window is definetly NOT the way to go.
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...