Jump to content

HideCaption


TurionAltec
 Share

Recommended Posts

HideCaption 0.9

Created by TurionAltec

hidecaption.zip

HideCaption allows toggling the visibility of Window Caption (title) bars using hotkeys

-ToggleCaption (default:Win+q) will toggle the caption on the active window

-FullScreen (default: Win+Alt+q) will force a window maximized with no caption, hiding the task bar (if it exists). Pressing the combination again will return the window to a 'Restored' state with a visible caption bar.

The hotkeys can be customized in the hidecaption.ini file which will be autogenerated in the script location

To move a window with a hidden caption bar, activate the system menu (Alt+space) or use the utility AltMove:

http://www.deskex.com/Altmove/

This program uses the _TargetStyle function of the ANYGUI library to change the state of the caption bar.

http://www.autoitscript.com/forum/index.php?showtopic=9517&view=findpost&p=638738

I was inspired to write this program due to the limited space on the screen of my 701 EeePC (800x480 resolution), and this allows freeing up 20 or so pixels from the top of each window. Full screen mode allows any application to run full screen. Some applications (like Word) have a full screen mode, but it hides all the toolbars. This allows me to keep the toolbars visible, but free up space from the titlebar and the caption bar. Don't want the taskbar hidden? Simple. Maximize the window like normal, then use the Toggle caption hotkey instead.

Screenshots

Here's some screenshots demonstrating HideCaption

Non-maximized windows before

Non-maximized windows after:

Maximized window with caption bar

Full screen without caption bar

Notice how 3 additional lines are now visible in Word!

Code snippets

Here's some pieces of code of interest:

;WS_popup = 0x00C00000

Func TC() ;Toggle Caption
    $xh = WinGetHandle("")
    _TargetStyle("toggle", 1, 0x00C00000, -1, $xh)
EndFunc   ;==>TC

Func Fullscreen()
    $xh = WinGetHandle("")
    $currentstate = _TargetStyle("", 1, $ws_popup, -1, $xh)
    $caption = BitAND($currentstate[0], 0x00C00000) ;Check if Caption set
    If Not $caption And BitAND(WinGetState($xh), 32) Then ;If caption not visible and window maximized, restore
        WinSetState($xh, "", @SW_RESTORE)
        _TargetStyle("toggle", 1, 0x00C00000, -1, $xh)
    Else
        WinSetState($xh, "", @SW_RESTORE)
        _TargetStyle("unset", 1, 0x00C00000, -1, $xh)
        WinSetState($xh, "", @SW_MAXIMIZE)
    EndIf
EndFunc   ;==>Fullscreen

Full code:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compression=4
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;hidecaption2
#include <WindowsConstants.au3>
#include <Constants.au3>
Global Const $inifile = @ScriptDir & "\hidecaption.ini"
Global $toggleHK = "#q"
Global $FullscreenHK = "#!q"

