themaskedwolf Posted March 27, 2010 Share Posted March 27, 2010 ok trying to find a better opt. right now this script is used for a deaf person for chat program. it searches for any windows that have the word 'chat' and then makes a gui for enabling windows on top. expandcollapse popup;script by masked Wolf Opt("WinTitleMatchMode",2) Opt('MustDeclareVars', 1) #include <GUIConstantsEx.au3> global $clients clients() Example() Func clients() if WinExists("Chat") Then $clients=WinList("Chat") local $c=$clients[0][0]+1 ReDim $clients[$c][4] for $x=1 to $clients[0][0] $clients[$x][1]=0 ;~ MsgBox(0,"clients",$clients[$x][0]) Next Else MsgBox(0,"ERROR!","There are Currently No Chats active.") Exit EndIf EndFunc Func Example() Local $msg Local $setstate GUICreate("Windows On Top",300,80+$clients[0][0]*55,-1,-1,-1) ; will create a dialog box that when displayed is centered GUISetFont(9, 300) For $i=1 to $clients[0][0] ;makes a lable/menu with all window names GUICtrlCreateGroup("", 10, 45*($i-1)+5,275,55) ;starts group GUICtrlCreateLabel("Window: "&$clients[$i][0],20,45*($i-1)+20) $clients[$i][1]= GUICtrlCreateCheckbox("Always On Top",35, 35+45*($i-1)) GUICtrlSetState(-1,$GUI_UNCHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group Next $setstate = GUICtrlCreateButton("Set On Top on/off",50,80+($clients[0][0]-1)*55) GUICtrlSetState(-1,$GUI_FOCUS) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg=$setstate Then ;~ MsgBox(0,"work","") for $l=1 to $clients[0][0] If GUICtrlRead($clients[$l][1])=$GUI_CHECKED Then WinSetOnTop($clients[$l][0],"",1) ;~ MsgBox(0,"ontop",$clients[$l][0]) else WinSetOnTop($clients[$l][0],"",0) ;~ MsgBox(0,"not ontop",$clients[$l][0]) EndIf Next EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop sleep(10) WEnd EndFunc Now what a really want to do is write a code that will add a PIn up down button beside the minimize button on the windows title bar*(note this way it would apply to all windows regardless of any title name). i looked around on the forums and through the old archives. first of all if this is even viable then plz point me in the right direction. also i might start looking to see if maybe i can just edit a registry key and have it apply to any window. regardless of any of that i was wanting to make it where it would apply the pin button on any open window or window to be opened as the script posted above only shows windows open apon time of excute although i know its simple to fix that i was looking for a better way of handling this from a user prespective and i was thinking a button beside the minimize that would pin it ontop or unpin it would be nice. any suggestions or help would be nice thanks, The Masked Wolf Link to comment Share on other sites More sharing options...
themaskedwolf Posted March 27, 2010 Author Share Posted March 27, 2010 on a farther note on testing i've been trying few different ways of doing this but i believe i'm in over my head. =( and as i was thinking it was simple to have my current script to update with any new windows opening has failed. anyways i'll keep checking back here daily to see if anyone has any ideas to throw at this ^^ thanks, The Masked Wolf Link to comment Share on other sites More sharing options...
picea892 Posted March 27, 2010 Share Posted March 27, 2010 HiYou will need to hook all window activities. I think this example is closest to what you are looking forMy linkRecognizing this is only your third post. I tried to simplify it for you a bit, perhaps isn't helpful but will include anyways.expandcollapse popup#include <Process.au3> #include <Array.au3> #include <WindowsConstants.au3> Global $GUI,$guictrl Global Const $HSHELL_WINDOWCREATED = 1 Global Const $HSHELL_WINDOWDESTROYED = 2 Global Const $HSHELL_WINDOWACTIVATED = 4; Global Const $HSHELL_REDRAW = 6; Global $WindowList = GetListOfWindows() $GUI = GUICreate("testing",122,22,0,0,$WS_POPUP,$WS_EX_TOOLWINDOW) WinSetOnTop("testing","",1) $guictrl=GUICtrlCreateLabel("test",0,0,122,22) GUIRegisterMsg(RegisterWindowMessage("SHELLHOOK"), "HShellWndProc") ShellHookWindow($GUI) While 1 Sleep(250) WEnd Func OnAutoItExit() ShellUnhookWindow($GUI) EndFunc ;==>OnAutoItExit Func RegisterWindowMessage($sText) Local $aRet = DllCall("user32.dll", "int", "RegisterWindowMessage", "str", $sText) Return $aRet[0] EndFunc ;==>RegisterWindowMessage Func ShellHookWindow($hWnd) Local $aRet = DllCall("user32.dll", "int", "RegisterShellHookWindow", "hwnd", $hWnd) Return $aRet[0] EndFunc ;==>ShellHookWindow Func ShellUnhookWindow($hWnd) Local $aRet = DllCall("user32.dll", "int", "DeregisterShellHookWindow", "hwnd", $hWnd) Return $aRet[0] EndFunc ;==>ShellUnhookWindow= Func HShellWndProc($hWnd, $Msg, $wParam, $lParam) Switch $wParam Case $HSHELL_WINDOWACTIVATED or $HSHELL_REDRAW If WinGetTitle($lParam) <> "" And IsVisible($lParam) Then ReDim $WindowList[UBound($WindowList, 1) + 1][UBound($WindowList, 2)] $WindowList[UBound($WindowList, 1) - 1][0] = WinGetTitle($lParam) $WindowList[UBound($WindowList, 1) - 1][1] = $lParam $WindowList[UBound($WindowList, 1) - 1][2] = WinGetProcess($lParam) $WindowList[UBound($WindowList, 1) - 1][3] = WinGetState($lParam) ; If Not IsMaximized($lParam) Then $butlocation=WinGetPos(WinGetTitle($lParam),"") WinMove($GUI,"",$butlocation[0]+30,$butlocation[1]) GUISetState(@SW_SHOW,$GUI) ; EndIf EndIf Case $HSHELL_WINDOWDESTROYED For $i = 1 To UBound($WindowList, 1) - 1 If $WindowList[$i][1] = $lParam Then _ArrayDelete($WindowList, $i) ExitLoop EndIf Next EndSwitch EndFunc ;==>HShellWndProc Func GetListOfWindows() Local $aArray, $i = 1 $aArray = WinList() ReDim $aArray[UBound($aArray, 1)][UBound($aArray, 2) + 2] $aArray[0][1] = "Win Handle" $aArray[0][2] = "PID" $aArray[0][3] = "Win State" While $i <= $aArray[0][0] If ($aArray[$i][0] = "") Or Not (IsVisible($aArray[$i][1])) Or (_ProcessGetName(WinGetProcess($aArray[$i][1])) <> "explorer.exe") Then ;only include visible windows from explorer.exe (such as open folders) _ArrayDelete($aArray, $i) $aArray[0][0] -= 1 Else $aArray[$i][2] = WinGetProcess($aArray[$i][1]) $aArray[$i][3] = WinGetState($aArray[$i][1]) $i += 1 EndIf WEnd Return $aArray EndFunc ;==>GetListOfWindows Func IsVisible($hWnd) Return BitAND(WinGetState($hWnd), 2) EndFunc ;==>IsVisible Func IsMaximized($hWnd) Return BitAND(WinGetState($hWnd), 32) EndFunc ;==>IsMaximized Link to comment Share on other sites More sharing options...
themaskedwolf Posted March 27, 2010 Author Share Posted March 27, 2010 Hi picea892 i appricate the reply give me a day or two and see if i can grasp what is going on i see that u made a window that attaches it to the title bar around the file menu toolbar which is great. i'll have to play with the code to fullunderstand what is happening. so i'll be getting back on the forum after understand more of how u coded this and do a little research on shell hooking as it seems to be what i was thinking i need. anyways just wanted to say thanks again. Thanks The Masked Wolf Link to comment Share on other sites More sharing options...
picea892 Posted March 28, 2010 Share Posted March 28, 2010 (edited) Hi again.I knew I've seen this before. Took a while but I found the script I was looking for. It needed updating so I updated for the new autoit version. Include the link here (See Mr. Creator's post) and the revised version belowexpandcollapse popup#include <GuiConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.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) AdlibRegister("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) AdlibUnRegister() 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 Edited March 28, 2010 by picea892 Link to comment Share on other sites More sharing options...
themaskedwolf Posted March 28, 2010 Author Share Posted March 28, 2010 (edited) hi picea i saw that and was trying to figure out a way to combine the movment of link code by martin and the one u posted before. i'll try ur code u just posted on first run i had a ES_center undeclared i'll see if i cant sort through the code. FYI i want to thank u for your help as i havent coded in 10+ years and this is like learning brand new. some of the logic of your code i cant exactly follow yet but i'm still researching and working on it ^^ just wanted to thank you again i'll keep u posted edit: seems i missed a include nneeded the include of #include <EditConstants.au3>. also it seems i was reading some where that adlibenable was changed i'll have to search up on it again i get errors in my runs with itedit2: i got the change to adlib reg/unreg and it works great although i'm trying to figure out y it moves sometimes when i click on it. although i noticed in the code on line 89/90 when u click on it it will double the values of - X so instead of -90 it will be -180 and i'm thinking it has to do with it thinks that the button it self is a window and from my understanding of the code thus far it is a child window of the window it controls.expandcollapse popup#include <GuiConstants.au3> #include <WindowsConstants.au3> #include <GuiButton.au3> #include <EditConstants.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) AdlibRegister("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] - 90 $y = $pos[1] + 2 WinMove($Title, "", $x, $y) WinSetOnTop($sGUI, "", 1) EndIf EndFunc Func _SetTransparent($Title) Opt("GuiOnEventMode", 0) AdlibUnRegister() 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) AdlibUnRegister() AdlibRegister("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) EndFuncThanksThe Masked Wolf Edited March 28, 2010 by themaskedwolf Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now