473,785 Members | 2,777 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 41887
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
2377
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
14734
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
1893
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
5503
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
10275
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
3111
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
4270
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
4028
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
1183
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
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
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
8973
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...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
3
2879
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.