# HDC / NSView access and 3rd party libs

**URL:** <https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574>\
**Category:** General JUCE discussion\
**Created:** [March 19, 2014, 5:52pm UTC](https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574 "2014-03-19T17:52:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KoenTanghe](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/koentanghe/32/533_2.png) [@KoenTanghe](https://forum.juce.com/u/KoenTanghe)\
**Post date:** [March 19, 2014, 5:52pm UTC](https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574/1 "2014-03-19T17:52:02Z")

</div>

Hi,

assume you have a 3rd party&nbsp;graphics rendering library that asks for a&nbsp;Windows HDC or Mac NSView to draw on. The library states that it draws on that directly, and that on Windows you should call it's "drawPage"&nbsp;method while handling the WM\_PAINT message.

How would you setup this library with Juce so that it draws into&nbsp;a Component's graphics area?

I found there is a&nbsp;LowLevelGraphicsContext, and I suspect this might be the way to go, but I'm not sure it's really meant for this, or how to integrate it.

Any advice?

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 19, 2014, 9:16pm UTC](https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574/2 "2014-03-19T21:16:43Z")

</div>

You can get the NSView or HWND pretty easily with Component::getWindowHandle, but the HDC is a bit more complicated. As a cross-platform library I've never really attempted to open up all the internal platform-specific nasties, but if you can suggest a non-messy tweak that would make it possible to do what you're attempting, then I'll certainly consider it.

---

<div class="post-metadata">

**Author:** ![KoenTanghe](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/koentanghe/32/533_2.png) [@KoenTanghe](https://forum.juce.com/u/KoenTanghe)\
**Post date:** [March 23, 2014, 4:16pm UTC](https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574/3 "2014-03-23T16:16:42Z")

</div>

OK, thanks!

It's a music notation library for displaying musical scores ([http://www.music-software-development.com/music-notation-software-library.html](http://www.music-software-development.com/music-notation-software-library.html)) and this is what is stated about displaying the score:

> MNLDisplayPage(...)
> 
> This music notation software library function displays the given page of the score in page mode, from the specified open document.
> 
> For Windows, drawing is performed to the device context supplied by the graphic parameter. The graphic parameter is in fact a Windows HDC type (handle to a device context). The most obvious way to use this function is while handling the WM\_PAINT Windows message.
> 
> For Mac, the graphic parameter is in fact an NSView object or a sub-class of it. The most obvious place to use this function is in the implementation function of the NSView object.

From this I understood that that "graphic" input parameter is a HDC on Windows.

So I guess that since I can get the window handle with getWindowHandle as you say, I can simply call GetDC(HWND hWnd) on Windows to get the DC and hand that over. Unless that's going to cause all kinds of problems for some reasons?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 23, 2014, 4:22pm UTC](https://forum.juce.com/t/hdc-nsview-access-and-3rd-party-libs/12574/4 "2014-03-23T16:22:44Z")

</div>

It may or may not work, it's hard to guess what issues might arise when you start mixing&nbsp;3rd party code.
