lukaskollmer / objc

🔮 NodeJS ↔ Objective-C bridge (experimental)
MIT License
98 stars 20 forks source link

how convert nativeWindowHandle to NSView #16

Open xingyibiao opened 5 years ago

xingyibiao commented 5 years ago

I want to convert nativeWindowHandle to NSView, like

const myView = win.getNativeWindowHandle()
$.myFramework.setView(myView)

any suggestion?

lukaskollmer commented 5 years ago

where are you getting the native window handle from?

xingyibiao commented 5 years ago

I use electron

lukaskollmer commented 5 years ago

have you tried objc.wrap?

const viewObject = objc.wrap(win.getNativeWindowHandle());
xingyibiao commented 5 years ago

I have tried, but objc can not receive NSView, It will be Buffer? not NSView?

ImpossibleReality commented 2 years ago

I know this is two years later, but any updates on this? It would be nice if I could use this library with electron to do some simple operations on NSWindow. If i try to run let nativeWindow = objc.wrap(screenshotWindow.getNativeWindowHandle()) objc spits out the ambiguous error: Attempt to use unknown class 0x7fd84748ea30.

nornagon commented 2 years ago

Came here because I was also trying to figure this out and Google lead me here. I did end up figuring it out: you need to call .readPointer() on the buffer returned from getNativeWindowHandle(), e.g.

const handle = mainWindow.getNativeWindowHandle().readPointer()
const nsview = objc.wrap(handle)
nsview.window().invalidateShadow()
Lijian1122 commented 2 years ago
wrap

Have you resolve this problem? thanks

Lijian1122 commented 2 years ago

Have you resolve this problem? thanks

readPointer

when I run the programe, it show error: readPointer is not a function