4

I am porting an application over to Mac OS X. It uses FindWindow(). Here's the specific function:

FindWindow(NULL, "MyApplication")

However, that isn't going to work on Mac. Is there a similar function for Mac OS X or, even better, a universal function?

I am trying to use it in "the application's main window" from this function.

Pon-3
  • 133
  • 1
  • 11
  • see http://stackoverflow.com/questions/4036420/how-to-get-a-list-of-all-open-nswindow-from-all-running-application – Daij-Djan Nov 28 '12 at 23:15
  • @Daij-Djan I am not trying to find a list of windows. Just a specific open window. – Pon-3 Nov 28 '12 at 23:17
  • what are you using for your gui/application mac? – pyCthon Nov 28 '12 at 23:20
  • @pyCthon 2 I am using OpenGL. – Pon-3 Nov 28 '12 at 23:23
  • 1
    I think pyCthon was asking about an application framework, such as Cocoa. OpenGL is not an application framework, as it has no windowing functions. – JWWalker Nov 29 '12 at 02:27
  • @JWWalker C++ if thats what you mean – Pon-3 Nov 29 '12 at 02:42
  • 1
    Nope, C++ is a language. It doesn't provide any interface to the OS windowing functions either. How does your app create any windows? – JWWalker Nov 29 '12 at 02:48
  • @JWWalker I'm faced the same issue as topic-starter. I'm using pure C++ with Qt. Is there some way to solve task without monstrous bindings of C++ with Objective C? – UndeadDragon Feb 15 '17 at 17:51
  • @UndeadDragon, if you want to pass a window to a Qt function, what data type does it expect, `WindowRef`, `NSWindow*`, `CGWindowID`, or what? – JWWalker Feb 16 '17 at 16:02
  • @JWWalker No-no, I just need to grab screenshot by title of window. On Windows it is easy, I need the same on Mac but I'm totally disappointed in Mac technologies. What will be the easiest way to do that? – UndeadDragon Feb 16 '17 at 17:21
  • @UndeadDragon, do you already know the title of the window that you want a screen shot of, or do you want to find the title of the main window? Maybe you should post your own question with details of what you want and what you have to work with. – JWWalker Feb 18 '17 at 04:22
  • @JWWalker I know exactly the title and that title is unique. I can't post new questions :) – UndeadDragon Feb 18 '17 at 08:51
  • @UndeadDragon, you can use `CGWindowListCreateImage` to get a screen shot of a window, but I don't think you'll be able to get a window title without using Cocoa APIs. – JWWalker Feb 18 '17 at 18:48

1 Answers1

0

there is no easy one shot function like this

You can do it via the CGWindow API like in the article. How to get a list of all open NSWindow from all running application?. It can be used to find a list or just one window.

Just take the sample code that lists and modify it to filter this for you so you only have the one window you want :)

Community
  • 1
  • 1
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135