Jump to content

TitleBar


James
 Share

Recommended Posts

Hey,

I am releasing TitleBar because I just cannot get the auto adjustment to work. Basically, TitleBar is a little script which can be integrated into an programs that have a GUI or not. You can set some functions for it to do like open notepad, if you type notepad in and press enter.

Currently, it is set to position itself with a 1024x768 resolution, as I cannot get Auto Adjustment to work.

#include <GuiConstants.au3>
#NoTrayIcon

$sGUI = GuiCreate("WinBar App", 100, 20, @DesktopWidth / 2 + 320, @DesktopHeight / 170, BitOR($WS_POPUP, $WS_EX_TOPMOST),$WS_EX_TOOLWINDOW)
$sInput = GUICtrlCreateInput("", -1, -1, 102, 22)
GUICtrlSetLimit($sInput, 20)

GuiSetState()
WinSetOnTop($sGUI, "", 1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sInput
            $sRead = GuiCtrlRead($sInput)
            ToDo()
    EndSwitch
Wend

Func ToDo()
    If $sRead = "help" Then MsgBox(0, "Help", "You need help?")
    If $sRead = "notepad" Then Run("notepad.exe")
EndFunc

I was hoping to make it into a UDF but I don't know how...

It's not great and it could be better, but I like it and it works.

Help

How do you exit the script? Type "exit" without the quotation marks into the title.

Thanks,

Secure

New links

My Version 2

Ed_Maximized Version

MsCreatoR's Version

On_fire's Version

Valuater's Version

Edit: Updated post with any help questions & links to other versions created by other members.

Edited by Secure_ICT
Link to comment
Share on other sites

  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I like the idea :whistle: . I think that it can be improved by incorporating a function that "remembers" entered commands and "learn" new ones.

In addition it would have to become visible when pressing a combination of keys and to be hidden automatically when executing...

These are only suggestions...

Ed

Link to comment
Share on other sites

And good ones.

Here is the new script with help from John Bailey:

#include <GuiConstants.au3>
#NoTrayIcon

$sGUI = GuiCreate("WinBar App", 100, 20, -1, -1, BitOR($WS_POPUP, $WS_EX_TOPMOST),$WS_EX_TOOLWINDOW)
$sInput = GUICtrlCreateInput("", -1, -1, 102, 22)
GUICtrlSetLimit($sInput, 20)

GuiSetState()
WinSetOnTop($sGUI, "", 1)

While 1
    WinFix()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $sInput
            $sRead = GuiCtrlRead($sInput)
            ToDo()
    EndSwitch
Wend

Func ToDo()
    If $sRead = "help" Then MsgBox(0, "Help", "You need help?")
    If $sRead = "notepad" Then Run("notepad.exe")
    EndFunc
    
Func WinFix()
    $pos = WinGetPos("Untitled - Notepad")
    $x = $pos[0] + $pos[2] - 200
    $y = $pos[1] +5
    $w = $pos[2]
    $h = $pos[3]
    WinSetOnTop($sGUI, "", 1)
    WinMove("WinBar App", "", $x, $y) 
    ;If @DesktopHeight = 1024 Then WinMove($sGUI, "", @DesktopHeight / 170, @DesktopWidth / 2 + 320)
EndFunc

Make sure Notepad is open :whistle:

Link to comment
Share on other sites

A little fixes and hotkeysets...

#include <GuiConstants.au3>
#NoTrayIcon
AutoItSetOption ( "GUICloseOnESC" , 0 )
HotKeySet ( "{esc}" , "HideWinBar" )
HotKeySet ( "!w" , "ShowWinBar" )

$sGUI = GuiCreate("WinBar App", 100, 20, @DesktopWidth -102 -55, 2, BitOR($WS_POPUP, $WS_EX_TOPMOST),$WS_EX_TOOLWINDOW)
$sInput = GUICtrlCreateInput("", 0, 0, 80, 20)
$Button1 = GUICtrlCreateButton("(Not allowed)", 80, 0, 20, 20, BitOR($BS_ICON,$BS_DEFPUSHBUTTON) )
GUICtrlSetImage(-1, "shell32.dll",137,0)
GUICtrlSetLimit($sInput, 20)

GuiSetState()
WinSetOnTop($sGUI, "", 1)

While 1
    WinFix()
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $sRead = GuiCtrlRead($sInput)
            ToDo()
    EndSwitch
    Sleep(50)
Wend
Exit

Func ToDo()
    If $sRead = "help" Then MsgBox(0, "Help", "You need help?")
    If $sRead = "notepad" Then Run("notepad.exe")
EndFunc

Func ShowWinBar()
    GUISetState(@SW_SHOW,$sGUI)
EndFunc

Func HideWinBar()
    GUISetState(@SW_HIDE,$sGUI)
EndFunc

Func WinFix()
    $var = WinList()
    For $i = 1 to $var[0][0]-1
        If $var[$i][0] <> "" AND WinActive($var[$i][0]) Then ExitLoop
    Next
    if $var[$i][0]<>"WinBar App" Then   
        $pos = WinGetPos($var[$i][1])
        $x = $pos[0] + $pos[2] - 157
        $y = $pos[1] +5
        $w = $pos[2]
        $h = $pos[3]
        WinMove("WinBar App", "", $x, $y)
        WinSetOnTop($sGUI, "", 1)
    EndIf
EndFunc

Notes:

Alt+W to show

ESC to hide

Ed

Link to comment
Share on other sites

Wow! Great idea!

I have taken it a litle bit to other direction, and have made this:

#include <GuiConstants.au3>
#NoTrayIcon
Opt("GUICloseOnESC", 0)
Opt("GuiOnEventMode", 1)

Global $Title = "WinBar App", $ActiveWin = WinGetTitle(""), $TransTitle
$WinActivePos = WinGetPos($ActiveWin)
$Left = $WinActivePos[0]
$sGUI = GuiCreate($Title, 20, 20, @DesktopWidth-90, 3, $WS_POPUP, $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST)

$Button = GUICtrlCreateButton("", 0, 0, 20, 20, $BS_ICON+$BS_DEFPUSHBUTTON)
GUICtrlSetImage(-1, "shell32.dll", 137, 0)
GUICtrlSetOnEvent(-1, "MainEvents")

$ContextMenu = GUICtrlCreateContextMenu()

$Minimize = GUICtrlCreateMenuitem("Minimize window", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
$Maximize = GUICtrlCreateMenuitem("Maximize window", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
$Hide = GUICtrlCreateMenuitem("Hide window (!)", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
$CloseWin = GUICtrlCreateMenuitem("Close window (!)", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
GUICtrlCreateMenuitem("", $ContextMenu)
$SetOnTop = GUICtrlCreateMenuitem("Set on Top", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
$UnSetOnTop = GUICtrlCreateMenuitem("UnSet on Top", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
GUICtrlCreateMenuitem("", $ContextMenu)
$SetTrans = GUICtrlCreateMenuitem("Set window transparent...", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
GUICtrlCreateMenuitem("", $ContextMenu)
$RunProgram = GUICtrlCreateMenuitem("Run program...", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")
GUICtrlCreateMenuitem("", $ContextMenu)
$CloseWinBar = GUICtrlCreateMenuitem("Exit WinBar", $ContextMenu)
GUICtrlSetOnEvent(-1, "MainEvents")

GuiSetState()
WinSetOnTop($sGUI, "", 1)
AdlibEnable("GuiMove", 10)

While 1
    Sleep(100)
Wend

Func MainEvents()
    Switch @GUI_CtrlId
        Case $Button
            ShowMenu($sGUI, @GUI_CtrlId, $ContextMenu)
        Case $Minimize
            If $ActiveWin <> $Title Then WinSetState($ActiveWin, "", @SW_MINIMIZE)
            GuiMove()
        Case $Maximize
            If $ActiveWin <> $Title Then WinSetState($ActiveWin, "", @SW_MAXIMIZE)
            GuiMove()
        Case $Hide
            If $ActiveWin <> $Title Then WinSetState($ActiveWin, "", @SW_HIDE)
            GuiMove()
        Case $CloseWin
            If $ActiveWin <> $Title Then WinClose($ActiveWin)
            GuiMove()
        Case $SetOnTop
            WinSetOnTop($ActiveWin, "", 1)
            WinSetOnTop($sGUI, "", 1)
        Case $UnSetOnTop
            WinSetOnTop($ActiveWin, "", 0)
        Case $SetTrans
            GUICtrlSetState($Button, 128)
            _SetTransparent($ActiveWin)
            GUICtrlSetState($Button, 64)
        Case $RunProgram
            Send("#r")
            GuiMove()
        Case $CloseWinBar
            Exit
    EndSwitch
EndFunc

Func GuiMove()
    If WinGetTitle("") <> $Title Then
        $ActiveWin = WinGetTitle("")
        $pos = WinGetPos($ActiveWin)
        $x = $pos[0] + $pos[2] - 95
        $y = $pos[1] + 7
        WinMove($Title, "", $x, $y)
        WinSetOnTop($sGUI, "", 1)
    EndIf
EndFunc

Func _SetTransparent($Title)
    Opt("GuiOnEventMode", 0)
    AdlibDisable()
    Global $TransTitle = $Title
    $TransGui = GUICreate("Setting Transparent", 300, 120, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW+$WS_EX_TOPMOST+$WS_EX_DLGMODALFRAME+$WS_EX_CLIENTEDGE )
    
    GUICtrlCreateLabel("Set transparent level for this window:" & @CR & $TransTitle, 20, 10, 280, 40, $ES_CENTER)
    
    Global $Slider = GUICtrlCreateSlider(15, 60, 280, 20)
    GUICtrlSetLimit(-1, 255)
    
    $OKButton = GUICtrlCreateButton("OK", 80, 90, 50, 20)
    $CancelButton = GUICtrlCreateButton("Cancel", 185, 90, 50, 20)
    
    GUISetState(@SW_SHOW, $TransGui)
    
    While 1
        SetTrans()
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $Slider
                WinSetTrans($TransTitle, "", 250-GUICtrlRead($Slider))
            Case $OKButton
                ExitLoop
            Case $CancelButton
                WinSetTrans($TransTitle, "", 250)
                ExitLoop
        EndSwitch
        Sleep(10)
    WEnd
    GUIDelete($TransGui)
    AdlibDisable()
    AdlibEnable("GuiMove", 10)
    Opt("GuiOnEventMode", 1)
EndFunc

Func SetTrans()
    WinSetTrans($TransTitle, "", 250-GUICtrlRead($Slider))
EndFunc

Func _IsVisible($handle)
    Return BitAnd(WinGetState($handle), 2)
EndFunc

Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $hMenu = GUICtrlGetHandle($nContextID)
    
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    
    Local $x = $arPos[0]
    Local $y = $arPos[1] + $arPos[3]
    
    ClientToScreen($hWnd, $x, $y)
    TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc

Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)

    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    $stPoint = 0
EndFunc

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc

It's not perfect, but realy cool! :whistle:

EDIT:

Just press on appeared button on active window and you will understand all :)

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Secure, I'm sorry to say that your posted script seems to be a little pointless. Please make an effort to post scripts that aren't useless and simple. Normally, I would not complain, but to think after such experience and time spent on this forum (843 posts), I expect something a little more appropriate. This is not an insult, but perhaps it is something to keep in mind.

Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Something like this has been posted before , I would urge you to check it out, It was something called like Run or something and yeah you could type commands in to do different things and such.

For the whole running an exe I would suggest using stringregexp and checking if .exe is present and there is an option with stringregexp that signifies to check if its the end of the line i think its $ or ?

Link to comment
Share on other sites

Not to be a me too or anything, but you gave me an idea too. :whistle:

Anyway, this will be a launcher that will do calculations, run programs, search your harddrive, go to links, search the web, ect.

Feel free to copy anything you want for your UDF. (Which I can help you with after I get done.) I would like to have multi monitor support, but a search didn't turn up anything that worked right. So if anyone knows how to get the size and position of monitors then please let me know.

Here is my alpha that I am in the middle of rewriting (for obvious reasons).

As far as I know it works fine, it's just bad, undocumented, code. XD

Let me know if you find anything interesting, or need any help.

CODE
#cs ----------------------------------------------------------------------------

Script Name:

Launcher

Script Description:

Adds a box to the top of your windows that runs things.

Instructions:

Edit settings.ini to your needs.

Author:

Sean "On_fire" Goheen <projects@onfire.us>

AutoIt Version:

3.1.1.0

Credits:

Secure_ICT Gave me the idea and the starting code. http://www.autoitscript.com/forum/index.php?showtopic=41473

Zebna Posted the code for getting the titlebar/border size.

#ce ----------------------------------------------------------------------------

Opt("RunErrorsFatal", 0)

#include <Misc.au3>

#include <GuiConstants.au3>

#Include <GuiCombo.au3>

#include <File.au3>

#include <Array.au3>

Global $oldText = ""

;~ #NoTrayIcon

_Singleton("Launcher")

HotKeySet("{esc}","hide")

HotKeySet("!{space}","show")

#region from Zedna http://www.autoitscript.com/forum/index.ph...tSystemMetrics#

Const $SM_CYCAPTION = 4

Const $SM_CXFIXEDFRAME = 7

$titleHeight = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CYCAPTION)

$titleHeight = $titleHeight[0] ; 19 or 26

$border = DllCall('user32.dll', 'int', 'GetSystemMetrics', 'int', $SM_CXFIXEDFRAME)

$border = $border[0] ; 3

#endregion

#region Startup

;Add extra space for uncommon buttons when requested

$extraBtnSpc = IniRead("settings.ini","settings", "extraBtnSpc", 0)

$Width = IniRead("settings.ini","settings", "WidthAjust", 100)

$Height = $titleHeight-IniRead("settings.ini","settings", "HeightAjust", 0)

$defaultLeft = @DesktopWidth-$Width-$extraBtnSpc-$titleHeight-$titleHeight-$titleHeight-IniRead("settings.ini","settings", "dftLft", 0)

$defaultTop = $border-IniRead("settings.ini","settings", "dftTop", 0)

#endregion

#region GUI

$sGUI = GuiCreate("Launcher", $Width, $Height, $defaultLeft, $defaultTop, BitOR($WS_POPUP, $WS_EX_TOPMOST),$WS_EX_TOOLWINDOW)

$sCombo = GUICtrlCreateCombo("", -1, -1, $Width+2, $Height+2,BitOR($CBS_NOINTEGRALHEIGHT,$GUI_SS_DEFAULT_COMBO))

$Submit = GUICtrlCreateButton("submit", -5, -5 , 2, 2, $BS_DEFPUSHBUTTON)

$History = _ArrayCreate("")

_FileReadToArray("history.txt", $History)

_ArrayDelete($History,0)

GUICtrlSetData($sCombo, _ArrayToString($History, "|"))

$actvWin = WinGetPos("")

WinMove($sGUI,"Launcher",($actvWin[0]+$actvWin[2])-$Width-$extraBtnSpc-$titleHeight-$titleHeight-$titleHeight-$border,$actvWin[1]+$border)

GuiSetState()

WinSetOnTop($sGUI, "", 1)

#endregion

While 1

$actvWin = WinGetpos("")

If WinGetHandle("") <> $sGUI Then WinMove($sGUI,"Launcher",($actvWin[0]+$actvWin[2])-$Width-$extraBtnSpc-$titleHeight-$titleHeight-$titleHeight-$border,$actvWin[1]+$border)

If WinGetHandle("") = "" Then WinMove($sGUI,"Launcher",$defaultLeft,$defaultTop)

_GUICtrlComboAutoComplete ($sCombo, $oldText)

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Submit

process()

EndSwitch

Wend

Func process()

$sRead = GuiCtrlRead($sCombo)

$words=StringSplit($sRead," ")

$srchRslt = IniRead("settings.ini", "Keywords", $words[1], 0)

Select

Case $words[1] = "exit"

Exit

Case $words[1] = "c"

MsgBox(0, "Launcher - Calc", Execute(StringReplace($sRead, $words[1] & " ", "")))

Case $srchRslt <> "0"

ShellExecute(StringReplace($srchRslt, "%s", StringReplace($sRead, $words[1] & " ", "")))

Case $sRead = "help"

MsgBox(0, "Launcher - Help", "You need help?")

Case Else

ShellExecute($sRead)

EndSelect

$i = _ArraySearch($History, $sRead)

If $i = -1 Then

If UBound($History) < IniRead("settings.ini","settings", "maxHist", 10) Then

_ArrayInsert($History, 0, $sRead)

Else

_ArrayPush($History,$sRead,1)

EndIf

Else

_ArrayDelete($History, $i)

_ArrayInsert($History, 0, $sRead)

EndIf

_FileWriteFromArray("history.txt", $History)

GUICtrlSetData($sCombo,"")

GUICtrlSetData($sCombo, _ArrayToString($History, "|"))

EndFunc

Func hide()

GuiSetState(@SW_HIDE,$sGUI)

GUICtrlSetData($sCombo,"")

GUICtrlSetData($sCombo, _ArrayToString($History, "|"))

EndFunc

Func show()

GuiSetState(@SW_SHOW,$sGUI)

EndFunc

Link to comment
Share on other sites

Nice. I'm glad you have found a use for it. So far its nice.

Thanks.

But it doesn't fit properly. Well the dropdown that is. If you run it, you will notice the GUI which is underneath. Check it out.

It's probably just my math is off somewhere. It's supposed to detect the size of the borders and titlebar, but it still seems to be off a bit.

I don't notice anything horribly wrong, but then I have the theme service turned off, so I don't know how well it will do on the default XP theme.

On second thought it may be that windows isn't resizing the combo properly, I'll have a look at it in a bit.

Edited by On_fire
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...