Jump to content
Stormgrade

@GUI_CTRLID mess with my switch

Recommended Posts

Stormgrade

Hello,

I need some help with my gui, when I click on button 2 it call a MsgBox 2, but when I click on button 1 then button 2 it call a MsgBox 1.

I tear appart my code to minimal function then the error occur again ...

Here the script :

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

 AutoIt Version : 3.3.14.0
 Auteur:

 Fonction du Script :
    Modèle de Script AutoIt.

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

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>


Opt("GUIOnEventMode", 1);important pour gérer les fonctions et les gui

Global $GUI1
Global $GUI1_Label1, $GUI1_Label2
Global $GUI1_Input1, $GUI1_Input2
Global $GUI1_Bouton1, $GUI1_Bouton2, $GUI1_Bouton3

Global $GUI2 = 9999
Global $GUI2_Label1 = 9999, $GUI2_Label2 = 9999, $GUI2_Label3 = 9999
Global $GUI2_Input1 = 9999, $GUI2_Input2 = 9999, $GUI2_Input3 = 9999
Global $GUI2_Bouton1 = 9999
Global $GUI2_Checkbox1 = 9999

Global $GUI3 = 9998, $GUI3_Input1 = 9998, $GUI3_Label1 = 9998, $GUI3_Bouton1 = 9998

Global $GUI4 = 9997
Global $GUI4_List1 = 9997
Global $GUI4_Bouton1 = 9997, $GUI4_Bouton2 = 9997, $GUI4_Bouton3 = 9997, $GUI4_Bouton4 = 9997, $GUI4_Bouton5 = 9997, $GUI4_Bouton6 = 9997, $GUI4_Bouton7 = 9997

Global $GUI9 = 5689
Global $GUI9_Input1 = 5689, $GUI9_Input2 = 5689, $GUI9_Input3 = 5689, $GUI9_Input4 = 5689
Global $GUI9_Label1 = 5689, $GUI9_Label2 = 5689, $GUI9_Label3 = 5689, $GUI9_Label4 = 5689
Global $GUI9_Bouton1 = 5689

Global $GUI6 = 9995
Global $GUI6_Label1 = 9995, $GUI6_Label2 = 9995, $GUI6_Label3 = 9995
Global $GUI6_Input1 = 9995, $GUI6_Input2 = 9995, $GUI6_Input3 = 9995
Global $GUI6_Bouton1 = 9995
Global $GUI6_Checkbox1 = 9995

Global $GUI7 = 9994
Global $GUI7_Label1 = 9994, $GUI7_Label2 = 9994, $GUI7_Label3 = 9994
Global $GUI7_Input1 = 9994, $GUI7_Input2 = 9994, $GUI7_Input3 = 9994
Global $GUI7_Bouton1 = 9994, $GUI7_Bouton2 = 9994, $GUI7_Bouton3 = 9994
Global $GUI7_Checkbox1 = 9994


Global $MyQuery, $MyQueryRow
Global $TempDataEncryptage, $TempDataDecryptage
Global $Input1_Read, $Input2_Read, $Input3_Read, $Input4_Read
Global $aSQLResult, $iRows, $iColumns, $iRval
Global $GUI4_List1_Indice, $GUI4_List1_Item


GUI1_Principal()

Func GUI1_Principal();fenêtre principale
    $GUI1 = GUICreate("Password Manager", 266, 120, 786, 412)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI1_Label1 = GUICtrlCreateLabel("Login", 24, 12, 30, 18)
    $GUI1_Label2 = GUICtrlCreateLabel("Password", 8, 44, 50, 18)

    $GUI1_Bouton1 = GUICtrlCreateButton("OUVRIR", 192, 8, 58, 58)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI1_Bouton2 = GUICtrlCreateButton("Change Password", 144, 72, 114, 34)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI1_Bouton3 = GUICtrlCreateButton("Change Login", 8, 72, 114, 34)
    GUICtrlSetOnEvent(-1, "On_Button")

    $GUI1_Input1 = GUICtrlCreateInput("", 64, 8, 114, 22)
    $GUI1_Input2 = GUICtrlCreateInput("", 64, 40, 114, 22)

    GUISetState()

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>GUI1_Principal

