Jump to content

Problem with multiple GUI's part II... Switch and Follow.


Recommended Posts

Hello everyone!

A new problem arises from my previous topic... My GUI creates a second one to wrap a putty session and provide right click and drag and drop...Everything works fine with just one Putty and one GUI, But sometimes will be needed to call mmore than 1 session, and the problems start here...

I have a follow script on the while, that target only for a Putty window, so if I have more than one, it stops working...
 

If WinExists("[CLASS:PuTTY]") Then

    $PUTTYpos = WinGetPos("[CLASS:PuTTY]")
    $GUIpos = WinGetPos("Connect Helper")

    $xpos = $PUTTYpos[2] - $GUIpos[2]
    $ypos = $PUTTYpos[3] - $GUIpos[3]
    If $PUTTYpos[0] <> $GUIpos[0] Then
    WinMove($GUIPUTTY,"",$PUTTYpos[0] + $xpos,$PUTTYpos[1] + $ypos)
    EndIf
EndIf

and the create part look like this:
 

The $b is because I tried some topics from the search before I come here for help...But I could not suceed and I'm a little lost about the follow part...

Func _GUIPUTTY()

$b += 1
Global $PuTTY = WinGetHandle("[CLASS:PuTTY]")

sleep(500)

$GUIPUTTY[$b] = GUICreate("Connect Helper Session", 200, 430, Default ,Default,$WS_POPUP,BitOR($WS_EX_TOOLWINDOW,$WS_EX_ACCEPTFILES),$PuTTY)
    _ChangeWindowMessageFilterEx($GUIPUTTY[$b], 0x233, 1) ; $WM_DROPFILES
    _ChangeWindowMessageFilterEx($GUIPUTTY[$b], $WM_COPYDATA, 1) ; redundant?
    _ChangeWindowMessageFilterEx($GUIPUTTY[$b], 0x0049, 1) ; $WM_COPYGLOBALDATA

                Global $InsertFile = GUICtrlCreateLabel("", 60, 310, 100, 100,-1,$WS_EX_STATICEDGE)
                GUICtrlSetState ($InsertFile, $GUI_DROPACCEPTED)
                GUICtrlSetTip ($InsertFile, "Arraste arquivos aqui para enviar!" & @CRLF & @CRLF & "Clique direito para menu!" )
                GUICtrlSetBkColor($InsertFile,0xFFFFFF)

GUISetState()
WinSetTrans($GUIPUTTY[$b],"",40)
GUISetControlsVisible($GUIPUTTY[$b])


WinMove($GUIPUTTY[$b],"",@DesktopWidth/2 - 342,@DesktopHeight/2 - 215,200,430)
WinMove($PuTTY,"",@DesktopWidth/2 - 350,@DesktopHeight/2 - 215,708,438)

$PUTTYID = WinGetProcess("[CLASS:PuTTY]")
$GUIID = WinGetProcess($GUIPUTTY[$b])



EndFunc

I'm using the advanced GuiGetMsg for multiples GUI:
 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_hGUI2 = 9999, $g_idButton3 ; Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time

gui1()

Func gui1()
    Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
    Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30)
    Local $idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
    GUISetState()

    Local $aMsg 
    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $hGUI1
                Switch $aMsg[0] ; Now check for the messages for $hGUI1
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we exit <<<<<<<<<<<<<<<
                        ExitLoop
                    Case $idButton1
                        MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1")
                    Case $idButton2
                        GUICtrlSetState($idButton2, $GUI_DISABLE)
                        gui2()
                EndSwitch
            Case $g_hGUI2
                Switch $aMsg[0] ; Now check for the messages for $g_hGUI2
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<<
                        GUIDelete($g_hGUI2)
                        GUICtrlSetState($idButton2, $GUI_ENABLE)
                    Case $g_idButton3
                        MsgBox($MB_OK, "MsgBox", "Test from Gui 2")
                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>gui1

Func gui2()
    $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
    Local $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
    GUISetState()
EndFunc   ;==>gui2

 

Someone have been troubled for something similar? Can a good soul point me to the right direction?

Thanks guys my script whouldn't come so far without your help! :)

Edited by edumanilha
correction
Link to comment
Share on other sites

hey again :D 

#include <Array.au3>
Local $aarray = WinList ( "[CLASS:PuTTY]","" )
_ArrayDisplay ( $aarray )

you can use this to difference between the handles of putty

 

i guess you didn't have declared the $GUIPutty on top as global if you didn't change it already, but if you declare it with a constant the error will appear again after (x declared instances) so you could use

Dim
Redim

 

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

LOL! Hero comes my savior again! :D

I'm stuck again my friend, many times I almost dropped the project...Nights sleeping late, some discussion here about lies...Its been hard! the script is getting far more complicated than the initial idea...I think thats the final step!

Quote
#include <Array.au3>
Local $aarray = WinList ( "[CLASS:PuTTY]","" )
_ArrayDisplay ( $aarray )

