Jump to content

Minimize program on focus loss - (Locked)


Recommended Posts

I have found a script that will minimize the currently focused window when a hotkey is pressed, but I don't know AutiIt very well.

I'm thinking of a loop checking if an exe has focus or not, and if it's minimized or not.  If it's not focused and not minimized, I want to send a command to minimize it.  Can anyone advise the right commands to lookup for that kind of thing?

Func _MinimizeActive()
    Local $v_Wnd, $w_Wnd ;declare variables
    $v_Wnd = _WinAPI_GetFocus() ;get focused window
    $w_Wnd = WinGetHandle($v_Wnd) ;get handle of focused window
    WinSetState($w_Wnd,"",@SW_MINIMIZE) ;minimize focused window
EndFunc

Link to comment
Share on other sites

1 hour ago, Earthshine said:

snip... is this so you can hide your gaming from your boss or something?

I would never inappropriately use work resources and time!  Especially not time I have free because I'm good at my job.

Link to comment
Share on other sites

good to know. if you look at the help file included with AutoIt or online help you will see all kinds of built in Windows functions to use

also, you can auto minimize everything on your desktop with a windows key shortcut

 

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Developers
1 hour ago, Earthshine said:

snip... is this so you can hide your gaming from your boss or something?

How do you say in English: "It takes one to know one" ?  ;) 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

1 hour ago, Earthshine said:

good to know. if you look at the help file included with AutoIt or online help you will see all kinds of built in Windows functions to use

also, you can auto minimize everything on your desktop with a windows key shortcut

 

Yeah the shortcut key is what I use now, but I have gotten use to one program that has this behavior built in(Factorio), and I want to add it to others.

I have found WinWaitNotActive in the help file, which solved one of the problems.  I can use WinActive to look for the window on a delay loop, then on another loop check if it's not active? Then other loop check if it's not minimized?  Then use WinSetState to minimize it.

When it says it returns the handle, thats the parameter to pass to WinSetState right(hWnd)? 

 

Link to comment
Share on other sites

just use WinExists to find windows, then see what their state is. Read the helpfile more.

https://www.autoitscript.com/autoit3/docs/functions/WinExists.htm

https://www.autoitscript.com/autoit3/docs/functions/WinSetState.htm

notice the helpfile information regarding the paramerters, you can pass title, handle or class of the window

Parameters

title The title/hWnd/class of the window to change the state. See Title special definition.
text The text of the window to change the state. See Text special definition.
flag The "show" flag of the executed program:
    @SW_HIDE = Hide window
    @SW_SHOW = Shows a previously hidden window
    @SW_MINIMIZE = Minimize window
    @SW_MAXIMIZE = Maximize window
    @SW_RESTORE = Undoes a window minimization or maximization
    @SW_DISABLE = Disables the window
    @SW_ENABLE = Enables the window

 

use the helpfile and run the samples in it to learn how to use each function.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

Here something you can build on :

#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>

HotKeySet ("{ESC}","_Exit")

WinMinimizeAll()
Sleep (500)
Const $hDesktop = _WinAPI_GetForegroundWindow ()
Local $hWinPrec = $hDesktop

While True
  Sleep (100)
  $hWin = _WinAPI_GetForegroundWindow ()
  If $hWin = $hWinPrec Then ContinueLoop
  ConsoleWrite ($hWin & "/" & $hWinPrec & @CRLF)
  If $hWinPrec And $hWinPrec <> $hDesktop And WinGetTitle ($hWinPrec) <> "" And Not BitAnd(WinGetState ($hWinPrec), $WIN_STATE_MINIMIZED) Then
    ConsoleWrite ("Minimizing " & $hWinPrec & @CRLF)
    WinSetState ($hWinPrec, "", @SW_MINIMIZE)
  EndIf
  $hWinPrec = $hWin
WEnd

Func _Exit ()
  Exit
EndFunc

It is not perfect, if you play with window's task bar, it will get somewhat defective. 

Link to comment
Share on other sites

I did this and it seems to work, but it seems to have an error sometimes with a flashing X on the icon.  Where do I get the log to figure out the error?

While 1 ;loop to keep alive
   WinWaitNotActive("[CLASS:HaemimontGamesWindowClass]")
   WinSetState("[CLASS:HaemimontGamesWindowClass]", "", @SW_MINIMIZE)
   WinWaitActive("[CLASS:HaemimontGamesWindowClass]")
WEnd

 

Link to comment
Share on other sites

  • Moderators

Welcome to the AutoIt forum.

Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked.

See you soon with a legitimate question I hope.

The Moderation team

 

Edit: To other forum members, earlier in the thread perhaps you should have pointed to the forum rules if you had suspicions, a simple - "Check out the forum rules, make sure you're adhering to them". We may have gotten to this point a whole lot more quickly.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...