[.net] get HDC from usercontrol object?

Started by
3 comments, last by avianRR 16 years, 1 month ago
I need to get the HDC of a System::Windows::Forms::UserControl object. All I've found so far is a Handle that's a IntPtr and won't work for the dll function I need to call.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
Advertisement
How about something like this:
using(Graphics g = this.CreateGraphics()){   IntPtr hdc = g.GetHdc();   // use it here...}

If it's in an OnPaint method, you don't need to do CreateGraphics(); you can just use the Graphics property of the PaintEventArgs object.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Actually what I need is a HDC. I need to pass the value to a function in a dll. It won't let me typecast the IntPtr to a HDC value.
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]
You should be able to cast it like so: (HDC)hdc.ToInt32()
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Ok, this is how I got it working.
HWND hWnd = (HWND)this->Handle.ToInt32();hDC = GetDC(hWnd);

Maybe someday I'll get the hang of this .NET stuff...
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement