简体   繁体   中英

What does IntPtr.Zero mean in System.Drawing.Graphics

I need to get the exact meaning of IntPtr.Zero in below function. I used this function for convert word document text range position pixel value to WPF unit value.

Graphics g = Graphics.FromHwnd(IntPtr.Zero)

That normally said to pass the handle,but I didn't get it.

Graphics.FromHwnd method is used to create a Graphics object from the specified handler of a window.

When you pass IntPtr.Zero as parameter you are creating a Graphics from the windows desktop that allow you draw directly in the screen.

IntPtr is a platform specific way to represent a handle or pointer. On 32 bit systems a pointer is 32 bits wide, whilst on a 64 bit system it is 64 bits wide. This type exists to hide these differences from you.

IntPtr.Zero represents a handle or pointer whose values is 0 (essentially null). You can use it in places where the API expects a Windows API style handle, such as in the FromHwnd call in your example. In the Windows API a HWND is a window handle, where null indicates "no window". To pass this via C# you use IntPtr.Zero .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM