Get NSWindow from kCGWindowNumber
Asked Answered
B

1

11

From kCGWindowNumber, how do I get NSWindow ref. I tried using:

[NSApp windowWithWindowNumber:windowNumber]

but I always get a null value. I need to get the NSWindow to apply [window setlevel:NSFloatingWindowLevel], that I have set the always on top of a given window. Does anyone know how to solve this problem or has any alternative solution?


Thanks for the answer, but this is not the solution, I had already tried but it does not work, actually I did a test , I tried the following code:

for (NSInteger i = 0; i <10000; i + +) {
NSWindow * wind;
wind = [NSApp windowWithWindowNumber: windowNumber];
NSLog (@ "\ n Window:% @", wind);
}

but the result is always the Window: (null)

I have a list of window, where can i get OwnerPid Number of window ecc.. ecc... and now I need to set the always on top of some windows.

The Always on top is possible set whit: [window setlevel:NSFloatingWindowLevel], window is a NSwindow object, it's real?

Do you have a solution? or another idea , for my problem?

Brennabrennan answered 28/9, 2011 at 17:16 Comment(1)
Where are you getting the window number from?Mountaineer
A
2

kCGWindowNumber is a CFNumber/NSNumber, -windowWithWindowNumber: expects an NSInteger. You'll need to extract the integer out of the window number reference (with -integerValue) before passing it to -windowWithWindowNumber:.

Astred answered 29/9, 2011 at 10:16 Comment(5)
This works only for windows that belong to the application which call it. But for others [NSApp windowWithWindowNumber:[[[NSWindow windowNumbersWithOptions:NSWindowNumberListAllApplications] objectAtIndex:i] integerValue]]; returns nil. Why?Bilabial
The documentation for windowWithWindowNumber: says: "may return nil for window numbers found using windowNumbersWithOptions: if there is no corresponding window object owned by your app".Edric
oops... missed that... need some other solutionBilabial
@Bilabial did you find something ?Oscilloscope
@AmitHooda I am sorry, this was 8 years ago and unfortunately I don't work there anymore. Eventually I even don't remember how I solved that issue. SorryBilabial

© 2022 - 2024 — McMap. All rights reserved.