Sign in to follow this  
Followers 0
exodius

WinSetState Issue

15 posts in this topic

I can't figure out why it is that this script won't hide and show the windows based on the window handles...

#include <GUIConstants.au3>
GUICreate("Window ReOrder", 620, 333, 192, 125)
$ListView1 = GUICtrlCreateListView("Window # | Window Name | Window Handle", 16, 8, 490, 310)
$MoveUp = GUICtrlCreateButton("Move Up", 520, 32, 91, 33)
$MoveDown = GUICtrlCreateButton("Move Down", 520, 80, 91, 33)
$MakeChanges = GUICtrlCreateButton("Make Changes", 520, 128, 91, 33)

$var = WinList()
Dim $list
Dim $Count = 1

For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) And $var[$i][0] <> "Program Manager" Then
    GUICtrlCreateListViewItem ( $count & "|" & $var[$i][0] & "|" & $var[$i][1], $ListView1)
    $count = $count + 1
  EndIf
Next

GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $MoveUp
        If GUICtrlRead ($ListView1) > 7 And GUICtrlRead ($ListView1) < $count + 7 - 1 Then
            If StringInStr ( GUICtrlRead(GUICtrlRead($ListView1)), "|" ) Then
                If StringInStr ( GUICtrlRead(GUICtrlRead($ListView1) - 1), "|" ) Then
                    $Selection = GuiCtrlRead ( $ListView1 )
                    $SelectionData = GUICtrlRead(GUICtrlRead($ListView1))
                    $SelectionDataSplit = StringSplit($SelectionData, "|" )
                    $SelectionDataWinNum = $SelectionDataSplit[1] - 1
                    $SelectionDataName = $SelectionDataSplit[2]
                    $SelectionDataHandle = $SelectionDataSplit[3]
                    $SelectionData = $SelectionDataWinNum & "|" & $SelectionDataName & "|" & $SelectionDataHandle
                    
                    $ToMove = GuiCtrlRead ( $ListView1 ) - 1
                    $ToMoveData = GUICtrlRead(GUICtrlRead($ListView1)- 1)
                    $ToMoveDataSplit = StringSplit($ToMoveData, "|" )
                    $ToMoveDataWinNum = $ToMoveDataSplit[1] + 1
                    $ToMoveDataName = $ToMoveDataSplit[2]
                    $ToMoveDataHandle = $ToMoveDataSplit[3]
                    $ToMoveData = $ToMoveDataWinNum & "|" & $ToMoveDataName & "|" & $ToMoveDataHandle
                    
                    GuiCtrlSetData ( $ToMove, $SelectionData )
                    GUICtrlSetData ( $Selection, $ToMoveData )
                    ControlSend ( "Window ReOrder", "", $ListView1, "{Up}" )
                EndIf
            EndIf
        EndIf
        
    Case $msg = $MoveDown
        If GUICtrlRead ($ListView1) >= 7 And GUICtrlRead ($ListView1) <= $count + 7 - 1 Then
            If StringInStr ( GUICtrlRead(GUICtrlRead($ListView1)), "|" ) Then
                If StringInStr ( GUICtrlRead(GUICtrlRead($ListView1) + 1), "|" ) Then
                    $Selection = GuiCtrlRead ( $ListView1 )
                    $SelectionData = GUICtrlRead(GUICtrlRead($ListView1))
                    $SelectionDataSplit = StringSplit($SelectionData, "|" )
                    $SelectionDataWinNum = $SelectionDataSplit[1] + 1
                    $SelectionDataName = $SelectionDataSplit[2]
                    $SelectionDataHandle = $SelectionDataSplit[3]
                    $SelectionData = $SelectionDataWinNum & "|" & $SelectionDataName & "|" & $SelectionDataHandle
                    
                    $ToMove = GuiCtrlRead ( $ListView1 ) + 1
                    $ToMoveData = GUICtrlRead(GUICtrlRead($ListView1)+ 1)
                    $ToMoveDataSplit = StringSplit($ToMoveData, "|" )
                    $ToMoveDataWinNum = $ToMoveDataSplit[1] - 1
                    $ToMoveDataName = $ToMoveDataSplit[2]
                    $ToMoveDataHandle = $ToMoveDataSplit[3]
                    $ToMoveData = $ToMoveDataWinNum & "|" & $ToMoveDataName & "|" & $ToMoveDataHandle
                    
                    GuiCtrlSetData ( $ToMove, $SelectionData )
                    GUICtrlSetData ( $Selection, $ToMoveData )
                
                    ControlSend ( "Window ReOrder", "", $ListView1, "{Down}" )
                EndIf
            EndIf
        EndIf
        
    Case $msg = $MakeChanges
        For $x = 1 To $count + 10
            If StringInStr ( GUICtrlRead($x), "|" ) Then
                $MakeChangesSplit = StringSplit ( GUICtrlRead($x), "|" )
                WinSetState ( $MakeChangesSplit[3], "", @SW_HIDE )
            EndIf
        Next
        For $x = 7 To $count + 10
            If StringInStr ( GUICtrlRead($x), "|" ) Then
                $MakeChangesSplit = StringSplit ( GUICtrlRead($x), "|" )
                WinSetState ( $MakeChangesSplit[3], "", @SW_SHOW )
            EndIf
        Next
    EndSelect
