(Is there a time limit on editing posts? I wanted to add the script to my post above and fix my typo ('it foobar' should be 'it') but I don't see an Edit button anymore)
Here is an updated version of the script. Took me a bit longer than I expected because I accidentally found out a huge oversight of mine: the classname of the main window changes depending on the interface you are using. So I had to devise an alternate method to figure that out. I also did some other improvements: no more need for WinAPIEx, you can have the script start foobar2000 for you (it will properly pass on command line parameters, so replacing your shortcuts/file associations to the compiled script over foobar2000.exe should work) and close itself when it's gone, it should detect the main window more reliably, and it will not spawn repeated instances of itself (it will still properly run your foobar command line).
(sorry for the long code below, there are no attachments and I'd rather not use a hosting service now that it's all contained in a single file)
#include <WinAPI.au3>
#include <Misc.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
; ============================================================================;
; Changing this to True will make the script start foobar200 itself, and exit when it closes.
; Otherwise the script will stay running indefinitely, monitoring for foobar2000 whenever it starts.
Global Const $startFoobar2000 = True
Global $pidFoobar2000 = 0
Global $wndFoobar2000 = 0
Global $wndSavedPosition
Global Const $FullscreenRect[2] = [ _
_WinAPI_GetSystemMetrics($SM_CXSCREEN), _
_WinAPI_GetSystemMetrics($SM_CYSCREEN) _
]
Func ToggleFullscreen()
Global $wndFoobar2000, $wndSavedPosition
Local Const $stylesToRemove = BitOR($WS_CAPTION, $WS_BORDER, $WS_SIZEBOX)
If Not WinExists($wndFoobar2000) Then Return
Local $wndStyle = _WinAPI_GetWindowLong($wndFoobar2000, $GWL_STYLE)
If @error Then Return
If BitAND($wndStyle, $stylesToRemove) <> 0 Then
$wndSavedPosition = WinGetPos($wndFoobar2000)
$wndStyle = BitAND($wndStyle, BitNOT($stylesToRemove))
_WinAPI_SetWindowLong($wndFoobar2000, $GWL_STYLE, $wndStyle)
_WinAPI_SetWindowPos($wndFoobar2000, $HWND_TOPMOST, _
0, 0, _
0, 0, _
BitOR($SWP_NOCOPYBITS, $SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
_WinAPI_SetWindowPos($wndFoobar2000, 0, _
0, 0, _
$FullscreenRect[0], $FullscreenRect[1], _
BitOR($SWP_NOCOPYBITS, $SWP_FRAMECHANGED, $SWP_NOZORDER))
Else
$wndStyle = BitOR($wndStyle, $stylesToRemove)
_WinAPI_SetWindowLong($wndFoobar2000, $GWL_STYLE, $wndStyle)
_WinAPI_SetWindowPos($wndFoobar2000, $HWND_NOTOPMOST, _
0, 0, _
0, 0, _
BitOR($SWP_NOCOPYBITS, $SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
If UBound($wndSavedPosition, 1) >= 4 Then
_WinAPI_SetWindowPos($wndFoobar2000, 0, _
$wndSavedPosition[0], $wndSavedPosition[1], _
$wndSavedPosition[2], $wndSavedPosition[3], _
BitOR($SWP_NOCOPYBITS, $SWP_FRAMECHANGED, $SWP_NOZORDER))
EndIf
EndIf
EndFunc
Func GetFoobar2000Window()
Local $allWindows = _WinAPI_EnumWindowsTop()
If @error Then Return 0
Local $wndAlt = 0
For $i=1 To $allWindows[0][0]
Local $hwnd = $allWindows[$i][0], $pidWindow
If _WinAPI_GetWindowThreadProcessId($hWnd, $pidWindow) And $pidWindow == $pidFoobar2000 Then
; This is a hackish way to try and detect foobar2000's main window.
; It should have a maximize button, or at least the corresponding style!
If(BitAND(_WinAPI_GetWindowLong($hwnd, $GWL_STYLE), $WS_MAXIMIZEBOX)) Then
Return $hWnd
ElseIf Not $wndAlt And StringInStr(_WinAPI_GetWindowText($hWnd), "foobar2000") Then
$wndAlt = $hWnd
EndIf
EndIf
Next
; No window found with the semi-reliable method. Just return one with 'foobar2000' in the title.
Return $wndAlt
EndFunc
If $startFoobar2000 Then
$pidFoobar2000 = Run(StringFormat('"%s/%s" %s', @ScriptDir, "foobar2000.exe", _Iif(@Compiled,$CmdLineRaw,"")))
If @error Then
MsgBox($MB_ICONHAND, "foobar2000 Full-screen", "Error: failed to start foobar2000.exe. Make sure this script is placed in foobar2000's folder.")
Exit 1
EndIf
If _Singleton("foobar2000_fullscreen", 1) == 0 Then
Exit 1
EndIf
Do
Sleep(500)
$wndFoobar2000 = GetFoobar2000Window()
If $wndFoobar2000 Then ExitLoop
Until Not ProcessExists($pidFoobar2000)
If Not $wndFoobar2000 Then
Exit 1
EndIf
ElseIf _Singleton("foobar2000_fullscreen", 1) == 0 Then
Exit 1
Else
$pidFoobar2000 = ProcessWait("foobar2000.exe")
EndIf
HotKeySet("^!+g","ToggleFullscreen")
While True
If Not WinExists($wndFoobar2000) Then
$wndFoobar2000 = GetFoobar2000Window()
If Not $wndFoobar2000 Then
If $startFoobar2000 Then
Exit
Else
Sleep(1000)
EndIf
EndIf
EndIf
Sleep(200)
WEnd