Opt("TrayMenuMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
TraySetToolTip("HideCaption 0.9")
$aboutitem = TrayCreateItem("&About")
TrayItemSetOnEvent($aboutitem, "TrayAbout")
$modifyitem = TrayCreateItem("&Modify Configuration")
TrayItemSetOnEvent($modifyitem, "ModifyConf")
$reloaditem = TrayCreateItem("&Reload Configuration")
TrayItemSetOnEvent($reloaditem, "LoadConf")
$Exititem = TrayCreateItem("E&xit")
TrayItemSetOnEvent($Exititem, "QuitProgram")

LoadConf()
While 1
    Sleep(10000) ;Main program Idle Loop
WEnd

Func ModifyConf()
    ShellExecute($inifile)
EndFunc   ;==>ModifyConf

Func TC() ;Toggle Caption
    $xh = WinGetHandle("")
    _TargetStyle("toggle", 1, 0x00C00000, -1, $xh)
EndFunc   ;==>TC

Func Fullscreen()
    $xh = WinGetHandle("")
    $currentstate = _TargetStyle("", 1, $ws_popup, -1, $xh)
    $caption = BitAND($currentstate[0], 0x00C00000) ;Check if Caption set
    If Not $caption And BitAND(WinGetState($xh), 32) Then ;If caption not visible and window maximized, restore
        WinSetState($xh, "", @SW_RESTORE)
        _TargetStyle("toggle", 1, 0x00C00000, -1, $xh)
    Else
        WinSetState($xh, "", @SW_RESTORE)
        _TargetStyle("unset", 1, 0x00C00000, -1, $xh)
        WinSetState($xh, "", @SW_MAXIMIZE)
    EndIf
EndFunc   ;==>Fullscreen

Func QuitProgram()
    Exit
EndFunc   ;==>QuitProgram

Func LoadConf()
    HotKeySet($toggleHK)
    HotKeySet($FullscreenHK)
    If FileExists($inifile) = 1 Then
        $toggleHK = IniRead($inifile, "Hotkeys", "ToggleCaption", "#q")
        $FullscreenHK = IniRead($inifile, "Hotkeys", "FullScreen", "#!q")
    Else
        FileWrite($inifile, "[Hotkeys]" & @CRLF & _
                "ToggleCaption=#q" & @CRLF & _
                "FullScreen=#!q" & @CRLF & @CRLF & _
                ";This file will be regenerated if removed." & @CRLF & _
                ";Hotkeys written in Autoit notation:" & @CRLF & _
                "; !=Alt" & @CRLF & _
                "; +=Shift" & @CRLF & _
                "; ^=Ctrl" & @CRLF & _
                "; #=Winkey" & @CRLF & _
                ";For more information: on AutoIT Hotkey Notation, and special keys:" & @CRLF & _
                ";http://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm" & @CRLF & _
                ";http://www.autoitscript.com/autoit3/docs/functions/Send.htm" & @CRLF & @CRLF & _
                ";HideCaption 0.9 Created by TurionAltec" & @CRLF & _
                ";HideCaption allows toggling the visibility of Window Caption (title) bars using hotkeys" & @CRLF & _
                ";'ToggleCaption' (default:Win+q) will toggle the caption on the active window" & @CRLF & _
                ";'FullScreen' (default: Win+Alt+q) will force a window maximized with no caption, hiding the task bar (if it exists)" & @CRLF & _
                ";Pressing the combination again will return the window to a 'Restored' state with a visible caption bar." & @CRLF & _
                ";To move a window with a hidden caption bar " & @CRLF & _
                ";activate the system menu (Alt+space) or use the utility AltMove:" & @CRLF & _
                ";http://www.deskex.com/Altmove/" & @CRLF & @CRLF & _
                ";For additional assistance with this tool, please read the AutoIT Thread:" & @CRLF & _
                ";http://www.autoitscript.com/forum/index.php?showtopic=103047")
        $toggleHK = "#q"
        $FullscreenHK = "#!q"
    EndIf
    HotKeySet($toggleHK, "TC")
    HotKeySet($FullscreenHK, "Fullscreen")
    _ReduceMemory()
EndFunc   ;==>LoadConf

Func TrayAbout()
    $message = "HideCaption 0.9" & @CRLF & _
            "Created by TurionAltec" & @CRLF & @CRLF & _
            "Allows toggling the visibility of the Caption (title) bar using hotkeys" & @CRLF & _
            "To move windows with a hidden caption bar " & @CRLF & _
            "activate the system menu (Alt+space) or use the utility AltMove:" & @CRLF & _
            "http://www.deskex.com/Altmove/" & @CRLF & @CRLF & _
            "To change the hotkeys select 'Modify Configuration' from the Tray menu" & @CRLF & @CRLF

    If $toggleHK = "#q" And $FullscreenHK = "#!q" Then
        $message &= "Currently the default hotkeys are being used:" & @CRLF & @CRLF & _
                "Toggle caption on the current window: Win+q" & @CRLF & _
                "Toggle 'full screen' mode: Win+Alt+q" & @CRLF

    Else
        $message &= "The following custom hotkeys are being used:" & @CRLF & @CRLF & _
                "Toggle caption on the current window: " & $toggleHK & @CRLF & _
                "Toggle 'full screen' mode: " & $FullscreenHK & @CRLF & @CRLF & _
                "Hotkeys written in Autoit notation:" & @CRLF & _
                "!=Alt" & @CRLF & _
                "+=Shift" & @CRLF & _
                "^=Ctrl" & @CRLF & _
                "#=Winkey"
    EndIf

    MsgBox(64, "HideCaption 0.9", $message)


EndFunc   ;==>TrayAbout
; from w0uter
;http://www.autoitscript.com/forum/index.php?showtopic=13399&view=findpost&p=93192
Func _ReduceMemory($i_PID = -1)
    If $i_PID <> -1 Then
        Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
        DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Else
        Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    EndIf
    Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

#Region AnyGUI
;Code from ANYGUI: http://www.autoitscript.com/forum/index.php?showtopic=9517&view=findpost&p=638738
Func _Refresh($TargethWnd)
    $r = DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $TargethWnd, "hwnd", $TargethWnd, _
            "int", 0, "int", 0, "int", 0, "int", 0, _
            "long", BitOR($SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOZORDER, $SWP_FRAMECHANGED))
    Return $r[0]