WEnd

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Share this post


Link to post
Share on other sites



to work with handle did you set

opt(WinTitleMatchMode,4)?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

to work with handle did you set

opt(WinTitleMatchMode,4)?

Setting that doesn't seem to make a difference... :lmao:

Edited by exodius

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Setting that doesn't seem to make a difference... :lmao:

Quite right, using window handles does not matter what mode you choose. Its irrelevant

However, your problem lies in the block of code below., specifically the loop and GUICtrlRead command.

What GuiCtrl are you trying to read?, as you have it currently, you are trying to read a control as defined in your $x variable, shouldnt it be $Listview1 ??

i.e GuiCtrlRead(GuiCtrlRead($Listview1)) returns selected item only

You need to use the _GUICtrlListViewGet functions, check out the help file.

I believe, using guictrlread on a listview on returns ONLY the currently selected item. Not what you want it to do.

Sorry cant help specifically, I am knackered Tired, but that is where your problem could lie.

but there again im so tired i may be wrong too.

Good Luck

HardCopy

Case $msg = $MakeChanges
        For $x = 1 To $count + 10
            If StringInStr ( GUICtrlRead($x), "|" ) Then
                $MakeChangesSplit = StringSplit ( GUICtrlRead($x), "|" ); <<<<----  here
                WinSetState ( $MakeChangesSplit[3], "", @SW_HIDE )
            EndIf
        Next
        For $x = 7 To $count + 10
            If StringInStr ( GUICtrlRead($x), "|" ) Then
                $MakeChangesSplit = StringSplit ( GUICtrlRead($x), "|" ); <<<<----- here
                WinSetState ( $MakeChangesSplit[3], "", @SW_SHOW )
            EndIf
        Next
    EndSelect
Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Wow, that is so totally what I was doing wrong... And I can see a lot more elegant way to do a lot of what I was doing. Thanks!

Share this post


Link to post
Share on other sites

Wow, that is so totally what I was doing wrong... And I can see a lot more elegant way to do a lot of what I was doing. Thanks!

So this is the product of HardCopy's observations... but I still can't get it to hide/show the windows at the end to make it put them in order for me! Can anyone else see anything blatantly wrong that I'm doing? :lmao:

#include <GUIConstants.au3>
#Include <GuiListView.au3>

GUICreate("Window ReOrder", 620, 333, 192, 125)
$ListView1 = GUICtrlCreateListView("Window Name | Window Handle", 16, 8, 490, 310)
$Top = GUICtrlCreateButton("Move to Top", 520, 8, 91, 33)
$MoveUpTwo = GUICtrlCreateButton("Move Up Two", 520, 50, 91, 33)
$MoveUp = GUICtrlCreateButton("Move Up", 520, 92, 91, 33)
$MoveDown = GUICtrlCreateButton("Move Down", 520, 132, 91, 33)
$MoveDownTwo = GUICtrlCreateButton("Move Down Two", 520, 174, 91, 33)
$Bottom = GUICtrlCreateButton("Move to Bottom", 520, 216, 91, 33)
$MakeChanges = GUICtrlCreateButton("Make Changes", 520, 285, 91, 33)

$var = WinList()
Dim $list
Dim $Count = 1

For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) And $var[$i][0] <> "Program Manager" Then
    GUICtrlCreateListViewItem ( $var[$i][0] & "|" & $var[$i][1], $ListView1)
  EndIf
Next

_GUICtrlListViewSetColumnWidth($ListView1, 0, 389)
_GUICtrlListViewSetItemSelState($ListView1, 0)
GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Top
        $Position = _GUICtrlListViewGetCurSel($ListView1)
        $Current = _GUICtrlListViewGetItemText($ListView1, $Position)
        _GUICtrlListViewDeleteItem($ListView1, _GUICtrlListViewGetCurSel($ListView1))
        _GUICtrlListViewInsertItem($ListView1, 0, $Current) 
        _GUICtrlListViewSetItemSelState($ListView1, 0)
    Case $msg = $MoveUpTwo
        If _GUICtrlListViewGetCurSel($ListView1)-2 > -1 Then
            $Position = _GUICtrlListViewGetCurSel($ListView1)
            $Current = _GUICtrlListViewGetItemText($ListView1, $Position)
            _GUICtrlListViewDeleteItem($ListView1, _GUICtrlListViewGetCurSel($ListView1))
            _GUICtrlListViewInsertItem($ListView1, $Position - 2, $Current) 
            _GUICtrlListViewSetItemSelState($ListView1, $Position - 2)
        EndIf
    Case $msg = $MoveUp
        $Position = _GUICtrlListViewGetCurSel($ListView1)
        $Current = _GUICtrlListViewGetItemTextArray ($ListView1, $Position)
        $New = _GUICtrlListViewGetItemTextArray ($ListView1, $Position-1)
        _GUICtrlListViewSetItemText($ListView1, $Position, 0, $New[1])
        _GUICtrlListViewSetItemText($ListView1, $Position, 1, $New[2])
        _GUICtrlListViewSetItemText($ListView1, $Position-1, 0, $Current[1])
        _GUICtrlListViewSetItemText($ListView1, $Position-1, 1, $Current[2])
        _GUICtrlListViewSetItemSelState($ListView1, $Position - 1)
    Case $msg = $MoveDown
        If _GUICtrlListViewGetCurSel($ListView1)+1 < _GUICtrlListViewGetItemCount($ListView1) Then
            $Position = _GUICtrlListViewGetCurSel($ListView1)
            $Current = _GUICtrlListViewGetItemTextArray ($ListView1, $Position)
            $New = _GUICtrlListViewGetItemTextArray ($ListView1, $Position+1)
            _GUICtrlListViewSetItemText($ListView1, $Position, 0, $New[1])
            _GUICtrlListViewSetItemText($ListView1, $Position, 1, $New[2])
            _GUICtrlListViewSetItemText($ListView1, $Position+1, 0, $Current[1])
            _GUICtrlListViewSetItemText($ListView1, $Position+1, 1, $Current[2])
            _GUICtrlListViewSetItemSelState($ListView1, $Position + 1)
        EndIf
    Case $msg = $MoveDownTwo
        If _GUICtrlListViewGetCurSel($ListView1)+2 < _GUICtrlListViewGetItemCount($ListView1) Then
            $Position = _GUICtrlListViewGetCurSel($ListView1)
            $Current = _GUICtrlListViewGetItemText($ListView1, $Position)
            _GUICtrlListViewDeleteItem($ListView1, _GUICtrlListViewGetCurSel($ListView1))
            _GUICtrlListViewInsertItem($ListView1, $Position + 2, $Current) 
            _GUICtrlListViewSetItemSelState($ListView1, $Position + 2)
        EndIf
    Case $msg = $Bottom
        $Position = _GUICtrlListViewGetCurSel($ListView1)
        $Current = _GUICtrlListViewGetItemText($ListView1, $Position)
        _GUICtrlListViewDeleteItem($ListView1, _GUICtrlListViewGetCurSel($ListView1))
        _GUICtrlListViewInsertItem($ListView1, _GUICtrlListViewGetItemCount($ListView1), $Current) 
        _GUICtrlListViewSetItemSelState($ListView1, _GUICtrlListViewGetItemCount($ListView1))
        
        
    Case $msg = $MakeChanges
        For $x = 0 To _GUICtrlListViewGetItemCount($ListView1)-1
            $MakeChangesSplit = _GUICtrlListViewGetItemTextArray ( $ListView1, $x )
            WinSetState ( $MakeChangesSplit[2], "", @SW_HIDE )
        Next
        For $x = 0 To _GUICtrlListViewGetItemCount($ListView1)-1
            $MakeChangesSplit = _GUICtrlListViewGetItemTextArray ( $ListView1, $x )
            WinSetState ( $MakeChangesSplit[2], "", @SW_SHOW )
        Next
    EndSelect
