1

How to hide the active current NSWindow A and focus on the last other one B (one level behind the current window) and make it active?

I'm trying with this followed code but it does not work (B will become to front window but not active):

[_parentWindow orderBack:nil];
// Now i want to do some stuffs with last opened App (NSWindow) and it should be focused and activated now. 
[_parentWindow orderFront:nil];
Quang Nguyen
  • 354
  • 1
  • 5
  • 20

2 Answers2

-1

Try makeKeyAndOrderFront: instead.

[_window makeKeyAndOrderFront:nil];
bluedome
  • 2,449
  • 1
  • 22
  • 17
  • No, I mean the _parentWindow is now already key window (active) and i want to put it in to background so that i can do some stuffs with other app, which i don't have reference to it. How can i get the other app on focus? – Quang Nguyen Jan 26 '15 at 11:16
  • ok. this post may be your help. http://stackoverflow.com/questions/4036420/how-to-get-a-list-of-all-open-nswindow-from-all-running-application – bluedome Jan 26 '15 at 11:27
-1

Supplement to @bluedome response. You can get information about windows in the current user session:

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSDictionary* entry in (__bridge NSArray *)windowList) {
  NSString *ownerName = [entry objectForKey:(id)kCGWindowOwnerName];
  NSInteger ownerPID = [[entry objectForKey:(id)kCGWindowOwnerPID] integerValue];
  NSString *windowName = [entry objectForKey:(id)kCGWindowName];
  NSLog(@"%@:%ld, %@", ownerName, (long)ownerPID, windowName);
}
Sinisa Drpa
  • 887
  • 1
  • 5
  • 16
  • What i really want is how to make the window behind the displaying window actively as when you mouse click on it and without closing the _parentWindow – Quang Nguyen Jan 26 '15 at 13:41