EndFunc   ;==>_Refresh

Func _TargetStyle($action = 0, $Bool = 0, $style = -1, $exstyle = -1, $LocTargethWnd = 0)
    If Not ($LocTargethWnd = 0) Then $TargethWnd = $LocTargethWnd
    Local $ostyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $TargethWnd, "int", -16);get existing Style
    Local $oexstyle = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $TargethWnd, "int", -20);get existing ExStyle
    Select
        Case $action = "set"
            If $style <> -1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -16, "long", BitOR($ostyle[0], $style));add Style to old style
            If $exstyle <> -1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -20, "long", BitOR($oexstyle[0], $exstyle));add Exstyle to old exstyle
        Case $action = "unset"
            If $style <> -1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -16, "long", BitAND($ostyle[0], BitNOT($style)));remove Style from old style
            If $exstyle <> -1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -20, "long", BitAND($oexstyle[0], BitNOT($exstyle)));remove Exstyle from old exstyle
        Case $action = "toggle"
            If $style <> -1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -16, "long", BitXOR($ostyle[0], $style));Toggle Style(s) on or off
            If $exstyle <> -1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -20, "long", BitXOR($oexstyle[0], $exstyle));Toggle ExStyle(s) on or off
        Case $action = "replace"
            If $style <> -1 Then Local $scall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -16, "long", $style);replace Style
            If $exstyle <> -1 Then Local $exscall = DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $TargethWnd, "int", -20, "long", $exstyle);replace Exstyle
        Case Else
            Dim $ret[2]
            $ret[0] = $ostyle[0]
            $ret[1] = $oexstyle[0]
            Return $ret
    EndSelect
    Dim $return[2]
    If $style <> -1 And $scall[0] <> $ostyle[0] Then
        SetError(1)
        $return[0] = 0
        MsgBox(4096, "Error setting Style", "Please check your Style settings and try again")
    ElseIf $exstyle <> -1 And $exscall[0] <> $oexstyle[0] Then
        SetError(2)
        $return[1] = 0
        MsgBox(4096, "Error setting ExStyle", "Please check your ExStyle settings and try again")
    Else
        If $style <> -1 Then
            $return[0] = $scall[0]
        Else
            $return[0] = $ostyle[0]
        EndIf
        If $exstyle <> -1 Then
            $return[1] = $exscall[0]
        Else
            $return[1] = $oexstyle[0]
        EndIf
    EndIf
    If $Bool = 1 Then _Refresh($TargethWnd)

    Return $return
EndFunc   ;==>_TargetStyle
#EndRegion AnyGUI

hidecaption.zip

EDIT: Small oversight. Win+Ctrl is awkward on my Eee's keyboard. Changed to Win+alt

EDIT: Posted entire program code

Edited by TurionAltec
Link to comment
Share on other sites

  • 7 months later...

I know this is a pretty old topic, but hopefully you will see this.

Is there any way to get HideCaption to hide all caption bars by default? That is, instead of having all title bars display as normal and having to hit Win (Alt) Q to hide them, is it possible for all windows to start WITHOUT title bars to begin with and then use Win (Alt) Q to optionally display them?

Thanks for reading.

Link to comment
Share on other sites

wandersfar, welcome to the forum.

While it may not be ppossible to start a window without caption by default, you can always tweak the script to consistently check for new window and hide the captions.

[Not using this account any more. Using "iShafayet" instead]

Link to comment
Share on other sites

Hi Shafayat, thanks for replying.

Could you point out the lines in the script I should modify (or add) to have the program check for new windows? I am not a programmer, but I'm willing to learn if you could show me what needs to be done.

Link to comment
Share on other sites

  • 2 months later...

I, too, would like to see if it is possible to modify the script to automatically make all windows that appear go fullscreen (like F11 in browser). I am not sure how to do this. Anyone who can advise of how to do this, or, point me to the correct forum to ask, would have my thanks.

~Bryan

Edited by 8ryan
Link to comment
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
 Share

  • Recently Browsing   0 members

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