Hawkwing Posted March 16, 2009 Share Posted March 16, 2009 I'm trying to make a script that creates a gui when you press a hotkey. I want the gui to have a list of windows that you can select. The gui will probably have a radio for Hide/Show, so you can either hide or show the selected window and a button to Hide/Show the window. I found this code for a list of windows, but doesn't list a window if it's hidden. I don't really understand the script either, so I don't know how to make it show hidden windows. CODE #include <Array.au3> #include <Constants.au3> #include <windowsConstants.au3> Dim $aWin = WinList(), $aWindows[1][1] Dim $hUser32 = DllOpen('user32.dll') Dim $iEx_Style, $iCounter = 0 For $i = 1 To $aWin[0][0] $iEx_Style = BitAND(GetWindowLong($aWin[$i][1], $GWL_EXSTYLE), $WS_EX_TOOLWINDOW) Local $iStyle = BitAND(WinGetState($aWin[$i][1]), 2) If $iEx_Style <> -1 And Not $iEx_Style And $iStyle Then ReDim $aWindows[$iCounter+1][1] $aWindows[$iCounter][0] = $aWin[$i][0] $iCounter += 1 EndIf Next _ArrayDisplay($aWindows) DllClose($hUser32) Func GetWindowLong($hWnd, $iIndex, $hUser = 'user32.dll') Local $Ret = DllCall($hUser, 'int', 'GetWindowLong', 'hwnd', $hWnd, 'int', $iIndex) If Not @error Then Return $Ret[0] Return SetError(-1, 0, -1) EndFunc The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Authenticity Posted March 16, 2009 Share Posted March 16, 2009 It lists only windows with a button on the taskbar, if you want to list all windows in the system you don't need this loop. Link to comment Share on other sites More sharing options...
Hawkwing Posted March 16, 2009 Author Share Posted March 16, 2009 So how would I make a gui with a list of all windows? The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Authenticity Posted March 16, 2009 Share Posted March 16, 2009 Something like this: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> Dim $hGUI = GUICreate('Test', 350, 600) Dim $Btn = GUICtrlCreateButton('&Search', 95, 530, 60, 23) Dim $hListView = _GUICtrlListView_Create($hGUI, 'Window title (if available) |Handle ', 10, 10, 330, 480) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) GUISetState() While 1 Local $Msg = GUIGetMsg() Switch $Msg Case $Btn GUICtrlSetState($Btn, $GUI_DISABLE) _Search() GUICtrlSetState($Btn, $GUI_ENABLE) Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Search() Local $avWin = WinList(), $i _GUICtrlListView_DeleteAllItems($hListView) _GUICtrlListView_BeginUpdate($hListView) For $i = 1 To $avWin[0][0] _GUICtrlListView_AddItem($hListView, $avWin[$i][0]) _GUICtrlListView_AddSubItem($hListView, $i-1, $avWin[$i][1], 1) Next _GUICtrlListView_EndUpdate($hListView) EndFunc Link to comment Share on other sites More sharing options...
Hawkwing Posted March 16, 2009 Author Share Posted March 16, 2009 (edited) Thanks. I put in an input box and a Hide/Show button, but I don't know how to make it so that when I click on one of the windows, it puts the title in the input box. If I can get that I can just use WinSetState (GUICtrlRead ($input), "", @SW_HIDE) And how do you find out if a window is hidden? I need to know to know whether to hide or show. If window is hidden Then WinSetState (GUICtrlRead ($input), "", @SW_SHOW) Else WinSetState (GUICtrlRead ($input), "", @SW_HIDE) Edited March 16, 2009 by pigeek The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Authenticity Posted March 16, 2009 Share Posted March 16, 2009 If it's not visible then BitAND(WinGetState($avWin[$i][1], 2) will result in 0 otherwise it's 2 (just greater than 0).What do you mean click on one of the windows? on an item of the ListView or on the window? Link to comment Share on other sites More sharing options...
Hawkwing Posted March 16, 2009 Author Share Posted March 16, 2009 Sorry, I should have been more specific. I meant by clicking on a window in the listview. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Authenticity Posted March 17, 2009 Share Posted March 17, 2009 Heh, funny stuff: expandcollapse popup#include <Constants.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> Dim $hGUI = GUICreate('Test', 350, 600) Dim $BtnSearch = GUICtrlCreateButton('&Search', 105, 530, 60, 23) Dim $BtnShow = GUICtrlCreateButton('Sho&w/Hide', 175, 530, 60, 23) Dim $hListView = _GUICtrlListView_Create($hGUI, 'Window title (if available) |Handle ', 10, 10, 330, 480) _GUICtrlListView_SetColumnWidth($hListView, 0, 200) GUISetState() While 1 Local $Msg = GUIGetMsg() Switch $Msg Case $BtnSearch GUICtrlSetState($BtnSearch, $GUI_DISABLE) _Search() GUICtrlSetState($BtnSearch, $GUI_ENABLE) Case $BtnShow Local $hWnd Local $sItem = _GUICtrlListView_GetSelectedIndices($hListView) If $sItem <> "" Then $hWnd = _GUICtrlListView_GetItemText($hListView, $sItem, 1) If BitAND(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), 0x10000000) Then _WinAPI_ShowWindow($hWnd, @SW_HIDE) Else _WinAPI_ShowWindow($hWnd, @SW_SHOW) _WinAPI_ShowWindow($hWnd, @SW_RESTORE) EndIf EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Search() Local $avWin = WinList(), $i _GUICtrlListView_DeleteAllItems($hListView) _GUICtrlListView_BeginUpdate($hListView) For $i = 1 To $avWin[0][0] _GUICtrlListView_AddItem($hListView, $avWin[$i][0]) _GUICtrlListView_AddSubItem($hListView, $i-1, $avWin[$i][1], 1) Next _GUICtrlListView_EndUpdate($hListView) EndFunc Link to comment Share on other sites More sharing options...
Hawkwing Posted March 17, 2009 Author Share Posted March 17, 2009 Thanks for the help. I've never really used a listview before, but I think I get it now. The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. 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