471,350 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

What's better? Graphics.FromHwnd or Graphics.FromHdc

I've seen both used... FromHwnd can be called like this
FromHwnd(this.Handle). FromHdc needs a call to
User32.GetWindowDC(this.Handle) - so my assumption is that FromHwnd is
better because it's less calls, but what's really the case?
Dec 2 '05 #1
1 7165
Benny,

Correct would be to use CreateGraphics method of the control class
e.g. Graphics g = this.CreateGraphics();

All other methods are meant to be used in some rear cases like for example
you receive handle to device context form a windows message (overridding
WndProc method), subclassing windows control (NativeWindow class), PInvoke,
etc.

Normally you shouldn't use those methods, there are sign that you may use
unmanaged code.

As long as it goes for Graphics.FromHwnd and Graphics.FromHdc I believe they
differ in their application. You may have HDC without having HWND like
memory device context or printers.

I don't know what is User32 that you are referring to, but I guess it is
some kind of a wrapper for PInvoke (unamanged API calls) in this case I'll
go for FromHwnd because the solution is at least managed.
--

Stoitcho Goutsev (100) [C# MVP]

"Benny Raymond" <be***@pocketrocks.com> wrote in message
news:up**************@TK2MSFTNGP15.phx.gbl...
I've seen both used... FromHwnd can be called like this
FromHwnd(this.Handle). FromHdc needs a call to
User32.GetWindowDC(this.Handle) - so my assumption is that FromHwnd is
better because it's less calls, but what's really the case?

Dec 2 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
53 posts views Thread by Paul Rubin | last post: by
1 post views Thread by DBC User | last post: by
9 posts views Thread by Jay | last post: by
1 post views Thread by Polaris | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.