473,396 Members | 1,786 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,396 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 7519
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
53
by: Paul Rubin | last post by:
I've been approached about writing a Windows app which will need a really professional looking GUI. Forget TKinter, this has to actually look good (real artists will be available to get the visual...
0
by: Martin | last post by:
Hi, I have create a Graphics object from a HWND Both the Window and the Graphics object are created by the same thread, nevertheless when i dispose the object, I get an exception indicating that...
1
by: DBC User | last post by:
Hi Sharpies, This is a very basic question. I am using .Net IDE 2003 and System.Drawing.dll (1.1.4322). I wrote a simple program like this (ommitting the commons) using System.Drawing; .....
9
by: Jay | last post by:
Everywhere I go (read/browse) I see these parameters.... ByVal sender As Object, ByVal e As System.EventArgs Yet I never see them used within the function/method. Could someone tell me what they...
6
by: NvrBst | last post by:
Hello. I can pInvoke "GetDC" with NULL or "IntPtr.Zero" and get the hDC for the entire screen. I can use the hDC for stuff like "GetPixel" and it works fine. When I try to do the... ...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
1
by: Polaris | last post by:
Hi Experts: I'd like to be able to draw image outside my application. I know I can get a drawing surface for a form by using: Graphics g = Form.CreateGraphics Just wonder, if there is...
3
by: jaxx0rr | last post by:
This will probably look like a really stupid piece of code.. but it works My question is, how can I write the last part so there is only one extended Canvas class that can recieve a parameter for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...
0
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,...

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.