Func GUI2_change_password();changer mot de passe
    $GUI2 = GUICreate("Change Password", 284, 152, 721, 395)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI2_Label1 = GUICtrlCreateLabel("Last Password", 8, 12, 74, 18)
    $GUI2_Label2 = GUICtrlCreateLabel("New Password", 8, 44, 76, 18)
    $GUI2_Label3 = GUICtrlCreateLabel("Check Password", 8, 76, 84, 18)

    $GUI2_Input1 = GUICtrlCreateInput("", 120, 8, 154, 22)
    $GUI2_Input2 = GUICtrlCreateInput("", 120, 40, 154, 22)
    $GUI2_Input3 = GUICtrlCreateInput("", 120, 72, 154, 22)

    $GUI2_Bouton1 = GUICtrlCreateButton("VALIDATE", 136, 104, 114, 34)
    GUICtrlSetOnEvent(-1, "On_Button")

    $GUI2_Checkbox1 = GUICtrlCreateCheckbox("Display Password", 8, 112, 114, 18)
    GUICtrlSetOnEvent(-1, "On_Checkbox")

    GUISetState()
EndFunc ;=>GUI2_change_password

Func GUI3_change_login();changer login
    $GUI3 = GUICreate("Change Login", 240, 102, 674, 392)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI3_Input1 = GUICtrlCreateInput("", 88, 16, 114, 22)

    $GUI3_Label1 = GUICtrlCreateLabel("New Login", 16, 20, 56, 18)

    $GUI3_Bouton1 = GUICtrlCreateButton("VALIDATE", 88, 48, 114, 34)
    GUICtrlSetOnEvent(-1, "On_Button")

    GUISetState()
EndFunc ;=>GUI3_change_login

