Jump to content

Locating what's calling the function


Recommended Posts

Hi everyone, I am working on a GUI Launcher as you can see. The button creation part was fine, but then i encountered this problem. How do i know which button called the function, i can set an event for it but is there any way that i know which one has called this function, button is in array so i am not making like 256 funcs, or am i missing something.

Thanks in advance.

#include<GUIConstants.au3>
#include <Math.au3>
#include<Array.au3>
Opt("GUIOnEventMode",1)
Opt("GUICloseOnEsc", 0)
Opt("GUIResizeMode", 802)

Global $Run[256],$Browse[256], $Counter=0, $WidthPos1=-199, $HeightPos1=1,$WidthPos2=-100, $HeightPos2=1
$mainfrm=GUICreate("GUI Launcher",190,55,-1,-1)
$filemenu=GUICtrlCreateMenu("File")
$fileexit=GUICtrlCreateMenuItem("Exit",$filemenu)
$createmenu=GUICtrlCreateMenu("Create")
$createitem=GUICtrlCreateMenuItem("Add Button",$createmenu)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUICtrlSetOnEvent($fileexit,"_Exit")
GUICtrlSetOnEvent($createitem,"_CreateButton")
GUISetState()
While 1
    Sleep(1)
WEnd
Func _Exit()
    Exit
EndFunc
Func _CreateButton()
    Local $WinPos=WinGetPos($mainfrm)
    $WidthPos1+=200
    $WidthPos2+=200
    $Run[$Counter]=GUICtrlCreateButton("Run"&" "&$Counter,$WidthPos1,$HeightPos1,90,30)
    GUICtrLSetOnEvent(-1,"_RunExecute")
    $Browse[$Counter]=GUICtrlCreateButton("Browse"&" "&$Counter,$WidthPos2,$HeightPos2,90,30)
    GUICtrLSetOnEvent(-1,"_BrowseDirc")
    $Counter+=1
    If _MathCheckDiv($Counter,3)=1 Then
        If $Counter>3 Then
        Else
            WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2]+205,$WinPos[3])
        EndIf
    Else
        WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2],$WinPos[3]+35)
        $WidthPos1-=600
        $WidthPos2-=600
        $HeightPos1+=35
        $HeightPos2+=35
    EndIf
EndFunc
Func _RunExecute()
    
EndFunc
Func _BrowseDirc()
    
EndFunc
Link to comment
Share on other sites

A new problem that i encountered, since i don't like creating a new topic, so i will just post here, also easier to manage.

The whole thing is basically done, at least i think so.

But then it's not working, i am bad with arrays. Can anyone point out what's the problem?

Thanks a lot.

#include<GUIConstants.au3>
#include <Math.au3>
#include<Array.au3>
Opt("GUIOnEventMode",1)
Opt("GUICloseOnEsc", 0)
Opt("GUIResizeMode", 802)

Global $Run[256],$Browse[256], $Counter=0, $WidthPos1=-199, $HeightPos1=1,$WidthPos2=-100, $HeightPos2=1, $Dir[256], $Execute[256]
$mainfrm=GUICreate("GUI Launcher",190,55,-1,-1)
$filemenu=GUICtrlCreateMenu("File")
$fileexit=GUICtrlCreateMenuItem("Exit",$filemenu)
$createmenu=GUICtrlCreateMenu("Create")
$createitem=GUICtrlCreateMenuItem("Add Button",$createmenu)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUICtrlSetOnEvent($fileexit,"_Exit")
GUICtrlSetOnEvent($createitem,"_CreateButton")
GUISetState()
While 1
    Sleep(1)
WEnd
Func _Exit()
    Exit
EndFunc
Func _CreateButton()
    Local $WinPos=WinGetPos($mainfrm)
    $WidthPos1+=200
    $WidthPos2+=200
    $Run[$Counter]=GUICtrlCreateButton("Run"&" "&$Counter,$WidthPos1,$HeightPos1,90,30)
    GUICtrLSetOnEvent(-1,"_RunExecute")
    $Browse[$Counter]=GUICtrlCreateButton("Browse"&" "&$Counter,$WidthPos2,$HeightPos2,90,30)
    GUICtrLSetOnEvent(-1,"_BrowseDirc")
    $Counter+=1
    If _MathCheckDiv($Counter,3)=1 Then
        If $Counter>3 Then
        Else
            WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2]+205,$WinPos[3])
        EndIf
    Else
        WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2],$WinPos[3]+35)
        $WidthPos1-=600
        $WidthPos2-=600
        $HeightPos1+=35
        $HeightPos2+=35
    EndIf
