473,236 Members | 1,348 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,236 software developers and data experts.

Device Context

Is it possible to render a winform directly to a memory device context
instead of rendering to a display device context ?

Jun 27 '08 #1
6 5338
On Thu, 12 Jun 2008 18:22:00 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
Is it possible to render a winform directly to a memory device context
instead of rendering to a display device context ?
In .NET, you render to a Graphics instance, not a DC. So technically, you
can do neither.

Depending on what you are _really_ trying to do, you may find the
Control.DrawToBitmap() method useful. Googling this newsgroup for other
threads that mention that method will turn up other techniques as well,
including Graphics.CopyFromScreen() and using p/invoke with the WM_PRINT
message.

Pete
Jun 27 '08 #2
Hi Peter, Thanks

The graphics object has a method called GetHdc() that gets a handle to the
current device context which then I can use in a win32 call to
createcompompatipledc.....

but I want to capture the form without it displaying to the physical display
if at all possible. I played around with Control.DrawToBitmap but the form is
still rendered to the physical display, I was just hoping I could change the
Device Context or something similar, whether in managed or unmanged code, so
that the Form would be rendered to a different type of device, so that the
form is captured but never seen on the display.

I went as far as to instantiate the new form call the show() method, capture
the
screen, then set the form to .visible = false; You don't see the form but
there is a
definite ugliness of seeing the screen flicker.

"Peter Duniho" wrote:
On Thu, 12 Jun 2008 18:22:00 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
Is it possible to render a winform directly to a memory device context
instead of rendering to a display device context ?

In .NET, you render to a Graphics instance, not a DC. So technically, you
can do neither.

Depending on what you are _really_ trying to do, you may find the
Control.DrawToBitmap() method useful. Googling this newsgroup for other
threads that mention that method will turn up other techniques as well,
including Graphics.CopyFromScreen() and using p/invoke with the WM_PRINT
message.

Pete
Jun 27 '08 #3
On Thu, 12 Jun 2008 18:56:06 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
The graphics object has a method called GetHdc() that gets a handle to
the
current device context which then I can use in a win32 call to
createcompompatipledc.....
Yes it does and yes you can. And yet, that has nothing to do with your
question.
but I want to capture the form without it displaying to the physical
display
if at all possible. I played around with Control.DrawToBitmap but the
form is
still rendered to the physical display,
DrawToBitmap() does not itself prevent the form from being shown
on-screen. In fact, it is generally limited to drawing the form as it's
shown on-screen, including any clipping that might occur (I know for
controls within a form this is true, and it might be for the whole form
too).
I was just hoping I could change the
Device Context or something similar, whether in managed or unmanged
code, so
that the Form would be rendered to a different type of device, so that
the
form is captured but never seen on the display.
I mentioned WM_PRINT. That might accomplish what you want, if you send it
to a form that's not visible but has otherwise been created. You may have
to call Control.CreateControl() first since you're not actually showing
the form.

I prefer not to second-guess, but the fact is what you're trying to do is
pretty unusual (as evidenced by lack of support in the API for it). I
don't know what your ultimate goal here is, but you may want to rethink
it. :)

Pete
Jun 27 '08 #4
Hi Peter,

What I meant by the first statement was a nice way of saying that a Device
Context does exist in .net, and the Graphics object does encapsulate it's
functionality, that's all I meant by that scenario.

I do like your second option with WM_PAINT, though.

On MSDN documentation it says that there are 4 types of Device Contexts, 2
obvious
Display, Printer, the third being a memory DC.......
The documentation states that if you use a memory DC and have your
application write to this vs a Display DC, the output is rendered, captured
and never shows, because you by-passed the Display device. Maybe I read to
much into this, but it sounded as though there was a way to set this Device
Context so that your app renders to a device of choosing. Unfortunitley the
documentation pretty much stopped there, and not going into how to change the
default funtionality of rendering to a Display DC.

Thanks

Nick

"Peter Duniho" wrote:
On Thu, 12 Jun 2008 18:56:06 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
The graphics object has a method called GetHdc() that gets a handle to
the
current device context which then I can use in a win32 call to
createcompompatipledc.....

Yes it does and yes you can. And yet, that has nothing to do with your
question.
but I want to capture the form without it displaying to the physical
display
if at all possible. I played around with Control.DrawToBitmap but the
form is
still rendered to the physical display,