Func GUI4_Manager();manager
    $GUI4 = GUICreate("Password Manager", 528, 282, 690, 294)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")


    $GUI4_List1 = GUICtrlCreateListView("", 16, 16, 426, 188)

    $GUI4_Bouton1 = GUICtrlCreateButton("Add Entry", 16, 216, 98, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton2 = GUICtrlCreateButton("Modify Entry", 120, 216, 98, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton3 = GUICtrlCreateButton("Delete Entry", 232, 216, 98, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton4 = GUICtrlCreateButton("View", 344, 216, 98, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton5 = GUICtrlCreateButton("Trie A/z", 464, 16, 50, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton6 = GUICtrlCreateButton("Trie Z/a", 464, 152, 50, 50)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI4_Bouton7 = GUICtrlCreateButton("PG", 464, 84, 49, 49)
    GUICtrlSetOnEvent(-1, "On_Button")

    GUISetState()
EndFunc ;=>GUI4_Manager

Func GUI5_Add();add entry
    $GUI9 = GUICreate("Add an entry", 304, 192, 666, 358)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI9_Input1 = GUICtrlCreateInput("", 112, 16, 178, 22)
    $GUI9_Input2 = GUICtrlCreateInput("", 112, 48, 178, 22)
    $GUI9_Input3 = GUICtrlCreateInput("", 112, 80, 178, 22)
    $GUI9_Input4 = GUICtrlCreateInput("", 112, 112, 178, 22)

    $GUI9_Label1 = GUICtrlCreateLabel("Name", 8, 20, 32, 18)
    $GUI9_Label2 = GUICtrlCreateLabel("Login", 8, 52, 30, 18)
    $GUI9_Label3 = GUICtrlCreateLabel("Password", 8, 84, 50, 18)
    $GUI9_Label4 = GUICtrlCreateLabel("Retape Password", 8, 116, 88, 18)

    $GUI9_Bouton1 = GUICtrlCreateButton("Validate", 112, 144, 114, 34); <================== problem
    GUICtrlSetOnEvent($GUI9_Bouton1, "On_Button")

    GUISetState()
EndFunc ;=>GUI5_Add

Func GUI6_MOD();mod entry
    $GUI6 = GUICreate("Modify Entry", 288, 166, 572, 306)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI6_Label1 = GUICtrlCreateLabel("Name", 8, 20, 32, 18)
    $GUI6_Label2 = GUICtrlCreateLabel("Login", 8, 52, 30, 18)
    $GUI6_Label3 = GUICtrlCreateLabel("Password", 8, 84, 50, 18)

    $GUI6_Input1 = GUICtrlCreateInput("", 80, 16, 194, 22)
    $GUI6_Input2 = GUICtrlCreateInput("", 80, 48, 194, 22)
    $GUI6_Input3 = GUICtrlCreateInput("", 80, 80, 194, 22)

    $GUI6_Bouton1 = GUICtrlCreateButton("Modify", 160, 120, 114, 34)
    GUICtrlSetOnEvent(-1, "On_Button")

    $GUI6_Checkbox1 = GUICtrlCreateCheckbox("Show Password", 40, 128, 100, 18)
    GUICtrlSetOnEvent(-1, "On_Checkbox")

    GUISetState()
EndFunc ;=>GUI6_MOD

Func GUI7_VIEW();view entry
    $GUI7 = GUICreate("View", 398, 112, 590, 298)
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close")

    $GUI7_Label1 = GUICtrlCreateLabel("Name", 8, 12, 32, 18)
    $GUI7_Label2 = GUICtrlCreateLabel("Login", 8, 44, 30, 18)
    $GUI7_Label3 = GUICtrlCreateLabel("Password", 8, 76, 50, 17)

    $GUI7_Input1 = GUICtrlCreateInput("", 80, 8, 218, 22)
    $GUI7_Input2 = GUICtrlCreateInput("", 80, 40, 218, 22)
    $GUI7_Input3 = GUICtrlCreateInput("", 80, 72, 218, 22)

    $GUI7_Bouton1 = GUICtrlCreateButton("Copy", 312, 40, 66, 26)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI7_Bouton2 = GUICtrlCreateButton("Copy", 312, 72, 66, 26)
    GUICtrlSetOnEvent(-1, "On_Button")
    $GUI7_Bouton3 = GUICtrlCreateButton("GO", 312, 6, 34, 26)
    GUICtrlSetOnEvent(-1, "On_Button")

    $GUI7_Checkbox1 = GUICtrlCreateCheckbox("", 360, 12, 16, 16)
    GUICtrlSetOnEvent(-1, "On_Checkbox")

    GUISetState()
EndFunc ;=>GUI7_VIEW

Func On_Button();gestion de tout les boutons
    Switch @GUI_CTRLID

        ;### Navigation ###
        Case $GUI1_Bouton1
            GUI4_Manager()


        Case $GUI1_Bouton2
            GUI2_change_password()
        Case $GUI1_Bouton3
            GUI3_change_login()
        Case $GUI4_Bouton1
            GUI5_Add()
        Case $GUI4_Bouton2
            GUI6_MOD()
        Case $GUI4_Bouton4

                GUI7_VIEW()


        ;#################

        Case $GUI2_Bouton1

        Case $GUI3_Bouton1


        Case $GUI9_Bouton1; <================== problem

                MsgBox(64,"Erreur de sécurité 5","Les mots de passe ================================= sont différents.",5)


        Case $GUI7_Bouton1
            ;_ClipBoard_SetData($Input2_Read,$CF_TEXT)
        Case $GUI7_Bouton2
            ;_ClipBoard_SetData($Input3_Read,$CF_TEXT)
        Case $GUI7_Bouton3
            If _IsValidURL($Input1_Read) = 1 Then
                ShellExecute($Input1_Read)
            Else
                MsgBox(64,"Erreur lien","L'URL ne semble pas valide.")
            EndIf

    EndSwitch
EndFunc ;=>On_Button

Func On_Checkbox();gestion des checkbox



EndFunc ;=>On_Checkbox

Func On_Close();gestion fermeture des fenêtres
    Switch @GUI_WINHANDLE
        Case $GUI1

            Exit
        Case $GUI2
            GUIDelete($GUI2)
        Case $GUI3
            GUIDelete($GUI3)
        Case $GUI4
            GUIDelete($GUI4)
        Case $GUI9
            GUIDelete($GUI9)
        Case $GUI6
            GUIDelete($GUI6)
        Case $GUI7
            GUIDelete($GUI7)
    EndSwitch
EndFunc ;=>On_Close


Func _IsValidURL($url)
    Local $IsValid = StringRegExp($url,"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$")
    Return ($IsValid)
EndFunc ;=>_IsValidURL

 

 The error :

Run my script, click on "OUVRIR" then click on "View" and click on "GO" you get a message : "L'URL ne semble pas valide."

Now close the view menu, click on "Add entry" , close this menu , click on "View" and click on "GO" you get another message : "Les mots de passe ================================= sont différents."

This message must only appear when you click on "Validate" in the "Add entry" menu ....

I had the same problem on another PC with AutoIT 3.3.14.0

I've changed my variable, add another button , etc... The problem occur only with this two menus and this button.

Can you test it ? If you don't have this error perhaps my AutoIT package (installer form AutoIT fr) have a problem.

Thank you.

Share this post


Link to post
Share on other sites
Melba23

Stormgrade,

The problem occurs because you are constantly creating and deleting GUIs and their controls. When you delete a control (such as by deleting the GUI that holds it) you leave an empty entry in the internal array that AutoIt uses to track the controls it creates - the index of a control in this array is the ControlID that is returned by the GUICtrlCreate* function.

So when you create one of your subsidiary GUIs the controls within it use the first available open entries in this array - and these indicies will be returned as ControlIDs. When you delete the GUI these entries are cleared, when you create the next GUI the controls will also use those entries and so have those ControlIDs - but the variables holding the ControlIDs of the now-deleted controls will still hold the same value, even though the control itself has been deleted. Then when you run your Switch, the first variable to match will fire - and in this  case it is one which refers to a deleted control.

The solution? Create all the GUIs just once at the beginning of the script and hide/show as required - or set all the variables used to store ControlIDs back to their placeholder values (as you do at the beginning of the script) when you delete a GUI. I know which is the simpler solution.

Please ask if anything is still unclear.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Stormgrade

Thank you !!!!!!!!!!!

I set all the variables used to store ControlID in the "On_close" function like this :

Func On_Close();gestion fermeture des fenêtres
    Switch @GUI_WINHANDLE
        Case $GUI1
            Exit
        Case $GUI2
            GUIDelete($GUI2)
            $GUI2 = 9999
            $GUI2_Label1 = 9999
            $GUI2_Label2 = 9999
            $GUI2_Label3 = 9999
            $GUI2_Input1 = 9999
            $GUI2_Input2 = 9999
            $GUI2_Input3 = 9999
            $GUI2_Bouton1 = 9999
            $GUI2_Checkbox1 = 9999
        Case $GUI3
            GUIDelete($GUI3)
            $GUI3 = 9998
            $GUI3_Input1 = 9998
            $GUI3_Label1 = 9998
            $GUI3_Bouton1 = 9998
        Case $GUI4
            GUIDelete($GUI4)
            $GUI4 = 9997
            $GUI4_List1 = 9997
            $GUI4_Bouton1 = 9997
            $GUI4_Bouton2 = 9997
            $GUI4_Bouton3 = 9997
            $GUI4_Bouton4 = 9997
            $GUI4_Bouton5 = 9997
            $GUI4_Bouton6 = 9997
            $GUI4_Bouton7 = 9997

        Case $GUI9
            GUIDelete($GUI9)
            $GUI9 = 5689
            $GUI9_Input1 = 5689
            $GUI9_Input2 = 5689
            $GUI9_Input3 = 5689
            $GUI9_Input4 = 5689
            $GUI9_Label1 = 5689
            $GUI9_Label2 = 5689
            $GUI9_Label3 = 5689
             $GUI9_Label4 = 5689
            $GUI9_Bouton1 = 5689
        Case $GUI6
            GUIDelete($GUI6)
            $GUI6 = 9995
            $GUI6_Label1 = 9995
            $GUI6_Label2 = 9995
            $GUI6_Label3 = 9995
            $GUI6_Input1 = 9995
            $GUI6_Input2 = 9995
            $GUI6_Input3 = 9995
            $GUI6_Bouton1 = 9995
            $GUI6_Checkbox1 = 9995
        Case $GUI7
            GUIDelete($GUI7)
            $GUI7 = 9994
             $GUI7_Label1 = 9994
             $GUI7_Label2 = 9994
            $GUI7_Label3 = 9994
            $GUI7_Input1 = 9994
            $GUI7_Input2 = 9994
            $GUI7_Input3 = 9994
            $GUI7_Bouton1 = 9994
            $GUI7_Bouton2 = 9994
            $GUI7_Bouton3 = 9994
            $GUI7_Checkbox1 = 9994
    EndSwitch
EndFunc ;=>On_Close

 

 Do you think I just need to do that ? It make me crazy to try to find the error but it seem to work like a charm now :)

Share this post


Link to post
Share on other sites
Melba23

Stormgrade,

That should work - but I would suggest that the other method I mentioned (creating all the GUIs and then hiding/showing them as required) would be much easier.

Or you could use my GUIExtender UDF to place all the sections within the same GUI and expand/retract the correct section when needed - let me know if you would like some help getting that idea to work.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Stormgrade

Thank you for your advice, I've used the AutoIt wiki to manage multiple GUI, If I use :

GUISetState(@SW_HIDE, $GUI5)

 GUISetState(@SW_SHOW, $GUI5)

I must "rethink" all I'had done with the GUis.

I've already used your UDF for a protoype, it's very useful for hiding showing GUI inside a GUI but I don't intend to make a password manager inside one GUI.

Share this post


Link to post
Share on other sites
Melba23

Stormgrade,

That sounds like you have got the measure of the problem - glad I could help you get there.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Similar Content

    • Sven-Seyfert
      By Sven-Seyfert
      Hi Community,

      I use a UDF by @smashly to play a video in a GUI. That works fine for my main monitor.
      But when I change the X and Y positions of the GUI (also for the video) to my second or third monitor, the video plays, I can hear the sound of it, but I don't see the video.

      I debugged the UDF and checked the Microsoft description for MCI Command Strings which are used in the UDF (docs.microsoft...) - everything is fine, so I got no clue why the video isn't displayed.

      PlayVideoTest.au3:
       
      VideoInGui_by_Smashky.au3 (UDF):
       
      The example video:
       
      It would be great when anyone can help .
      Is there maybe a other way to play (display videos in GUI)?

      Thanks for any suggestion - I'm grateful!
      Sven
    • TheAutomator
      By TheAutomator
      Is there a (simple) way to make your script using a picture-control to resize the gui?
      This would be useful for a transparant pop-up window with a custom made theme using picture controls:
      $Form = GUICreate('', 301, 173, 5, 5, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUICtrlCreatePic(@scriptdir & "\resize_win.bmp", 0, 73, 20, 51) ; some api call or code telling the os to use this picture as a resize border GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While True if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit WEnd  
      EDIT: to make it more clear what i wanna do, if you go with the mouse arrow over the border of a re-sizable window the arrow changes to a "resize" arrow, you click and drag the border and then the window size adjusts to the mouse position until you release the mouse button.
      I want my picture control to be used the same way as the resize border to resize my window.
    • UEZ
      By UEZ
      Following script shows a parent GUI with a child GUI initialized as MDICHILD.
      #include <Constants.au3> #include <GUIConstantsEx.au3> #include <GuiReBar.au3> #include <GuiScrollBars.au3> #include <GuiToolbar.au3> #include <ScreenCapture.au3> #include <ScrollBarConstants.au3> #include <WindowsConstants.au3> _GDIPlus_Startup() Global Enum $idNew = 1000, $idOpen, $idSave, $idHelper Global Const $iImageW = @DesktopWidth, $iImageH = @DesktopHeight Global Const $hBMP_ScreenCapture = _ScreenCapture_Capture("", 0, 0, $iImageW, $iImageH, False) Global Const $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP_ScreenCapture) Sleep(50) Global Const $iW = 1500, $iH = 700, $SC_DRAGMOVE = 0xF012 Global Const $hGUI = GUICreate("Move child GUI within GUI", $iW, $iH) Global Const $hToolbar = _GUICtrlToolbar_Create($hGUI) Global Const $hReBar = _GUICtrlRebar_Create($hGUI, BitOR($CCS_TOP, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) Global Const $height_delta = 37 Global Const $idPic = GUICtrlCreatePic("", 0, $height_delta + 2, $iW, $iH) Global $hBitmap_tmp, $hHBitmap_tmp $hBitmap_tmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global $hGfx_Context = _GDIPlus_ImageGetGraphicsContext($hBitmap_tmp) _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) _GUICtrlToolbar_AddButton($hToolbar, $idNew, $STD_FILENEW) _GUICtrlToolbar_AddButton($hToolbar, $idOpen, $STD_FILEOPEN) _GUICtrlToolbar_AddButton($hToolbar, $idSave, $STD_FILESAVE) _GUICtrlToolbar_AddButtonSep($hToolbar) _GUICtrlToolbar_AddButton($hToolbar, $idHelper, $STD_HELP) _GUICtrlRebar_AddToolBarBand($hReBar, $hToolbar, "", 0) Global Const $iVSscroll = _WinAPI_GetSystemMetrics(2) Global Const $iHSscroll = _WinAPI_GetSystemMetrics(3) Global Const $iYCaption = _WinAPI_GetSystemMetrics(4) Global Const $iYFixedFrame = _WinAPI_GetSystemMetrics(8) Global Const $iXFixedFrame = _WinAPI_GetSystemMetrics(7) Global Const $iMetricsSumX = $iVSscroll + $iXFixedFrame * 2 Global Const $iMetricsSumY = $iHSscroll + $iYCaption + $iYFixedFrame _GUIScrollBars_Init($hGUI) _GUIScrollBars_SetScrollInfoMin($hGUI, $SB_HORZ, 0) _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_HORZ, $iImageW - $iW + 61 + $iMetricsSumX) _GUIScrollBars_SetScrollInfoMin($hGUI, $SB_VERT, 0) _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $iImageH - $iH + $iMetricsSumY + $height_delta - 1) GUISetState(@SW_SHOW, $hGUI) Global Const $STM_SETIMAGE = 0x0172 _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP_ScreenCapture)) Global $IE_offset_x = 0, $IE_offset_y = 0 DrawImage($hGfx_Context, $hBitmap, $IE_offset_x, $IE_offset_y, $iW, $iH) GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL_IE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL_IE") Global $iPosX_Crop = 0, $iPosY_Crop = 0, $iW_crop = 200, $iH_crop = 200, $bMove_Crop = True Global $hGUI_IE_Crop = GUICreate("", $iW_crop, $iH_crop, $iPosX_Crop, $iPosY_Crop) GUISetStyle(BitOR($WS_BORDER, $WS_POPUP), $WS_EX_MDICHILD) _WinAPI_SetParent($hGUI_IE_Crop, $hGUI) WinSetTrans($hGUI_IE_Crop, "", 0xA0) Global $iLable_CropMove = GUICtrlCreateLabel("", 0, 0, $iW_crop, $iH_crop, -1, $GUI_WS_EX_PARENTDRAG) GUISetState(@SW_SHOW, $hGUI_IE_Crop) GUIRegisterMsg($WM_MOVE, "WM_MOVE_IE_GUI_Crop") ;~ GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Until False GUIRegisterMsg($WM_HSCROLL, "") GUIRegisterMsg($WM_VSCROLL, "") GUIRegisterMsg($WM_MOVE, "") GUIRegisterMsg($WM_LBUTTONDOWN, "") _WinAPI_DeleteObject($hBMP_ScreenCapture) _GDIPlus_BitmapDispose($hBitmap_tmp) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hGfx_Context) _GDIPlus_Shutdown() Exit Func WM_HSCROLL_IE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $lParam Local $Min, $Max, $Page, $TrackPos ; Get all the horizontal scroll bar information Local $tSCROLLINFO_X = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO_X, "nMin") $Max = DllStructGetData($tSCROLLINFO_X, "nMax") $Page = DllStructGetData($tSCROLLINFO_X, "nPage") ; Save the position for comparison later on $IE_offset_x = DllStructGetData($tSCROLLINFO_X, "nPos") $TrackPos = DllStructGetData($tSCROLLINFO_X, "nTrackPos") #forceref $Min, $Max Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x - $Page) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box DllStructSetData($tSCROLLINFO_X, "nPos", $IE_offset_x + $Page) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO_X, "nPos", $TrackPos) EndSwitch DllStructSetData($tSCROLLINFO_X, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO_X) $IE_offset_x = DllStructGetData($tSCROLLINFO_X, "nPos") DrawImage($hGfx_Context, $hBitmap, $IE_offset_x, $IE_offset_y, $iW, $iH) $hHBitmap_tmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_tmp) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_tmp)) _WinAPI_DeleteObject($hHBitmap_tmp) $bMove_Crop = False ConsoleWrite($iPosX_Crop & ", " & $iPosY_Crop & " / " & $IE_offset_x & ", " & $IE_offset_y & @CRLF) WinMove($hGUI_IE_Crop, "", -$IE_offset_x + $iPosX_Crop, -$IE_offset_y + $iPosY_Crop) ;~ DllCall("user32.dll", "bool", "MoveWindow", "hwnd", $hGUI_IE_Crop, "int", -$IE_offset_x + $iPosX_Crop, "int", -$IE_offset_y + $iPosY_Crop, "int", $iW_crop, "int", $iH_crop, "bool", True) $bMove_Crop = True Return "GUI_RUNDEFMSG" EndFunc ;==>WM_HSCROLL_IE Func WM_VSCROLL_IE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $lParam Local $Min, $Max, $Page, $TrackPos ;~ ; Get all the horizontal scroll bar information Local $tSCROLLINFO_Y = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT) $Min = DllStructGetData($tSCROLLINFO_Y, "nMin") $Max = DllStructGetData($tSCROLLINFO_Y, "nMax") $Page = DllStructGetData($tSCROLLINFO_Y, "nPage") ; Save the position for comparison later on $IE_offset_y = DllStructGetData($tSCROLLINFO_Y, "nPos") $TrackPos = DllStructGetData($tSCROLLINFO_Y, "nTrackPos") #forceref $Min, $Max Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y - $Page) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of the scroll box DllStructSetData($tSCROLLINFO_Y, "nPos", $IE_offset_y + $Page) Case $SB_THUMBTRACK ; user dragged the scroll box DllStructSetData($tSCROLLINFO_Y, "nPos", $TrackPos) EndSwitch DllStructSetData($tSCROLLINFO_Y, "fMask", $SIF_POS) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO_Y) $IE_offset_y = DllStructGetData($tSCROLLINFO_Y, "nPos") DrawImage($hGfx_Context, $hBitmap, $IE_offset_x, $IE_offset_y, $iW, $iH) $bMove_Crop = False ConsoleWrite($iPosX_Crop & ", " & $iPosY_Crop & " / " & $IE_offset_x & ", " & $IE_offset_y & @CRLF) WinMove($hGUI_IE_Crop, "", -$IE_offset_x + $iPosX_Crop, -$IE_offset_y + $iPosY_Crop) ;~ DllCall("user32.dll", "bool", "MoveWindow", "hwnd", $hGUI_IE_Crop, "int", -$IE_offset_x + $iPosX_Crop, "int", -$IE_offset_y + $iPosY_Crop, "int", $iW_crop, "int", $iH_crop, "bool", True) $bMove_Crop = True Return "GUI_RUNDEFMSG" EndFunc ;==>WM_VSCROLL_IE Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) _SendMessage($hGUI_IE_Crop, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndFunc ;==>_WM_LBUTTONDOWN Func WM_MOVE_IE_GUI_Crop($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam If $hWnd = $hGUI_IE_Crop And $bMove_Crop Then $iPosX_Crop = _WinAPI_LoWord($lParam) $iPosY_Crop = _WinAPI_HiWord($lParam) EndIf Return "GUI_RUNDEFMSG" EndFunc ;==>WM_MOVE_IE_GUI_Crop Func WM_SIZE_IE_GUI_Crop($hWnd, $iMsg, $wParam, $lParam) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE_IE_GUI_Crop Func DrawImage($hGfx_Context, $hBitmap, $IE_offset_x, $IE_offset_y, $iW, $iH) _GDIPlus_GraphicsDrawImageRectRect($hGfx_Context, $hBitmap, $IE_offset_x, $IE_offset_y, $iW, $iH, 0, 0, $iW, $iH) $hHBitmap_tmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap_tmp) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_tmp)) _WinAPI_DeleteObject($hHBitmap_tmp) EndFunc  
      My problem: if you move the child window at left upper corner to another place and move either H or V scrollbar the child GUI will be moved properly. BUT if you have scrolled the scrollbars to the right bottom of the image and move the child GUI to that corner, too then the child GUI jumps if you click on one of the scrollbars.
      Is there something that I didn't consider?
    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • MJ36
      By MJ36

      How to click this button ? 
      I Try 
       
      func test () $oCorrectObj = "" $tags = $oIE.document.GetElementsByTagName("button") For $tag in $tags $class_value = $tag.GetAttribute("type") If string($class_value) = "buttont" Then $oCorrectObj = $tag MsgBox(0, "Level: ", "Level found :)") Else MsgBox(16, "Failed", "Not found.") ExitLoop EndIf Next If IsObj ( $oCorrectObj ) Then _IEAction ($oCorrectObj, "click") EndIF  
      and
       
      func klik () Local $oFound = "" Local $oBtns = _IETagNameGetCollection($oIE, "span") For $oBtn In $oBtns If String($oBtn.classname) = "yt-uix-button-content" Then $oFound = $oBtn EndIf Next _IEAction ($oFound, "click") EndFunc  
      Please Help 
      Can you click it by name?
×