Jump to content

Last created control = ? + Call with variable pars


Recommended Posts

Q1

When a control is created you can refer to the last control by using -1 instead of the control id.

How do I know in my script what the last created control ID was? I know I can use enumchildwindows but I wondered if there was something like a variable similar to $Gui_CtrlId that I could use but I can't find.

Q2

I want to call a function but I don't know at design time the function name or how many parameters. The functions will already have been written and cannot be modified.

I know I can use Call("func1",$par1,$Par2), but if the function to be called has 3 parameters how can I call the function programmatically with the correct number of parameters.

To put it another way, how do I improve on this?

Function($callfunc,$NumParams,$Par1,$par2='',$par3='',$par4='')

switch $NumParams
  Case 1
   Call($callfunc,$par1)
  Case 2
   Call($callfunc,$par1,$par2)
  Case 3
   .
   .
   .
 endswitch

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

Q2

I want to call a function but I don't know at design time the function name or how many parameters. The functions will already have been written and cannot be modified.

I know I can use Call("func1",$par1,$Par2), but if the function to be called has 3 parameters how can I call the function programmatically with the correct number of parameters.

To put it another way, how do I improve on this?

Function($callfunc,$NumParams,$Par1,$par2='',$par3='',$par4='')

switch $NumParams
  Case 1
   Call($callfunc,$par1)
  Case 2
   Call($callfunc,$par1,$par2)
  Case 3
   .
   .
   .
 endswitch

endfunc
The way to do it is

$exec = "Call($callfunc"
    for $n = 1 to $NumParams
        $exec &= ", $Param" & $n
    Next
    $exec &= ")"
    Execute($exec)

Now please stop bothering me so I can get on with some work.

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

How do I know in my script what the last created control ID was?

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Get Last CtrlID - Example", 300, 200)

GUICtrlCreateButton("Button", 20, 40, 60, 20)

GUICtrlCreateLabel("Some Label", 20, 80)
GUICtrlCreateCheckbox("Some CheckBox", 20, 120)

GUISetState(@SW_SHOW, $GUI)

$iLastCtrlID = _GUIGetLastCtrlID()

MsgBox(64, "Last CtrlID", StringFormat("Last CtrlID Is: %i\nData from CtrlID: %s", $iLastCtrlID, GUICtrlRead($iLastCtrlID, 1)))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUIGetLastCtrlID()
    Local $aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))
    
    Return $aRet[0]
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

#include <GuiConstantsEx.au3>

$GUI = GUICreate("Get Last CtrlID - Example", 300, 200)

GUICtrlCreateButton("Button", 20, 40, 60, 20)

GUICtrlCreateLabel("Some Label", 20, 80)
GUICtrlCreateCheckbox("Some CheckBox", 20, 120)

GUISetState(@SW_SHOW, $GUI)

$iLastCtrlID = _GUIGetLastCtrlID()

MsgBox(64, "Last CtrlID", StringFormat("Last CtrlID Is: %i\nData from CtrlID: %s", $iLastCtrlID, GUICtrlRead($iLastCtrlID, 1)))

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _GUIGetLastCtrlID()
    Local $aRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", GUICtrlGetHandle(-1))
    
    Return $aRet[0]
EndFunc
:) Thanks MsCreatoR, that's just what I need. Excellent. That makes my script very much better; I should have known about that but I didn't.
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

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