you can use this to difference between the handles of putty

I'll take a look! thanks!

Quote

i guess you didn't have declared the $GUIPutty on top as global if you didn't change it already, but if you declare it with a constant the error will appear again after (x declared instances) so you could use

Dim
Redim

I've declared like this:

Global $GUIPUTTY[9]
Global $PuTTY[9]

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <windowsConstants.au3>
#include <array.au3>
Global $b = 1
Dim $GUIPUTTY[$b]
Dim $InsertFile[$b]
Dim $PuTTY[$b]
Global $g_hGUI2 = 9999, $g_idButton3 ; Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time

gui1()

Func gui1()
    Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100)
    Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30)
    Local $idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30)
    GUISetState()

    Local $aMsg
    While 1
        $ubnd = UBound($GUIPUTTY) - 1
;~      MsgBox ( 64,"",$ubnd )
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        Switch $aMsg[1] ; check which GUI sent the message
            Case $hGUI1
                Switch $aMsg[0] ; Now check for the messages for $hGUI1
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we exit <<<<<<<<<<<<<<<
                        ExitLoop
                    Case $idButton1
;~                         MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1")
                        _GUIPUTTY()
                    Case $idButton2
                        GUICtrlSetState($idButton2, $GUI_DISABLE)
                        gui2()
                EndSwitch
            Case $g_hGUI2
                Switch $aMsg[0] ; Now check for the messages for $g_hGUI2
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<<
                        GUIDelete($g_hGUI2)
                        GUICtrlSetState($idButton2, $GUI_ENABLE)
                    Case $g_idButton3
                        MsgBox($MB_OK, "MsgBox", "Test from Gui 2")

                EndSwitch
        EndSwitch
        For $i = 0 To $ubnd
            Switch $aMsg[1]
                Case $GUIPUTTY[$i]
                    Switch $aMsg[0]
                        Case $GUI_EVENT_PRIMARYDOWN
                            MsgBox(64, "Putty Instance Handle", $aMsg[1])
                        Case $GUI_EVENT_DROPPED
                            MsgBox(64, "", @GUI_DragFile)
                    EndSwitch
            EndSwitch
        Next
    WEnd
EndFunc   ;==>gui1

Func gui2()
    $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350)
    Local $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
    GUISetState()
EndFunc   ;==>gui2

Func _GUIPUTTY()
    $b += 1
    ReDim $InsertFile[$b]
    ReDim $PuTTY[$b]
    ReDim $GUIPUTTY[$b]

    Local $aPutty = WinList("[CLASS:PuTTY]")
    If $aPutty[0][0] > 0 Then
        If $aPutty[0][0] > $b - 1 Then
            For $i = 1 To $b - 1
                $PuTTY[$i] = $aPutty[$i][1]
            Next
        Else
            For $i = 1 To $aPutty[0][0]
                $PuTTY[$i] = $aPutty[$i][1]
            Next
        EndIf
        WinMove($PuTTY[$b - 1], "", 1 + ($b - 2) * 700, 1, 675, 408)
        $GUIPUTTY[$b - 2] = GUICreate("Connect Helper Session", 200, 430, Default, Default, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_ACCEPTFILES), $PuTTY[$b - 1])
;~     _ChangeWindowMessageFilterEx($GUIPUTTY[$b], 0x233, 1) ; $WM_DROPFILES
;~     _ChangeWindowMessageFilterEx($GUIPUTTY[$b], $WM_COPYDATA, 1) ; redundant?
;~     _ChangeWindowMessageFilterEx($GUIPUTTY[$b], 0x0049, 1) ; $WM_COPYGLOBALDATA
        $InsertFile[$b - 2] = GUICtrlCreateLabel("", 60, 310, 100, 100, -1, $WS_EX_STATICEDGE)
        GUICtrlSetState($InsertFile, $GUI_DROPACCEPTED)
        GUICtrlSetTip($InsertFile, "Arraste arquivos aqui para enviar!" & @CRLF & @CRLF & "Clique direito para menu!")
        GUICtrlSetBkColor($InsertFile, 0xFFFFFF)
        GUISetState()
        WinSetTrans($GUIPUTTY[$b - 2], "", 40)
;~ GUISetControlsVisible($GUIPUTTY[$b-2])
        WinMove($GUIPUTTY[$b - 2], "", 238 + ($b - 2) * 700, 1, 200, 430)
    EndIf
EndFunc   ;==>_GUIPUTTY

Get started...

Couldn't test the drag & drop because i was to lazy to insert the func x) 

Tested with 3 instances of PuTTy but like this you can use how much you want :) you just have to adjust the winmove then

EDIT: The sad story on it is the For Next loop inside the GUI loop there is a way to get it with 

Case $GUIPUtty[0] To $GUIPUTTY[Ubound($GUIPUTTY)-1]

but it didn't work for me for any reason :( 

 

