Jump to content

how to call a button of the same application


Go to solution Solved by Werty,

Recommended Posts

Hi my friends,

 

Just to ask about to call a button of the same application

 

I have this button with this code

$__hGUI = GUICreate("PTGUI Automate V1",                 720, 900, 1920, 0, -1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST ) 

$But_check_1 = GUICtrlCreateButton("Check 1",             245, 118, 70, 25)
Local $but_check1h = GUICtrlGetHandle($But_check_1)

 

i need to click $But_check_1

 i tried using ControlClick command

 

best regards

Edited by Netol
Link to comment
Share on other sites

  • Moderators

Netol,

Why do you need to press a button in your own app? Surely all you need to is call the same code as would run if the button were pressed by an external operation.

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

 

Link to comment
Share on other sites

thanks for your responce

If it is possible to do it another way it would be great

 

i need to call this codes with only one button

 

        case $But_check_1

        case $But_check_2

        case $But_check_3

        case $But_check_4

        case $But_check_5

 

 

Edited by Netol
Link to comment
Share on other sites

  • Moderators

Netol,

That is a clear as mud.

Do you mean you wish a single button to run 5 separate checks? If so then what determines which check is run?

Please explain more clearly just what you are trying to do.

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

 

Link to comment
Share on other sites

What Melba was trying to convey is you shouldn't have to click each button, but instead run the code that occurs when a button click Msg is detected.

I imagine you have some code beneath each case...is that correct?

case $But_check_1
    ;button 1 code...
    ;...
    ;...
case $But_check_2
    ;button 2 code...
    ;...
    ;...    
case $But_check_3
    ;button 3 code...
    ;...
    ;...
case $But_check_4
    ;button 4 code...
    ;...
    ;...
case $But_check_5
    ;button 5 code...
    ;...
    ;...
Link to comment
Share on other sites

18 minutes ago, spudw2k said:

What Melba was trying to convey is you shouldn't have to click each button, but instead run the code that occurs when a button click Msg is detected.

I imagine you have some code beneath each case...is that correct?

case $But_check_1
    ;button 1 code...
    ;...
    ;...
case $But_check_2
    ;button 2 code...
    ;...
    ;...    
case $But_check_3
    ;button 3 code...
    ;...
    ;...
case $But_check_4
    ;button 4 code...
    ;...
    ;...
case $But_check_5
    ;button 5 code...
    ;...
    ;...

Yes, my code has that structure

In my case i need to execute

case $But_check_1

and them

case $But_check_2

and them

case $But_check_3

and them

case $But_check_4

and them

case $But_check_5

 

with only one button

Link to comment
Share on other sites

If you want to run 5 different code things with only one button increase a variable with each click, then use the switch command to run the code ...

something like:

#include <GUIConstants.au3>


  Local  $hGUI  =  GUICreate ( "Test" ,  300 ,  50 )
  Local  $idButton  =  GUICtrlCreateButton ( "LetsGo" ,  0 ,  0 ,  50 , 20 )
  GUICtrlSetBkColor($idButton, 0xf0f0f0)
  GUISetState ( )

$stage=-1

  While  True
    Switch  GUIGetMsg ( )
      Case  $GUI_EVENT_CLOSE
        ExitLoop
        Case  $idButton
            $stage=$stage+1
            Switch $stage
                case 0
                    WinSetTitle ($hGUI,"","Stage 0")
                    GUICtrlSetBkColor($idButton, 0xfff00)
                case 1
                    WinSetTitle ($hGUI,"","Stage 1")
                    GUICtrlSetBkColor($idButton, 0xffff80)
                case 2
                    WinSetTitle ($hGUI,"","Stage 2")
                    GUICtrlSetBkColor($idButton, 0x00ffff)
                case 3
                    $stage=-1
                    GUICtrlSetBkColor($idButton, 0xf0f0f0)
                    WinSetTitle ($hGUI,"","Test")
            EndSwitch
    EndSwitch
  WEnd

if you need to run it all in a single click ... place the code in 5 functions then do:
 

case $But_check_1
func1()
func2()
func3()
func4()
func5()

 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

I think Dan's recommendation isn't bad, but adds more complexity to account for.

I would recommend creating a function/routine for each button case; something like this:

case $But_check_1
    But1()
case $But_check_2
    But2()
case $But_check_3
    But3()
case $But_check_4
    But4()
case $But_check_5
    But5()
    
Func But1()
    ;button 1 code...
    ;...
    ;...
EndFunc

Func But2()
    ;button 2 code...
    ;...
    ;...
EndFunc

Func But3()
    ;button 3 code...
    ;...
    ;...
EndFunc

Func But4()
    ;button 4 code...
    ;...
    ;...
EndFunc

Func But5()
    ;button 5 code...
    ;...
    ;...
EndFunc

then calling the functions directly in order:

But1()
But2()
But3()
But4()
But5()
Link to comment
Share on other sites

  • Solution

How about...(the but_check_all)