EndFunc
Func _RunExecute()
    Local $Id=@GUI_CtrlHandle
    For $i=0 to 255
        If $Run[$i]=$Id Then
            ShellExecute($Dir[$i])
        EndIf
    Next
EndFunc
Func _BrowseDirc()
    Local $Id=@GUI_CtrlHandle
    Local $Dirc, $String, $Display
    $Dirc=FileOpenDialog("Please Select the Exe",@DesktopDir,"All Executables (*.exe)",1+2)
    $String=StringSplit($Dirc,".")
    $String2=StringSplit($String[1],"\")
    $Display=UBound($String2,1)-1
    For $i=0 to 255
        If $Browse[$i]=$Id Then
            $Dir[$i]=$Dirc
            $Execute[$i]=$String2[$Display]
            GUICtrlSetData($Run[$i],$Execute[$i])
        EndIf
    Next
EndFunc
Link to comment
Share on other sites

i'm looking forward to this neat little software. i'm bad with arrays to so i cant help, but it looks awesome :)

The main problem seems like it's not going into the loop for some reason, i tried to put a msgbox in there to see if it goes through but it didn't.
Link to comment
Share on other sites

it seems to work until you hit the run button.. its weird, but i'm not that great with arrays so i might be wrong.

It doesn't go into the loop, if you can see after browse it's suppose to change the button name from run to the exe name you selected. But yet it didn't hapen.

Anyone else?

Link to comment
Share on other sites

It doesn't go into the loop, if you can see after browse it's suppose to change the button name from run to the exe name you selected. But yet it didn't hapen.

Anyone else?

This works, sorry to mess your code around

#include<GUIConstants.au3>
#include <Math.au3>
#include<Array.au3>
Opt("GUIOnEventMode",1)
Opt("GUICloseOnEsc", 0)
Opt("GUIResizeMode", 802)

Global $Run[256],$Browse[256], $Counter=0, $WidthPos1=-199, $HeightPos1=1,$WidthPos2=-100, $HeightPos2=1, $Dir[256], $Execute[256]
$mainfrm=GUICreate("GUI Launcher",190,55,-1,-1)
$filemenu=GUICtrlCreateMenu("File")
$fileexit=GUICtrlCreateMenuItem("Exit",$filemenu)
$createmenu=GUICtrlCreateMenu("Create")
$createitem=GUICtrlCreateMenuItem("Add Button",$createmenu)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUICtrlSetOnEvent($fileexit,"_Exit")
GUICtrlSetOnEvent($createitem,"_CreateButton")
GUISetState()
While 1
    Sleep(1)
WEnd
Func _Exit()
    Exit
EndFunc
Func _CreateButton()
    Local $WinPos=WinGetPos($mainfrm)
    $WidthPos1+=200
    $WidthPos2+=200
    $Run[$Counter]=GUICtrlCreateButton("Run"&" "&$Counter,$WidthPos1,$HeightPos1,90,30)
    GUICtrLSetOnEvent(-1,"_RunExecute")
    $Browse[$Counter]=GUICtrlCreateButton("Browse"&" "&$Counter,$WidthPos2,$HeightPos2,90,30)
    GUICtrLSetOnEvent(-1,"_BrowseDirc")
    $Counter+=1
    If _MathCheckDiv($Counter,3)=1 Then
        If $Counter>3 Then
        Else
            WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2]+205,$WinPos[3])
        EndIf
    Else
        WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2],$WinPos[3]+35)
        $WidthPos1-=600
        $WidthPos2-=600
        $HeightPos1+=35
        $HeightPos2+=35
    EndIf
EndFunc
Func _RunExecute()
    Local $Id=@GUI_CtrlHandle
    For $i=0 to 255
        If GUICtrlGetHandle($Run[$i])=$Id Then
            ShellExecute($Dir[$i])
            ExitLoop
        EndIf
    Next
