Jump to content
  • Advertisement
Sign in to follow this  
avianRR

[.net] get HDC from usercontrol object?

This topic is 3757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!