FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

How to set focus to a program?

 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows
View previous topic :: View next topic  
Author Message
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Sun Feb 04, 2007 10:09 pm    Post subject: How to set focus to a program? Reply with quote

I would like some code to set focus to a program. F.eks. sometimes when i run a program from my phone, it isn't in the front, but I want it to be.
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Sun Feb 04, 2007 11:50 pm    Post subject: Re: How to set focus to a program? Reply with quote

try this:

tell application "xxx" to activate

- Jonas

[quote="Runarius"]I would like some code to set focus to a program. F.eks. sometimes when i run a program from my phone, it isn't in the front, but I want it to be.[/quote]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Mon Feb 05, 2007 5:52 pm    Post subject: Reply with quote

??? when I try that code it does nothing... actually, I can't open my script then.

[code:1]
tell application "MediaPortal.exe" to activate
[/code:1]
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Mon Feb 05, 2007 6:14 pm    Post subject: Reply with quote

Sorry. I mistook your question as being about the Mac. My mistake.

On Windows, you can do something along these lines:

var windowHandle = FindWindow( "windowClass", "windowName" );
if( windowHandle != 0 ) ActivateWindow( windowHandle );

For BSPlayer, for instance, it goes like this:

var windowHandle = FindWindow( "windowClass", "" );
if( windowHandle != 0 ) ActivateWindow( windowHandle );

(windowName is ignored in this case, as the passed in string is empty; this is what we want)

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Mon Feb 05, 2007 10:23 pm    Post subject: Reply with quote

Hmmm... I feel really stupid now but I don't know how to find the windowclass... I got the code to work with Notepad and some folders, but when I tried it with MediaPortal, nothing happened.

[code:1]var windowHandle = FindWindow( "MediaPortal", "" );
ShowMessage( windowHandle )
if( windowHandle != 0 ) ActivateWindow( windowHandle );[/code:1]

returns 0 ofcourse... What should I write instead of MediaPortal? Where can I find this information?

EDIT:

Never mind, I think I got it:

[code:1]var windowHandle = FindWindow( "WindowsForms10.Window.8.app.0.3ce0bb8", "" );
if( windowHandle != 0 ) ActivateWindow( windowHandle ); [/code:1]

isn't that a bit odd for a classname? Guess it is becouse mediaPortal isn't finished yet. Anyways, it works great:D thanks:D
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Tue Feb 06, 2007 1:06 am    Post subject: Reply with quote

Glad to hear you found it. Beware that they might change the class name in the future; hopefully not, but there's a risk. Either way, the class name may (or may not) be more stable that the window name (title/caption).

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Tue Feb 06, 2007 5:03 pm    Post subject: Reply with quote

yes, the window title is useless, since in media portal, it changes depending on what I am doing in the program. But everything is working a 100% with the class name, so I'll stick to it, even if it may change in future versions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group