HDC / NSView access and 3rd party libs



assume you have a 3rd party graphics rendering library that asks for a 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" method while handling the WM_PAINT message.

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

I found there is a 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?



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.


OK, thanks!

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


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?


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