473,230 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

How can I draw on the desktop?

Don
Is there any way I can get an object that allows me to draw to the Windows
desktop using managed code? I've managed to figure out how to do it with
unmanaged code using API functions, but I was just wondering if there was a
more "proper" way to do it in VB.NET

- Don
Nov 20 '05 #1
7 8142
* "Don" <un*****@oblivion.com> scripsit:
Is there any way I can get an object that allows me to draw to the Windows
desktop using managed code? I've managed to figure out how to do it with
unmanaged code using API functions, but I was just wondering if there was a
more "proper" way to do it in VB.NET


AFAIS that's not supported by the .NET Framework.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Don
> > Is there any way I can get an object that allows me to draw to the
Windows
desktop using managed code? I've managed to figure out how to do it with unmanaged code using API functions, but I was just wondering if there was a more "proper" way to do it in VB.NET


AFAIS that's not supported by the .NET Framework.


That would explain why System.Drawing.Graphics.FromHwnd() works when passed
a handle to a form but not when passed a handle to the desktop. :-(

- Don
Nov 20 '05 #3
"Don" <un*****@oblivion.com> schrieb
Is there any way I can get an object that allows me to draw to the
Windows desktop using managed code? I've managed to figure out how
to do it with unmanaged code using API functions, but I was just
wondering if there was a more "proper" way to do it in VB.NET

Private Declare Function GetDC Lib "user32.dll" _
(ByVal hwnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32.dll" _
(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr

'...
Dim hdc As IntPtr

hdc = GetDC(IntPtr.Zero)

Try
Dim g As Graphics
g = Graphics.FromHdc(hdc)
Try
g.FillRectangle(Brushes.Red, 10, 10, 100, 100)
Finally
g.Dispose()
End Try
Finally
ReleaseDC(IntPtr.Zero, hdc)
End Try
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Sounds like you found the only way. The only thing I'd suggest is writing a managed code wrapper class for the unmanaged code functions you're using. At least that way you could call managed code methods from your application. (The wrapper calls the unmanaged code functions within the methods you define, and handles the exceptions.) That's what I do when I have to work with the shell, BITS, and other Windows APIs

Good luck
Ben
Nov 20 '05 #5
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Don" <un*****@oblivion.com> schrieb
Is there any way I can get an object that allows me to draw to the
Windows desktop using managed code? I've managed to figure out how [...]

Private Declare Function GetDC Lib "user32.dll" _
(ByVal hwnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32.dll" _
(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr


That's not managed code...

:-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
All I have to say is Longhorn.

Hopefully.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Don" <un*****@oblivion.com> schrieb
Is there any way I can get an object that allows me to draw to the
Windows desktop using managed code? I've managed to figure out how
[...] Private Declare Function GetDC Lib "user32.dll" _
(ByVal hwnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32.dll" _
(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr


That's not managed code...

:-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #7
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Private Declare Function ReleaseDC Lib "user32.dll" _
(ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As IntPtr


That's not managed code...

:-)


Ahhh, sorry!! I didn't read conscientiously. :-/
--
Armin

Nov 20 '05 #8

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

Similar topics

2
by: Matt | last post by:
I am writing a recursive program to draw the lines recursively, given the range and number of intervals (n) between the range. The problem is I don't know how to draw the line in point 0.375, as...
0
by: Florida Draw | last post by:
------=_NextPart_000_0012_1D5428A2.65C196F8 Content-Type: text/plain Content-Transfer-Encoding: 8bit Sign-up for the FREE Holiday Giveaway Draw You must register to be eligible for the draw....
5
by: Matt | last post by:
I am writing a recursive program to draw the lines recursively, given the range and number of intervals (n) between the range. The problem is I don't know how to draw the line in point 0.375, as...
3
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...
6
by: redneon | last post by:
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...
3
by: Richard | last post by:
I have a requirement to put a GDI style circle or rectangle border around the selected row of a datagrid/ It will overlap into the row above and below the selected row. Doing this in a the OnPaint...
1
by: Carsten Klotz | last post by:
Hi, I've set the TransparencyKey of a form to black. That means, all black pixel will be shown transparent within the drawing content of that form. If I set the background to black, I can see...
9
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you抣l learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.