简体   繁体   中英

Is there a way to programmatically hide an carbon application on osx?

I have a carbon C++ application and I would like to programmatically do the equivalent of Command-H (to hide the application) which is available in the Application menu for my app. I have explored the carbon API for TransitionWindow and HideWindow and while these can hide my window, they do not do the equivalent of Command-H. I looked into the AppleEvent reference on the offhand I needed to create an AppleEvent but I didn't see one for hide application. Any thoughts?

Sorry to answer my own question but the ShowHideProcess() API seems to do what I want. If there are better solutions I would love to hear them.

请注意:隐藏窗口与隐藏应用程序非常不同。

如果愿意,您也可以从Carbon事件管理器发送kHICommandHide('hide')命令事件(该菜单项的作用,并在处理后调用ShowHideProcess()),例如,如果您希望此操作被一个事件实现。

I looked into the AppleEvent reference on the offhand I needed to create an AppleEvent but I didn't see one for hide application. Any thoughts?

I'm no expert but you can just use AppleEvent to set the visible property of a process to false – at least it works with an AppleScript

tell application "System Events"
    set visible of process "xyz" to false
end tell

On the other hand, your API seems to be the most direct way and the above code probably just uses it as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM