Hello,
I read a recent discussion (see Set App to Front) about how to bring a Xojo application to the front and… I would like to do the exact opposite.
I need to take a screen shot. So I first hide the application window but I then need to bring the application which is behind my Xojo app to the front so that it gets activated.
I have tried to look for declares but could not implement one.
One solution was to force my application to be “hidden”, but I could not figure out how to go from the Apple Developer Manual (see Apple doc for hide function to a working Declare.
many thanks,
best,
Franck
OK. I understood how to do it so I answer to myself (a bit schizophrenic here…)
Method HideApp
//Hide the application
#if TargetCocoa
declare function NSClassFromString lib "Cocoa" ( inName as CFStringRef ) as Ptr
declare function sharedApplication lib "Cocoa" selector "sharedApplication" ( classRef as Ptr ) as Ptr
Dim myApp as Ptr = sharedApplication( NSClassFromString( "NSApplication" ) )
declare sub hide lib "Cocoa" Selector "hide:" (id as Ptr)
hide myApp
#endif
Use the same snippet using unhide: instead of hide: to show and activate the application
Method UnHideApp
//show the application
#if TargetCocoa
declare function NSClassFromString lib "Cocoa" ( inName as CFStringRef ) as Ptr
declare function sharedApplication lib "Cocoa" selector "sharedApplication" ( classRef as Ptr ) as Ptr
Dim myApp as Ptr = sharedApplication( NSClassFromString( "NSApplication" ) )
declare sub unhide lib "Cocoa" Selector "unhide:" (id as Ptr)
unhide myApp
#endif
I also posted it on Xippet (see xipppet)
1 Like