EndFunc
Func _BrowseDirc()
   ;Local $Id=@GUI_CtrlHandle
    Local $Dirc, $String, $Display
    $Dirc=FileOpenDialog("Please Select the Exe",@DesktopDir,"All Executables (*.exe)",1+2)
    ConsoleWrite($dirc & @CRLF)
    $String=StringSplit($Dirc,".")
    $String2=StringSplit($String[1],"\")
    $Display=UBound($String2,1)-1
    ConsoleWrite("browsed for button " & $counter & @CRLF)
   ;For $i=0 to 255
       ;If $Browse[$i]=$Id Then
            $Dir[$Counter-1]=$Dirc
            $Execute[$Counter-1]=$String2[$Display]
            GUICtrlSetData($Run[$Counter-1], $Execute[$Counter-1])
       ;EndIf
   ;Next
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This works, sorry to mess your code around

#include<GUIConstants.au3>
#include <Math.au3>
#include<Array.au3>
Opt("GUIOnEventMode",1)
Opt("GUICloseOnEsc", 0)
Opt("GUIResizeMode", 802)

Global $Run[256],$Browse[256], $Counter=0, $WidthPos1=-199, $HeightPos1=1,$WidthPos2=-100, $HeightPos2=1, $Dir[256], $Execute[256]
$mainfrm=GUICreate("GUI Launcher",190,55,-1,-1)
$filemenu=GUICtrlCreateMenu("File")
$fileexit=GUICtrlCreateMenuItem("Exit",$filemenu)
$createmenu=GUICtrlCreateMenu("Create")
$createitem=GUICtrlCreateMenuItem("Add Button",$createmenu)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUICtrlSetOnEvent($fileexit,"_Exit")
GUICtrlSetOnEvent($createitem,"_CreateButton")
GUISetState()
While 1
    Sleep(1)
WEnd
Func _Exit()
    Exit
EndFunc
Func _CreateButton()
    Local $WinPos=WinGetPos($mainfrm)
    $WidthPos1+=200
    $WidthPos2+=200
    $Run[$Counter]=GUICtrlCreateButton("Run"&" "&$Counter,$WidthPos1,$HeightPos1,90,30)
    GUICtrLSetOnEvent(-1,"_RunExecute")
    $Browse[$Counter]=GUICtrlCreateButton("Browse"&" "&$Counter,$WidthPos2,$HeightPos2,90,30)
    GUICtrLSetOnEvent(-1,"_BrowseDirc")
    $Counter+=1
    If _MathCheckDiv($Counter,3)=1 Then
        If $Counter>3 Then
        Else
            WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2]+205,$WinPos[3])
        EndIf
    Else
        WinMove($mainfrm,"",$WinPos[0],$WinPos[1],$WinPos[2],$WinPos[3]+35)
        $WidthPos1-=600
        $WidthPos2-=600
        $HeightPos1+=35
        $HeightPos2+=35
    EndIf
EndFunc
Func _RunExecute()
    Local $Id=@GUI_CtrlHandle
    For $i=0 to 255
        If GUICtrlGetHandle($Run[$i])=$Id Then
            ShellExecute($Dir[$i])
            ExitLoop
        EndIf
    Next
EndFunc
Func _BrowseDirc()
  ;Local $Id=@GUI_CtrlHandle
    Local $Dirc, $String, $Display
    $Dirc=FileOpenDialog("Please Select the Exe",@DesktopDir,"All Executables (*.exe)",1+2)
    ConsoleWrite($dirc & @CRLF)
    $String=StringSplit($Dirc,".")
    $String2=StringSplit($String[1],"\")
    $Display=UBound($String2,1)-1
    ConsoleWrite("browsed for button " & $counter & @CRLF)
  ;For $i=0 to 255
      ;If $Browse[$i]=$Id Then
            $Dir[$Counter-1]=$Dirc
            $Execute[$Counter-1]=$String2[$Display]
            GUICtrlSetData($Run[$Counter-1], $Execute[$Counter-1])
      ;EndIf
  ;Next
EndFunc
Thanks a lot, your way inspired me and i found out what was the problem, I thought when you assign a button into a variable it returns the control handle, but then it was the ID, now it works perfectly. Thanks alot.
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...