btw so much time actually because corona :D and yes my scripts all time are bigger and complicated as thought before ... im on a huge project but i can't script on it for long time because my head burns after few hours :D and there is still so much to do on it :( 

i'm working slowly since 3 month on it.

 

I always say it to myself: i learn so much from it and that's just a thing to make it worth :P even the script is worth on what it does later :D 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

Quote

Get started...

😨 Hayai!

I need a closer look to what you did here...

example: why you inclement 2 here

Func _GUIPUTTY()
ReDim $GUIPUTTY[$b+2]

and remove when you call the gui?

$GUIPUTTY[$b-2]

In this part:

The two "then" here are some kind of "Or"?

Local $aPutty = WinList ( "[CLASS:PuTTY]" )
If $aPutty[0][0] > 0 Then
    If $aPutty[0][0] > $b - 1 Then
For $i = 1 To $b - 1
    $PuTTY[$i] = $aPutty[$i][1]
Next
Else
For $i = 1 To $aPutty[0][0]
    $PuTTY[$i] = $aPutty[$i][1]
Next
EndIf

On the switch:

You did a search for static names, closed the switch and started a new one?
 

"previous Switch $aMsg[1]"
  EndSwitch
        For $i = 0 To $ubnd
         new   Switch $aMsg[1]


 

I always say it to myself: i learn so much from it and that's just a thing to make it worth :P even the script is worth on what it does later :D

Yeah of course! What I'm learning here will have many uses! I like a lot when I have an idea and can put to work! I'm expecting something when I finish this script too!

Link to comment
Share on other sites

1 hour ago, edumanilha said:

😨 Hayai!

I need a closer look to what you did here...

example: why you inclement 2 here

Func _GUIPUTTY()
ReDim $GUIPUTTY[$b+2]

and remove when you call the gui?

I edited it while you wrote :D had it unclean before and forgot it to change :D 

1 hour ago, edumanilha said:

 

$GUIPUTTY[$b-2]

 

 

this is necessary because i wanted to start the array on [0]

 

1 hour ago, edumanilha said:

In this part:

The two "then" here are some kind of "Or"?

Local $aPutty = WinList ( "[CLASS:PuTTY]" )
If $aPutty[0][0] > 0 Then
    If $aPutty[0][0] > $b - 1 Then
For $i = 1 To $b - 1
    $PuTTY[$i] = $aPutty[$i][1]
Next
Else
For $i = 1 To $aPutty[0][0]
    $PuTTY[$i] = $aPutty[$i][1]
Next
EndIf

 

yea a bit different way of OR because i need to switch between the "To" just for the first GUI... maybe you find a better solution.. was the first way i thought

1 hour ago, edumanilha said:

On the switch:

You did a search for static names, closed the switch and started a new one?
 

"previous Switch $aMsg[1]"
  EndSwitch
        For $i = 0 To $ubnd
         new   Switch $aMsg[1]

 

 

yes else you would loop the statics too ... should be a difference in timerinit... also i tried to loop all but it was buggy idk why exactly

 

but does it work for you generally?

 

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

Wait it's not the kind of "OR" you think i just noticed... 

If $aPutty[0][0] > 0 Then

this is if Winlist find any PuTTy session because Winlist always return an array

If $aPutty[0][0] > $b - 1 Then

this is to compare it with "$b"

Edited by Aelc

why do i get garbage when i buy garbage bags? <_<

Link to comment
Share on other sites

21 minutes ago, Aelc said:

Wait it's not the kind of "OR" you think i just noticed... 

If $aPutty[0][0] > 0 Then

this is if Winlist find any PuTTy session because Winlist always return an array

If $aPutty[0][0] > $b - 1 Then

this is to compare it with "$b"

Ohhh...I see! Thanks for all your explanations! :)

Quote

but does it work for you generally?

Yes! I can call the GUI, the right click menu and drop are there, I can get the drop message! But I have some problem with "pairing", when I open two puttys or more things get messy, the GUI2 stole the already paired Putty1...at 3 or 4 they are not pairing anymore.

Tomorrow I'll try to find out why this is happening and try the follow while part...
 

Thanks again for your great help! Good night! :D

Link to comment
Share on other sites

20 minutes ago, edumanilha said:

Ohhh...I see! Thanks for all your explanations! :)

Yes! I can call the GUI, the right click menu and drop are there, I can get the drop message! But I have some problem with "pairing", when I open two puttys or more things get messy, the GUI2 stole the already paired Putty1...at 3 or 4 they are not pairing anymore.

Tomorrow I'll try to find out why this is happening and try the follow while part...
 

Thanks again for your great help! Good night! :D

no problem 

I had the stealing problem,too. this is when the variable called in Winmove is 0 because it will move the current window then. could be the problem for other stealings, too. :)

so you need another if statement before.

Good luck for your script and maybe see ya tomorrow if necessary :P 

why do i get garbage when i buy garbage bags? <_<

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...