thepip3r Posted January 23, 2008 Share Posted January 23, 2008 http://www.autoitscript.com/autoit3/docs/f...lSetOnEvent.htmScoured the online content and couldn't find any forum postings related to it. I'm trying to find a way to pass a path to a function when using GUICtrlSetOnEvent. It seems like it should be able to work but I can't seem to make it work. Can anyone help me out?If this is my function for running the path (I realize there's uneeded code/unfinished code -- I'm just tyring to get this to work initially):Func __FileOpen($path="") MsgBox(0,"",$path) If $path <> "" Then ShellExecute($path) EndIf EndFuncI'm trying to use GUICtrlSetOnEvent to execute the path when clicked, and here's how I'm trying to accomplish this in my loop:$tf = $fp & "\" & $file If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") EndIf EndIf...where $tf is the Total File of the file path and the file name (including extension (theoretically getting the absolute path to the file)). My problem is that if I can't pass an argument to my function, I can't figure out how to make Autoit do what I'm looking to do. When I try to pass an argument to my function (as in the code example above), I get an error stating that __FileOpen($fp) is an unknown function. But again, if I can't pass an arugment to the function inside of GUICtrlSetOnEvent, can anyone point me in the right direction as how I get a path executed on a button click when my buttons are created dynamically in a loop? TIA My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
blademonkey Posted January 23, 2008 Share Posted January 23, 2008 i am also interested in a solution to this. ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung Link to comment Share on other sites More sharing options...
rover Posted January 23, 2008 Share Posted January 23, 2008 just declare a Global variable for use in the function Opt("RunErrorsFatal", 0) ; silent error for shellexecute, place at top of script below includes Global $tf ; global var for use in function, place with rest of global vars at top of script ; declared vars and rest of script here $tf = $fp & "\" & $file If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__FileOpen") Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__FileOpen") EndIf EndIf Func __FileOpen() MsgBox(0,"",$tf) If $tf <> "" Then ShellExecute($tf) SetError(@error) ; set error return from shellexecute Else SetError(0) EndIf ;$tf = "" EndFunc I see fascists... Link to comment Share on other sites More sharing options...
thepip3r Posted January 23, 2008 Author Share Posted January 23, 2008 yeah but that won't work. take for instance, my loop is looping through a bunch of files and paths. if i continually reset the a global var to a different value, by the time my program is rendered, each button will all click the exact same path (that of the last value of $tf).... right? My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
rover Posted January 23, 2008 Share Posted January 23, 2008 if you want to reuse the same function for more than one menu item then you need to use @GUI_CTRLID in the function to identify which menu item was used to run the function and use more than one global var for path/file you don't show a loop in your example and only one menu item i assume you are presetting or user is selecting filename elsewhere in your script? I see fascists... Link to comment Share on other sites More sharing options...
thepip3r Posted January 23, 2008 Author Share Posted January 23, 2008 (edited) here is the entire functions so u can see how it works: __DirtoMenu("C:\Documents and Settings\All Users\Start Menu\Programs",$menuAllProgsParent) Func __DirtoMenu($fp,$menu) Dim $arrFile,$newMenu,$val,$fp,$file,$search,$menu,$fileAttrib,$menuTempParent $search = FileFindFirstFile($fp & "\*.*") If $search = -1 Then GUICtrlCreateMenuItem("<Parsing Error>",$menuTempParent) While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $tf = $fp & "\" & $file $fileAttrib = FileGetAttrib($tf) If @error Then GUICtrlCreateMenuItem("<Parsing Error>",$menuTempParent) ExitLoop Else If StringInStr($fileAttrib, "D") Then $newMenu = GUICtrlCreateMenu($file,$menu) __DirtoMenu($tf,$newMenu) Else If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") EndIf EndIf EndIf EndIf WEnd FileClose($search) EndFunc the function iterates a passed directory and does a recursive loop to auto generate a menu -> submenu structure but when it comes to a file of sorts, I was that button, onclick, to run or shellrun that absolute path. so my problem is trying to store that absolute path in the button or create some intelligent method of managing associating the button name with the path, etc... does that clear it up at all? Edited January 23, 2008 by thepip3r My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
ptrex Posted January 23, 2008 Share Posted January 23, 2008 @all Would this get you going. $tf = $fp & "\" & $file If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__FileOpen_tf") EndIf EndIf Func __FileOpen_tf() __FileOpen($tf) EndFunc Func __FileOpen($path="") MsgBox(0,"",$path) If $path <> "" Then ShellExecute($path) EndIf EndFunc regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
rover Posted January 23, 2008 Share Posted January 23, 2008 (edited) looks like you need a 2d array of path\filenames matched to control ids of menu items col1 path\filename col2 menuitem control id then use switch/case with @GUI_CTRLID in your __FileOpen() function Edit: ok scrub the above suggestion look at the GUIMenuManagement UDF's set menuentry number when creating menu items, then when menu item is clicked and function is run, get ctrlid and use that to get text from menu item and shell execute that. Edited January 23, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
thepip3r Posted January 23, 2008 Author Share Posted January 23, 2008 i'm off for a bit but will try to implement changes and test tomorrow rover and ptrex... ty for the help. My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 23, 2008 Share Posted January 23, 2008 (edited) That just won't work: Opt("GuiOnEventMode", 1) $hGUI = GUICreate("Test", 400, 300) GUISetOnEvent(-3, "_Quit") $menu = GUICtrlCreateMenu("Test") $fp = "C:\temp" $file = "TestFile.url" $tf = $fp & "\" & $file If $file <> "desktop.ini" Then If StringRight($file,4) = ".lnk" Or StringRight($file,4) = ".url" Then GUICtrlCreateMenuItem(StringTrimRight($file,4),$menu) GUICtrlSetOnEvent(-1,"__FileOpen($tf)") Else GUICtrlCreateMenuItem($file,$menu) GUICtrlSetOnEvent(-1,"__FileOpen_tf") EndIf EndIf GUISetState() While 1 Sleep(20) WEnd Func __FileOpen_tf() __FileOpen($tf) EndFunc Func __FileOpen($path="") MsgBox(0,"__FileOpen()","$path = " & $path) EndFunc Func _Quit() Exit EndFunc Result (ignoring the syntax checker error to run it): +>08:11:35 Starting AutoIt3Wrapper v.1.9.4 >Running AU3Check (1.54.10.0) from:C:\Program Files\AutoIt3 C:\Program Files\AutoIt3\Scripts\Test_1.au3(11,47) : ERROR: __FileOpen($tf)(): undefined function. GUICtrlSetOnEvent(-1,"__FileOpen($tf)") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\Program Files\AutoIt3\Scripts\Test_1.au3 - 1 error(s), 0 warning(s) !>08:11:35 AU3Check ended.rc:2 >Running:(3.2.10.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Program Files\AutoIt3\Scripts\Test_1.au3" C:\Program Files\AutoIt3\Scripts\Test_1.au3 (11) : ==> Unknown function name.: GUICtrlSetOnEvent(-1,"__FileOpen($tf)") ->08:11:38 AutoIT3.exe ended.rc:1 +>08:11:38 AutoIt3Wrapper Finished Edit: Tweaked demo to run the bad case (file ends in .url). Edited January 23, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
thepip3r Posted January 25, 2008 Author Share Posted January 25, 2008 just wanted to say ty gents and especially Rover. the 2d array idea works like a charm. thanx for the assistance. =D My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now