How to get 'Graphics' of the whole screen?

  • Thread starter Thread starter Polaris
  • Start date Start date
P

Polaris

Hi Experts:

I'd like to be able to draw image outside my application.

I know I can get a drawing surface for a form by using:
Graphics g = Form.CreateGraphics

Just wonder, if there is similar way to get an instance of Graphics of the
whole screen?

Thanks In Advance!
Polaris
 
Polaris,

You can get the windows desktop handle through the P/Invoke layer,
calling the GetDesktopWindow function.

Once you have that, you can pass the handle to the static FromHwnd
method on the Graphics class to get the graphics instance for that window.
 
Hello,
I'd like to be able to draw image outside my application.

You should create a transparent form for that and paint on it. Even though
you can get a DC to paint “onscreen†(provided that your OS is not Vista),
the image would not be consistent as other apps start moving around or repainting
themselves.

The simplest way is to create a Window (from .NET 3.0) with AllowsTransparency=True,
without any border, and with transparent background — effectively, there
will be just the picture floating onscreen. Prior to 3.0, seems like there's
no easy way. That requires a few PInvoke calls — basically, you should use
PInvoke for CreateCompatibleDC, then CreateBitmap in it, then you can create
a Graphics over that DC, paint whatever needed, and blit that onscreen with
UpdateLayeredWindow.

(H) Serge
 
Back
Top