WEnd

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Share this post


Link to post
Share on other sites

Quite right, using window handles does not matter what mode you choose. Its irrelevant

Busted.

Remarks

This function is for use with the advanced WinTitleMatchMode options that allow you to use classnames and handles to specify windows rather than "title" and "text".

Once you have obtained the handle you can access the required window even if its title changes.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Busted.

Was any of this post actually directed at me?

Share this post


Link to post
Share on other sites

Was any of this post actually directed at me?

LoL no...was at me!!

My statement i made was a little misleading when another responder said try:

Opt("WinTitleMatchMode",4), i said it was irrelevant, but what that came over as was, u dont need to use it

What i should of said, was that which ever option parameter you use, when addressing using window handles as you are, it doesnt matter which option you use 1,2,3 or 4.

So now u have made some changes, include it at the top see if that does indeed now work.

HardCopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Sorry for the confusion, exodius


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Sorry for the confusion, exodius

It's all good... although when I tried switching the WinTitleMatchMode it didn't help... :lmao:

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

It's all good... although when I tried switching the WinTitleMatchMode it didn't help... :lmao:

Ok

add wintitlematchmode,4 at top

change your code section makechanges to this:

we were missing the HWnd command,because handles are not either strings or numbers. doh!!!

Case $msg = $MakeChanges
        For $x = 0 To _GUICtrlListViewGetItemCount($ListView1)-1
            $MakeChangesSplit = _GUICtrlListViewGetItemTextArray ( $ListView1, $x )
            WinSetState (HWnd($MakeChangesSplit[2]), "", @SW_HIDE )
        Next
        For $x = 0 To _GUICtrlListViewGetItemCount($ListView1)-1
            $MakeChangesSplit = _GUICtrlListViewGetItemTextArray ( $ListView1, $x )
            WinSetState (HWnd($MakeChangesSplit[2]), "", @SW_SHOW )
        Next

HardCopy

Edited by HardCopy

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

Ok

add wintitlematchmode,4 at top

change your code section makechanges to this:

we were missing the HWnd command,because handles are not either strings or numbers. doh!!!

HardCopy

That did the trick! Thanks a lot, I didn't know that it was necessary to use the HWnd command with handles... I knew of it, and now that you mention it, it makes sense... maybe that little tidbit of info needs added to the Winlist and WinGetHandle pages in the helpfile.

At any rate, thanks a bunch hardcopy! Now I don't suppose you'd have any idea on how to get a listing of the windows in the order that they appear on the toolbar would ya? :lmao:

Share this post


Link to post
Share on other sites

That did the trick! Thanks a lot, I didn't know that it was necessary to use the HWnd command with handles... I knew of it, and now that you mention it, it makes sense... maybe that little tidbit of info needs added to the Winlist and WinGetHandle pages in the helpfile.

At any rate, thanks a bunch hardcopy! Now I don't suppose you'd have any idea on how to get a listing of the windows in the order that they appear on the toolbar would ya? :lmao:

No, sorry, I Don't

But u can apparently, dictate the order you want them to appear, by hiding then showing them again

see here: Link

HardCopy


Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Share this post


Link to post
Share on other sites

No, sorry, I Don't

But u can apparently, dictate the order you want them to appear, by hiding then showing them again

see here: Link

HardCopy

It's all good, that very action is exactly what this script is geared towards. It'd be nice if this script could present them to you in the order they're already in so if you just wanted to move a single window for example then it wouldn't be as much work.. :lmao: I'm starting to think there isn't a way to know.. or at least if there is no one's aware of it. But hey I do appreciate all of your help on this, you defintely got me past the snags that I'd ran into. Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0