Jump to content
Sign in to follow this  
PvS1

window focus

Recommended Posts

PvS1

Hi All,

I wrote an AutoIT script that repeatedly invokes a commandline program through the use of RunWait().

Everything works fine with one exception: If this script is in the background while I am doing something else (like e.g. browsing the Web, entering this question) each time a new commandline program is started it steels focus.

What I would like to do is modify my AutoIT script such that It determines whether it has focus (using WinGetTitle("[active]")) and invokes the commandline program accordingly (AutoIT has focus -> commandline program gets focus, AutoIT does not have focus -> commandline program does not get focus.

Anybody any ideas on how to do this? The only thing I could come up with is in case of no focus: start the commandline program in a hidden or minimised window (RunWait option). This however has the drawback that I can no longer see progress.

Regards,

PvS

Edited by PvS1

Share this post


Link to post
Share on other sites
water

It's a bit hard to suggest a solution without seeing the code you have so far.

Can you post what you have coded?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
PvS1

There is a "show_flag" parameter for run functions that should do what you need.

I know there is a show_flag parameter, that however allows me to either minimize/maximize/hide only, not start normally just without focus. This is also the option I referred to in my initial submission: start the commandline program in a hidden or minimised window (RunWait option). This however has the drawback that I can no longer see progress.

Here is the piece of my source code that invokes the command line program:

Func RunLame($FileName,$ReCode,$CmdOpt,$Decode)

Local $Drive, $Dir, $FName, $Ext, $tSrc, $tDst, $SrcExt, $DstExt

If $Decode=$GUI_UNCHECKED Then

$SrcExt=".WAV"

$DstExt=".MP3"

Else

$SrcExt=".MP3"

$DstExt=".WAV"

EndIf

_PathSplit($FileName, $Drive,$Dir,$FName,$Ext)

; Check if output file already created

$tDst=FileGetTime($Drive&$Dir&$FName&$DstExt,0,1)

If $ReCode=$GUI_UNCHECKED And Not @error Then

$tSrc=FileGetTime($FileName,0,1)

if $Decode=$GUI_CHECKED Or $tDst>$tSrc Then

GUICtrlSetData($ProcessingList,"Skipped: "&$FileName)

GUICtrlSendMsg($ProcessingList,$WM_VSCROLL,$SB_LINEDOWN,0)

Return

EndIf

EndIf

GUICtrlSetData($ProcessingList,"Processing: "&$FileName)

GUICtrlSendMsg($ProcessingList,$WM_VSCROLL,$SB_LINEDOWN,0)

If $Decode=$GUI_UNCHECKED Then

$cmd=$LameCmd&' '&$CmdOpt&' "'&$FName&$Ext&'"'

Else

$cmd=$LameCmd&' --decode "'&$FName&$Ext&'"'

EndIf

RunWait($cmd,$Drive&$Dir)

If @error Then ; Error running Lame

MsgBox(4096, "Error running Lame", "cmd='"&$cmd&"', Default directory='"&$Drive&$Dir&"'")

Exit

EndIf

EndFunc

Share this post


Link to post
Share on other sites
BrewManNH

You missed a couple of the show flags, there's

@SW_SHOWMINNOACTIVE Displays the window as a minimized window. This value is similar to @SW_SHOWMINIMIZED, except the window is not activated.

and

@SW_SHOWNOACTIVATE Displays a window in its most recent size and position. This value is similar to @SW_SHOWNORMAL, except the window is not activated.

These might be useful to do what you're hoping to accomplish.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
PvS1

You are right, I tested both and they work as their name suggests.

Neither of them do what I intend to accomplish. I think I was on the wrong track / using the wrong windows terminology (active).

It seems like active does not mean on top and therefor visible. A not activated window that is not minimised will overlay the previously active window.

Concrete example: When editing a file with e.g. MS-Word and such a window pops up it will make MS-Word become covered by the new window, active or not.

So how can I start a non minimised window that will be below and not interfere with the current active window?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×