[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

how do I draw on top of an existing Windows application

Scott Weinstein

12/12/2004 6:59:00 AM

I have the need to draw on top of an existing Windows application, and if
the window is not maximized I also need to draw outside of the window frame.
However, I need the existing Windows application to remain activated.

my first attempt at doing this I created a transparent form, maximized it,
and did my drawing. That worked well, but if my transparent form was
activated, the existing Windows application wasn't, and if the existing
Windows application was activated, the area overlapped didn't show my new
drawing.

So then I split the work, by using a transparent Windows form for the area
outside the application and the following for the area inside the app.
Dim g As Graphics = Graphics.FromHwnd(BaseWindow.Handle)

but the solution seems clumsy, and I don't know how to clear the drawing
created by the above line.

are there any suggestions on how to do this the correct way?



--Scott




3 Answers

Bob Powell

12/12/2004 2:13:00 PM

0

Use interop to obtain the desktop window and the desktop DC then draw on
that.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Scott Weinstein" <ScottAR@online.nospam> wrote in message
news:u9SwYgB4EHA.2288@TK2MSFTNGP11.phx.gbl...
> I have the need to draw on top of an existing Windows application, and if
> the window is not maximized I also need to draw outside of the window
frame.
> However, I need the existing Windows application to remain activated.
>
> my first attempt at doing this I created a transparent form, maximized it,
> and did my drawing. That worked well, but if my transparent form was
> activated, the existing Windows application wasn't, and if the existing
> Windows application was activated, the area overlapped didn't show my new
> drawing.
>
> So then I split the work, by using a transparent Windows form for the area
> outside the application and the following for the area inside the app.
> Dim g As Graphics = Graphics.FromHwnd(BaseWindow.Handle)
>
> but the solution seems clumsy, and I don't know how to clear the drawing
> created by the above line.
>
> are there any suggestions on how to do this the correct way?
>
>
>
> --Scott
>
>
>
>


Scott Weinstein

12/14/2004 12:37:00 AM

0

that works really well, except I'm having trouble with two things:

1 when my graphics intersect Win forms labels, the label seems to get
priority, and my graphics aren't shown

2 I'm not sure how to clear what I've drawn.I've tried the following
g = Graphics.FromHdc(desk.DC)
g.Restore(DesktopState)
but it doesn't seem to work. any suggestions?

--Scott W.



"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:OU04zSF4EHA.2316@TK2MSFTNGP15.phx.gbl...
> Use interop to obtain the desktop window and the desktop DC then draw on
> that.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> "Scott Weinstein" <ScottAR@online.nospam> wrote in message
> news:u9SwYgB4EHA.2288@TK2MSFTNGP11.phx.gbl...
>> I have the need to draw on top of an existing Windows application, and if
>> the window is not maximized I also need to draw outside of the window
> frame.
>> However, I need the existing Windows application to remain activated.
>>
>> my first attempt at doing this I created a transparent form, maximized
>> it,
>> and did my drawing. That worked well, but if my transparent form was
>> activated, the existing Windows application wasn't, and if the existing
>> Windows application was activated, the area overlapped didn't show my new
>> drawing.
>>
>> So then I split the work, by using a transparent Windows form for the
>> area
>> outside the application and the following for the area inside the app.
>> Dim g As Graphics = Graphics.FromHwnd(BaseWindow.Handle)
>>
>> but the solution seems clumsy, and I don't know how to clear the drawing
>> created by the above line.
>>
>> are there any suggestions on how to do this the correct way?
>>


Bob Powell

12/14/2004 6:21:00 AM

0

When and how are you drawing your graphics? I'm guessing in response to the
form paint in which case the child windows will draw after and overwrite
what you've drawn.

If you want to get rid of what you've drawn on the desktop you'll need to
take a snapshot of what was there before and blit the old bits back. You may
also be able to invalidate all the top-level windows under the pixels that
you want removed.

Another possibility that hadn't occurred to me before was that you might be
able to draw your stuff in a layered window that sits above the desktop.
Invalidating this window would automatically invalidate the windows below
and the system would manage your desktop redraws for you.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Scott Weinstein" <ScottAR@online.nospam> wrote in message
news:elznjUX4EHA.824@TK2MSFTNGP11.phx.gbl...
> that works really well, except I'm having trouble with two things:
>
> 1 when my graphics intersect Win forms labels, the label seems to get
> priority, and my graphics aren't shown
>
> 2 I'm not sure how to clear what I've drawn.I've tried the following
> g = Graphics.FromHdc(desk.DC)
> g.Restore(DesktopState)
> but it doesn't seem to work. any suggestions?
>
> --Scott W.
>
>
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:OU04zSF4EHA.2316@TK2MSFTNGP15.phx.gbl...
> > Use interop to obtain the desktop window and the desktop DC then draw on
> > that.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > "Scott Weinstein" <ScottAR@online.nospam> wrote in message
> > news:u9SwYgB4EHA.2288@TK2MSFTNGP11.phx.gbl...
> >> I have the need to draw on top of an existing Windows application, and
if
> >> the window is not maximized I also need to draw outside of the window
> > frame.
> >> However, I need the existing Windows application to remain activated.
> >>
> >> my first attempt at doing this I created a transparent form, maximized
> >> it,
> >> and did my drawing. That worked well, but if my transparent form was
> >> activated, the existing Windows application wasn't, and if the existing
> >> Windows application was activated, the area overlapped didn't show my
new
> >> drawing.
> >>
> >> So then I split the work, by using a transparent Windows form for the
> >> area
> >> outside the application and the following for the area inside the app.
> >> Dim g As Graphics = Graphics.FromHwnd(BaseWindow.Handle)
> >>
> >> but the solution seems clumsy, and I don't know how to clear the
drawing
> >> created by the above line.
> >>
> >> are there any suggestions on how to do this the correct way?
> >>
>
>