How to get NSView* from HIViewRef?


#1

Hi All,
I have a HIViewRef handle from which I need to get a NSView* handle. I tried this code but it’s returning NULL :

NSView* view = HICocoaViewGetView(ref);

Any suggestions?

Thanks & Regards,
Dheeraj.


#2

Hi Dheeraj,
Which version of Macintosh OS and juce are you using?

Try doing this, am not sure whether this would help.

NSView *view = (NSView*) HICocoaViewGetView (ref);

#3

Did not work buddy. :slight_smile:
Thanks anyway. :slight_smile:


#4

Surprising, because I had used the following code sometime back and it had worked.

NSString *urlText = @"http://google.com"; 
WebView *webView = (WebView*) HICocoaViewGetView (hiView); 
if (webView != NULL)
   [[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];

#5

[quote=“vishvesh”]NSString *urlText = @“http://google.com”;
WebView webView = (WebView) HICocoaViewGetView (hiView);
if (webView != NULL)
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];[/quote]

I think you need to pass a Carbon view that serves as a wrapper for a Cocoa view to HICocoaViewGetView, but not HIViewRef itself.
I’m passing HIViewRef directly.


#6

Can you post more of your code? Especially were you get “ref”.


#7

Think I have an application window handle which is of type HIViewRef. I get this handle in an callback function :

void callback(HIViewRef ref)
{
NSView* view = (NSView*)HICocoaViewGetView(ref);
}

The view is NULL.

I want to create a NSView object using HIViewRef. Is it possible? Have you tried anytime?