#include <GUIConstants.au3>

  Local  $hGUI  =  GUICreate ( "Test" ,  300 ,  250 )
  Local  $But_check_1  =  GUICtrlCreateButton ( "Button 1" ,  10 ,  10 ,  50 , 20 )
  Local  $But_check_2  =  GUICtrlCreateButton ( "Button 2" ,  10 ,  40 ,  50 , 20 )
  Local  $But_check_3  =  GUICtrlCreateButton ( "Button 3" ,  10 ,  70 ,  50 , 20 )
  Local  $But_check_4  =  GUICtrlCreateButton ( "Button 4" ,  10 ,  100 ,  50 , 20 )
  Local  $But_check_5  =  GUICtrlCreateButton ( "Button 5" ,  10 ,  130 ,  50 , 20 )
  Local  $But_check_All  =  GUICtrlCreateButton ( "Button All" ,  10 ,  170 ,  50 , 20 )

  GUISetState ( )

  While  True
    Switch  GUIGetMsg ( )
      Case  $GUI_EVENT_CLOSE
        ExitLoop
        
    Case $But_check_1
        ;Do something
    Case $But_check_2
        ;Do something
    Case $But_check_3
        ;Do something
    Case $But_check_4
        ;Do something
    Case $But_check_5
        ;Do something
    Case $But_check_All
        ControlClick($hGUI, "", "Button 1")
        ControlClick($hGUI, "", "Button 2")
        ControlClick($hGUI, "", "Button 3")
        ControlClick($hGUI, "", "Button 4")
        ControlClick($hGUI, "", "Button 5")
    EndSwitch
  WEnd

Or in one line...

BitAND(ControlClick($hGUI, "", "Button 1"), ControlClick($hGUI, "", "Button 2"), ControlClick($hGUI, "", "Button 3"), ControlClick($hGUI, "", "Button 4"), ControlClick($hGUI, "", "Button 5"))

 

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

1 hour ago, Werty said:

How about...(the but_check_all)

#include <GUIConstants.au3>

  Local  $hGUI  =  GUICreate ( "Test" ,  300 ,  250 )
  Local  $But_check_1  =  GUICtrlCreateButton ( "Button 1" ,  10 ,  10 ,  50 , 20 )
  Local  $But_check_2  =  GUICtrlCreateButton ( "Button 2" ,  10 ,  40 ,  50 , 20 )
  Local  $But_check_3  =  GUICtrlCreateButton ( "Button 3" ,  10 ,  70 ,  50 , 20 )
  Local  $But_check_4  =  GUICtrlCreateButton ( "Button 4" ,  10 ,  100 ,  50 , 20 )
  Local  $But_check_5  =  GUICtrlCreateButton ( "Button 5" ,  10 ,  130 ,  50 , 20 )
  Local  $But_check_All  =  GUICtrlCreateButton ( "Button All" ,  10 ,  170 ,  50 , 20 )

  GUISetState ( )

  While  True
    Switch  GUIGetMsg ( )
      Case  $GUI_EVENT_CLOSE
        ExitLoop
        
    Case $But_check_1
        GUICtrlCreateLabel("Button 1", 100, 10)
    Case $But_check_2
        GUICtrlCreateLabel("Button 2", 100, 40)
    Case $But_check_3
        GUICtrlCreateLabel("Button 3", 100, 70)
    Case $But_check_4
        GUICtrlCreateLabel("Button 4", 100, 100)
    Case $But_check_5
        GUICtrlCreateLabel("Button 5", 100, 130)
    Case $But_check_All
        ControlClick($hGUI, "", "Button 1")
        ControlClick($hGUI, "", "Button 2")
        ControlClick($hGUI, "", "Button 3")
        ControlClick($hGUI, "", "Button 4")
        ControlClick($hGUI, "", "Button 5")
    EndSwitch
  WEnd

Or in one line...

BitAND(ControlClick($hGUI, "", "Button 1"), ControlClick($hGUI, "", "Button 2"), ControlClick($hGUI, "", "Button 3"), ControlClick($hGUI, "", "Button 4"), ControlClick($hGUI, "", "Button 5"))

 

Thanks to everyone who responded
This is the solution I was waiting for
Thank you so much

Link to comment
Share on other sites

2 hours ago, Werty said:
  Case $But_check_1
        GUICtrlCreateLabel("Button 1", 100, 10)
    Case $But_check_2
        GUICtrlCreateLabel("Button 2", 100, 40)
    Case $But_check_3
        GUICtrlCreateLabel("Button 3", 100, 70)
    Case $But_check_4
        GUICtrlCreateLabel("Button 4", 100, 100)
    Case $But_check_5
        GUICtrlCreateLabel("Button 5", 100, 130)

Not a huge fan of creating a new label every time a button is clicked. Seems unnecessary and a recipe for a memory leak.  Am I missing something?

Link to comment
Share on other sites

22 minutes ago, spudw2k said:

Not a huge fan of creating a new label every time

Completely agree, it was just for sake of the example, i just picked something fast, It's not what OP needed so he wont be using it, only the button part he needed, but nice call, I'll edit the example if someone else should read it and use it.

Edited by Werty

Some guy's script + some other guy's script = my script!

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