10

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?

Justin Boo
  • 10,132
  • 8
  • 50
  • 71
Esse
  • 121
  • 1
  • 5

1 Answers1

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:.

一二三
  • 21,059
  • 11
  • 65
  • 74
  • 1
    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? – Garnik Aug 08 '13 at 16:14
  • 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**". – 一二三 Aug 10 '13 at 05:21
  • oops... missed that... need some other solution – Garnik Aug 22 '13 at 08:52
  • 1
    @Garnik did you find something ? – Amit Hooda May 28 '20 at 07:03
  • 1
    @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. Sorry – Garnik Jun 01 '20 at 11:04