DrawToBitmap() does not itself prevent the form from being shown
on-screen. In fact, it is generally limited to drawing the form as it's
shown on-screen, including any clipping that might occur (I know for
controls within a form this is true, and it might be for the whole form
too).
I was just hoping I could change the
Device Context or something similar, whether in managed or unmanged
code, so
that the Form would be rendered to a different type of device, so that
the
form is captured but never seen on the display.

I mentioned WM_PRINT. That might accomplish what you want, if you send it
to a form that's not visible but has otherwise been created. You may have
to call Control.CreateControl() first since you're not actually showing
the form.

I prefer not to second-guess, but the fact is what you're trying to do is
pretty unusual (as evidenced by lack of support in the API for it). I
don't know what your ultimate goal here is, but you may want to rethink
it. :)

Pete
Jun 27 '08 #5
Hey Peter,

Lets take this from a different angle. Lets say I have Device X, and I've
created
a device driver for device X, how do I get a .Net application to render it's
contents to Device X .VS. the default device the Display ?

Thanks

Nick

"Peter Duniho" wrote:
On Thu, 12 Jun 2008 18:56:06 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
The graphics object has a method called GetHdc() that gets a handle to
the
current device context which then I can use in a win32 call to
createcompompatipledc.....

Yes it does and yes you can. And yet, that has nothing to do with your
question.
but I want to capture the form without it displaying to the physical
display
if at all possible. I played around with Control.DrawToBitmap but the
form is
still rendered to the physical display,

DrawToBitmap() does not itself prevent the form from being shown
on-screen. In fact, it is generally limited to drawing the form as it's
shown on-screen, including any clipping that might occur (I know for
controls within a form this is true, and it might be for the whole form
too).
I was just hoping I could change the
Device Context or something similar, whether in managed or unmanged
code, so
that the Form would be rendered to a different type of device, so that
the
form is captured but never seen on the display.

I mentioned WM_PRINT. That might accomplish what you want, if you send it
to a form that's not visible but has otherwise been created. You may have
to call Control.CreateControl() first since you're not actually showing
the form.

I prefer not to second-guess, but the fact is what you're trying to do is
pretty unusual (as evidenced by lack of support in the API for it). I
don't know what your ultimate goal here is, but you may want to rethink
it. :)

Pete
Jun 27 '08 #6
On Fri, 13 Jun 2008 06:59:00 -0700, ncolosi
<nc*****@discussions.microsoft.comwrote:
Lets take this from a different angle. Lets say I have Device X, and
I've created
a device driver for device X, how do I get a .Net application to render
it's
contents to Device X .VS. the default device the Display ?
That depends on what you mean by "contents". If it's your own class, you
just draw to the appropriate DC at the appropriate time.

If it's some other class, you hope that it supports WM_PRINT. Because if
it doesn't, short of somehow hooking into Windows's own screen
invalidation and redraw implementation, you don't have enough control over
those other classes.

Pete
Jun 27 '08 #7

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

Similar topics

1
by: Abd | last post by:
Hiiiiiii I am programming in Visual C++ 6.0 I want to get RGB percent of all of pixls of screen, and so I need to get Device Context of entire screen. I know that CClientDC dc(this) gets a divice...
0
by: Rahul | last post by:
Hi All, We are invoking a method exposed by thrid party DLL (Non COM), the method expects one of the parameter as handle to device context of vb.net form. As form object is changed in .Net, we...
1
by: Ben Taylor | last post by:
Hi Does anybody have any code examples of using C# to draw to a window using device contexts, more specifically, erasing the entire window by painting a background color in the OnPaint / OnDraw...
0
by: sandy_pt_in | last post by:
I am very new to C#... i have one VC++ dll using that i have to display video frames in picture box but VC++ dll function asking device context... how can I get device context of picture box as i...
1
by: Dennis | last post by:
I'm using VS 2003 my project uses COM interop and the Tao Framework. I have a custom control derived from UserControl. It implements many functions similar to the Tao's SimpleOpenGLControl, for...
0
by: Jigar Mehta | last post by:
Hye Friends.. Jigar Mehta from India.. Currently I want to load one BMP and show it onto device context.. So, has anyone done the thing? I have loaded the Image by CBitmap, but how to get it in...
13
by: Metallicraft | last post by:
I have a vb6 application. On the main form is a picture box with one or two images and several pieces of text displayed in it. These are created on the fly using gdi32 routines that are all in a...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
0
by: =?Utf-8?B?bmNvbG9zaQ==?= | last post by:
Is it possible to render a winform directly to a memory device context instead of rendering to a display device context ?
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: 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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.