Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Jun 22, 2018 7:41 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Bringing App to Front
PostPosted: Fri Oct 22, 2010 8:06 am 
Offline

Joined: Fri Apr 21, 2006 7:11 pm
Posts: 73
Location: Cincinnati, OH
How can I make sure my application is at the front? I have a situation where a business card is scanned and the scanning software comes to the front while scanning. When it's finished, I want my application to come to the front. I know when it's finished scanning because I look for the file it creates.

Thanks!
Floyd


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Fri Oct 22, 2010 8:13 am 
Offline
User avatar

Joined: Wed Nov 15, 2006 3:50 pm
Posts: 2353
Location: England
self.show ought to do it.
Quote:
I know when it's finished scanning because I look for the file it creates


Pinch of salt there. What if the final file is supposed to be 1Gb and you find it while it is only 880Kb in size?


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Fri Oct 22, 2010 10:23 am 
Offline

Joined: Fri Apr 21, 2006 7:11 pm
Posts: 73
Location: Cincinnati, OH
Self.show. Why didn't I think of that! As for the file size, these are business card scans which are really small JPEGs and don't get dumped until the scan is complete. But thanks for the "pinch of salt"!

Take care,
Floyd


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Thu Oct 28, 2010 7:29 pm 
Offline

Joined: Wed Oct 05, 2005 12:42 am
Posts: 63
macmage wrote:
Self.show. Why didn't I think of that! As for the file size, these are business card scans which are really small JPEGs and don't get dumped until the scan is complete. But thanks for the "pinch of salt"!

Take care,
Floyd


self.show will only bring a window to the very front if your application is the current application. Otherwise it will simply bring that window to the front of your application, but will not be focus to your application. We use an apple script to activate the app as we haven't found a better way of getting our app to activate on the system and come to the front of all applications.


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Oct 30, 2010 4:21 am 
Offline

Joined: Sun Mar 26, 2006 11:02 am
Posts: 85
I use this handy routine in all my apps:
Sub BringAllToFront()
Dim psn As MemoryBlock

Declare Function GetFrontProcess Lib "Carbon" (PSN as Ptr) as Integer
Declare Function SetFrontProcess Lib "Carbon" (PSN as Ptr) as Integer

psn = NewMemoryBlock(4)

if GetFrontProcess(psn) = 0 then
Call SetFrontProcess(psn)
end if

End Sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Oct 30, 2010 6:37 pm 
Offline

Joined: Thu Oct 05, 2006 11:45 pm
Posts: 1002
Location: Sol:Planet Earth:North America:California
I couldn't get this to work on 10.6.4, not sure about other OS X versions. If I check the result of the call it is 0 which should indicate that it worked but it doesn't bring my app to the front if another app has the focus.

I will have to dig through my code to find the app that has this feature because I don't remember what I used in it. I may have used the AppleScript approach.

One thing that does work is this one liner that I think came from someone on the NUG years ago:

app.ExecutableFile.Launch

No declares or AS needed.

_________________
This message made with 100% recycled pixels.
MacBook CD2.0/2GB/OSX 10.6.8 / REAL Studio 2010R1 Pro


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Dec 01, 2012 2:12 pm 
Offline

Joined: Mon Oct 09, 2006 9:05 am
Posts: 145
PSmith wrote:
I use this handy routine in all my apps:
Sub BringAllToFront()
Dim psn As MemoryBlock

Declare Function GetFrontProcess Lib "Carbon" (PSN as Ptr) as Integer
Declare Function SetFrontProcess Lib "Carbon" (PSN as Ptr) as Integer

psn = NewMemoryBlock(4)

if GetFrontProcess(psn) = 0 then
Call SetFrontProcess(psn)
end if

End Sub


Is there a similar COCOA_Declare to bring the application to the front?


Thanks in advance.

_________________
Working system: Mac OS X 10.6.x
_________________________________
Note : I am not interested in any solutions that need custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Dec 01, 2012 2:49 pm 
Offline

Joined: Sun Feb 28, 2010 4:14 am
Posts: 37
This seems to be working:

Dim psn As MemoryBlock

Declare Function GetCurrentProcess Lib "Carbon" (PSN as Ptr) as Integer
Declare Function SetFrontProcess Lib "Carbon" (PSN as Ptr) as Integer

psn = NewMemoryBlock(4)

if GetCurrentProcess(psn) = 0 then
Call SetFrontProcess(psn)
end if


I use this code in one of my projects:

Dim p as ProcessMBS
p=new ProcessMBS
p.GetCurrentProcess
p.SetFrontProcessWithOptions 1


...but it requires MBS Plugins.

You may also use the following AppleScript:

on run
activate
end run


All three methods work in Cocoa applications.


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Dec 01, 2012 3:04 pm 
Offline

Joined: Mon Oct 09, 2006 9:05 am
Posts: 145
Thank you gre for your post.

But I'm looking only for a similar native COCOA_Declare to bring the application to the front.

Does someone know a COCOA-Declare?

_________________
Working system: Mac OS X 10.6.x
_________________________________
Note : I am not interested in any solutions that need custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Dec 01, 2012 7:02 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
The first snippet is a Cocoa declare

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sat Dec 01, 2012 7:24 pm 
Offline

Joined: Mon Oct 09, 2006 9:05 am
Posts: 145
Thank you shaosean.

shaosean wrote:
The first snippet is a Cocoa declare


Cocoa declare with carbon lib?

_________________
Working system: Mac OS X 10.6.x
_________________________________
Note : I am not interested in any solutions that need custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Sun Dec 02, 2012 1:28 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
You can call Carbon from Cocoa.. That snippet works fine in a Cocoa build.. If you want a fully Cocoa version, it will only work on 10.6 or greater and you will need to convert this code to declares..

NSArray* apps = [NSRunningApplication
runningApplicationsWithBundleIdentifier:@"com.bla.blah"];
[(NSRunningApplication*)[apps objectAtIndex:0]
activateWithOptions: NSApplicationActivateAllWindows];

_________________
Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: Bringing App to Front
PostPosted: Mon Dec 03, 2012 2:03 pm 
Offline

Joined: Thu Nov 25, 2010 9:35 am
Posts: 36
Location: France
Using MBS Plugins, do this :
app.FrontmostMBS = True

_________________
RS under Lion... OS Lion, MacBook Air 13" and Mini Server OS Lion Server.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group