473,897 Members | 3,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Draw directly to screen

Is it possible to draw directly to the screen using the .net libraries? I
thought that it might be possible with GDI+ but I can't find out how to do it
anywhere. A part of me suspects I may have to look into using the Windows API.

Any ideas,

Darrell

Nov 16 '05 #1
6 41913
Within your own window you can draw using the Graphics object passed in the
OnPaint or Paint event arguments.

Dou you mean directly on the desktop? Yes you can by obtaining the desktop
handle and wrapping it in a GDI+ Graphics object using Graphics.FromHd c.

I generally use interop for this and import the GetDc and ReleaseDc methods.
You must remember to correctly release DC's when you do this.

It's not neat or pretty though...

[DllImport("User 32.dll")]

public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User 32.dll")]

public static extern void ReleaseDC(IntPt r dc);

protected override void OnPaint(PaintEv entArgs e)

{

SolidBrush b=new SolidBrush(Colo r.Red);
IntPtr desktopDC=GetDC (IntPtr.Zero);

Graphics g = Graphics.FromHd c(desktopDC);

g.FillEllipse(b ,0,0,1024,768);

g.Dispose();

ReleaseDC(deskt opDC);

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

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

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

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

"redneon" <re*****@discus sions.microsoft .com> wrote in message
news:05******** *************** ***********@mic rosoft.com...
Is it possible to draw directly to the screen using the .net libraries? I
thought that it might be possible with GDI+ but I can't find out how to do
it
anywhere. A part of me suspects I may have to look into using the Windows
API.

Any ideas,

Darrell

Nov 16 '05 #2
You cannot draw somewhere but within your own created windows.
That means you have to create a window before you can draw something.
If you want to make appear something on the users desktop you can always
make a borderless shaped/transparent window but you cannot draw without a
window neither with .net nor with the windows API.

"redneon" <re*****@discus sions.microsoft .com> schrieb im Newsbeitrag
news:05******** *************** ***********@mic rosoft.com...
Is it possible to draw directly to the screen using the .net libraries? I
thought that it might be possible with GDI+ but I can't find out how to do it anywhere. A part of me suspects I may have to look into using the Windows API.
Any ideas,

Darrell

Nov 16 '05 #3
This is great. Thanks. There's just another problem with it though. It only
draws it once. Is there any way to get it to constantly draw it? I'm
wondering if there's an event message I could capture in public override
WndProc for a screen refresh and stick it in there. I tried putting it in a
recursive while loop in it's own thread but obviously this is a bad idea and,
while it worked, it ended up just recursively drawing, jerking and generally
looking a mess.

Darrell

"Bob Powell [MVP]" wrote:
Within your own window you can draw using the Graphics object passed in the
OnPaint or Paint event arguments.

Dou you mean directly on the desktop? Yes you can by obtaining the desktop
handle and wrapping it in a GDI+ Graphics object using Graphics.FromHd c.

I generally use interop for this and import the GetDc and ReleaseDc methods.
You must remember to correctly release DC's when you do this.

It's not neat or pretty though...

[DllImport("User 32.dll")]

public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User 32.dll")]

public static extern void ReleaseDC(IntPt r dc);

protected override void OnPaint(PaintEv entArgs e)

{

SolidBrush b=new SolidBrush(Colo r.Red);
IntPtr desktopDC=GetDC (IntPtr.Zero);

Graphics g = Graphics.FromHd c(desktopDC);

g.FillEllipse(b ,0,0,1024,768);

g.Dispose();

ReleaseDC(deskt opDC);

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

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

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

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

"redneon" <re*****@discus sions.microsoft .com> wrote in message
news:05******** *************** ***********@mic rosoft.com...
Is it possible to draw directly to the screen using the .net libraries? I
thought that it might be possible with GDI+ but I can't find out how to do
it
anywhere. A part of me suspects I may have to look into using the Windows
API.

Any ideas,

Darrell


Nov 16 '05 #4
What about this funny idea: Generate a composition between the users current
desktop wallpaper and the stuff you want to draw.
That means you have to draw into this wallpaperbitmap in memory, write it to
a new file and set it as wallpaper.
The question is how often the things you are drawing should be refreshed.
May I ask what exactly you are drawing?

"redneon" <re*****@discus sions.microsoft .com> schrieb im Newsbeitrag
news:F1******** *************** ***********@mic rosoft.com...
This is great. Thanks. There's just another problem with it though. It only draws it once. Is there any way to get it to constantly draw it? I'm
wondering if there's an event message I could capture in public override
WndProc for a screen refresh and stick it in there. I tried putting it in a recursive while loop in it's own thread but obviously this is a bad idea and, while it worked, it ended up just recursively drawing, jerking and generally looking a mess.

Darrell

"Bob Powell [MVP]" wrote:
Within your own window you can draw using the Graphics object passed in the OnPaint or Paint event arguments.

Dou you mean directly on the desktop? Yes you can by obtaining the desktop handle and wrapping it in a GDI+ Graphics object using Graphics.FromHd c.

I generally use interop for this and import the GetDc and ReleaseDc methods. You must remember to correctly release DC's when you do this.

It's not neat or pretty though...

[DllImport("User 32.dll")]

public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("User 32.dll")]

public static extern void ReleaseDC(IntPt r dc);

protected override void OnPaint(PaintEv entArgs e)

{

SolidBrush b=new SolidBrush(Colo r.Red);
IntPtr desktopDC=GetDC (IntPtr.Zero);

Graphics g = Graphics.FromHd c(desktopDC);

g.FillEllipse(b ,0,0,1024,768);

g.Dispose();

ReleaseDC(deskt opDC);

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

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

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

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

"redneon" <re*****@discus sions.microsoft .com> wrote in message
news:05******** *************** ***********@mic rosoft.com...
Is it possible to draw directly to the screen using the .net libraries? I thought that it might be possible with GDI+ but I can't find out how to do it
anywhere. A part of me suspects I may have to look into using the Windows API.

Any ideas,

Darrell


Nov 16 '05 #5
> What about this funny idea: Generate a composition between the users current
desktop wallpaper and the stuff you want to draw.


There are about a million problems with that. Firstly, we're not all running
Cray supercomputers so the refresh rate will kill people. Secondly, I want to
draw on top of Windows too and setting the wallpaper would draw behind them.

Nov 16 '05 #6
Thats why I asked you what exactly you are trying to achieve. There is
always the option to make a topmost small invible/translucent window and
draw you stuff in there.

"redneon" <re*****@discus sions.microsoft .com> schrieb im Newsbeitrag
news:5F******** *************** ***********@mic rosoft.com...
What about this funny idea: Generate a composition between the users current desktop wallpaper and the stuff you want to draw.
There are about a million problems with that. Firstly, we're not all

running Cray supercomputers so the refresh rate will kill people. Secondly, I want to draw on top of Windows too and setting the wallpaper would draw behind them.

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2386
by: Stan Shankman | last post by:
C# -- Visual Studio.Net – Windows Application Greetings all, How do I copy a Form’s image to a bitmap? – And do so before it gets to the screen. I haven’t been able to find anyone that knows how to do this - - all I want to do is copy a Form’s image to a bitmap. - - In effect, I want to take a window-shot of a Form, (as opposed to a “screen-shot”) but it must be done before that Form hits the screen. Anyone? Ideas?
3
14742
by: °Ë´óɽÈË | last post by:
Hi, I create a graphics object for desktop window by following step: IntPtr hWnd = GetDesktopWindow(); // API Graphics g = Graphics.FromHWnd(hWnd); then draw the screen by g, but I can't draw anything. WHY?? And I try to draw by DC (get by GetDC), it's fail either.
1
1902
by: redneon | last post by:
Is it possible to draw directly to the title bar on a window? I'm wanting to add another button to the window to pin it on top. Any ideas? Darrell
2
5506
by: Hai Ly Hoang | last post by:
Hi, I want to draw directly on to the screen. I think i should get the Graphics object of the screen. It's easy to get do it in C++ (by GetWindowDC(NULL)). But how to do that in C# ? Thanks
8
10278
by: Oberfuhrer | last post by:
I am an old mathematician, who in my sparetime work on a topic oriented math application. I have converted from old, dry Fortran to the more intuitive and juicy VB.net and Windows. In particular i would like to have options to draw graphics straight to a bitmap object. A typical example would be to save a plot of a function y=f(x) drawn on a control.
2
3115
by: myjpa1 | last post by:
Hi, all, I want to draw image directly onto top of screen, which simulates the OSD(on screen display) effects. However, class Graphics must link to certain controls, that cannot be used to draw at an arbitary position. Does anyone know any approaches can perform this job? thanks,
1
4278
by: nickyeng | last post by:
i have to design a simple game. I asked some question before in this forum. Now the game version is the new version with more items in it. now, i have a 11 items to draw, '$'. and i have a function in a header file called utils.h, GetRandom() function. code: inline unsigned GetRandom(unsigned min, unsigned max) { return rand() % (max - min + 1) + min;
9
4040
by: zhaow | last post by:
Hi, All Greetings! I want to develop as appllication that requires a line-drawing function in the blank area between two forms. I have looked up the MSDN, it says that a graphics object need a reference to a control or a form. I guess it means that lines can't be draw on blank area between two forms. Can anybody guarantee this for me? Is there any method can realize this function? I mainly want to draw a line from a button in form1 to...
0
1186
by: active | last post by:
On a user control that contains a tabcontrol I do: Dim gr As Graphics = TabPage5.CreateGraphics... and nothing displays I add a panel2 and change to
0
10849
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10476
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9655
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8031
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6073
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4697
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4292
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3299
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.