Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:53:53+00:00 2026-05-28T00:53:53+00:00

I have a library that draw on to given HDC using GDI+ apis. I

  • 0

I have a library that draw on to given HDC using GDI+ apis.
I want to use that in a WPF application. I did try getting the handle from WindowInteropHelper class and passing it to the library method which does the drawing. However it fails simply because it cannot create Gdi+ Graphics from that handle.

I then tried using a WinForm element in WindowsFormsHost control and using the HDC available in WinForm control’s paint event and it did work fine.
What I want to know is can the same thing be made to work directly on WPF control\window?
Is there some other way to get the HDC from WPF elements on which GDI draw apis can be used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:53:53+00:00Added an answer on May 28, 2026 at 12:53 am

    If you have the window handle (HWND) of your WPF window, presumably obtained using the WindowInteropHelper class, then you can easily obtain a handle to a device context (HDC) for that window.

    There are two ways of getting at it, although both ultimately do the same thing. The first is to P/Invoke the necessary GDI+ API functions, but we can rule that out pretty quickly as being unnecessarily time consuming. Remember that the .NET Framework already wraps all this stuff for WinForms development in the System.Drawing namespace, and in particular, the Graphics class. So all you need to do is add a reference to System.Drawing to your WPF application, and you’ll get all of this wrapped functionality for free.

    The part you’re interested in is the Graphics.FromHwnd method, which creates a new Graphics object from the specified window handle (HWND).

    Once you’ve got that, you can obtain a handle to a device context (HDC) by calling the Graphics.GetHdc method, which returns exactly what you’re after—an IntPtr value that represents a handle to a device context.

    Remember that you’ll need to call the Dispose method on your Graphics object after you’re finished with it in order to release its associated resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I have a library that use across different websites/ applications I've always just
I have a shared library that I wish to link an executable against using
I have 2 different layout files that I want to use for modifying the
I have a tracking application and uses osmdroid library. My prolbem is that osmrdroid
I have a library that I would like to license and distribute. I know
I have a library that interacts with our phone system, ie, Hey phone, call
I have a library that does I/O. There are a couple of external knobs
I have a library that I created with some business logic that includes writing
Common scenario: I have a library that uses other libraries. For example, a math
I have a C++ library that provides various classes for managing data. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.