Sign in to follow this  
Followers 0
peter1234

need help with FileOpenDialog (my first GUI)

10 posts in this topic

#1 ·  Posted (edited)

When I use FileOpenDialog all of the relative addresses of the files in my GUI are set to the folder that it opens. How do I get the relative address to refer to my GUI folder again? This is what I have tried, where the UPDATE function uses FileOpenDialog to find the file to process. But this does not work. As you might guess, I am not an experienced programmer but I really want to learn how to use AutoIt. Also, how do I get my code to go in a box when I am posting like this? I tried highlighting the code and clicking the code box, but that didn't work.

$GUIhandle=GUICreate($title, 400,420, @DesktopWidth/2-210, @DesktopHeight/2-200, -1, 0x00000018); WS_EX_ACCEPTFILES

with

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn_2

exitloop

CASE $MSG = $BTN_1

UPDATE() ; FileOpenDialog function

GUISetState ( @SW_ENABLE , $GUIhandle )

$msg = 0

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

EDIT: ------

I have partially solved this problem by adding FileChangeDir and manually entering the GUI directory info with the following change:

$msg = 0

While $msg <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

Select

Case $msg = $btn_2

exitloop

CASE $MSG = $BTN_1

UPDATE() ; FileOpenDialog function

FileChangeDir ( "C:\Documents and Settings\user\Desktop\DV to MP4 GUI - REV. C" )

$msg = 0

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

Now my problem is, how do I automatically get the directory information about the GUI window so that this will work where ever the GUI is located?

Edited by peter1234

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't understand where you are going with your script, however, here's a sample I just made utilizing the beta version of AutoIt (Switch doesn't exist in prod):

#include <GuiConstants.au3>

GuiCreate("MyGUI", 300, 150,(@DesktopWidth-300)/2, (@DesktopHeight-150)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

Global Const $g_inFile = GuiCtrlCreateInput("", 20, 30, 150, 20)
Global Const $g_bFind = GuiCtrlCreateButton("Browse", 190, 30, 50, 20)
Global Const $g_bOpen = GuiCtrlCreateButton("Open File", 60, 110, 60, 30)
Global Const $g_bExit = GuiCtrlCreateButton("Exit", 160, 110, 60, 30)
GUICtrlSetState($g_inFile, $GUI_DISABLE)

GuiSetState()
While 1
    Switch(GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            ContinueCase
        Case $g_bExit
            ExitLoop
        Case $g_bFind
            Local $return = FileOpenDialog('MyGUI', @ScriptDir, 'Text Files (*.txt)|Script Files (*.au3)', 1)
            GUICtrlSetData($g_inFile, $return, '')
      ;or following line
      ;GUICtrlSetData($g_inFile, FileOpenDialog('MyGUI', @ScriptDir, 'Text Files (*.txt)|Script Files (*.au3)', 1), '')
        Case $g_bOpen
            If FileExists(GUICtrlRead($g_inFile)) Then
                Run('notepad.exe ' & GUICtrlRead($g_inFile))
            EndIf
    EndSwitch
WEnd
Exit

Hope that helps

Edit: It's not pretty, but it works... ;)

Edit2: Saw your update, for findnig the directory the script is located in, that's the @ScriptDir macro (as seen in sample)

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

I answer to your question about getting your code in a box.

Click "Code" button

Paste or type your code

Click "Code" button

I will leave the rest of your question to those better qualified



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

@MSLx Fanboy:

Thanks for your reply. I am not sure if it addresses my problem or not. This is my UPDATE function:

FUNC UPDATE()
$return = FileOpenDialog ( "SEARCH", "", "All (*.*)"   )  
IF $return<>1 then
    $default1=$return
EndIf
EndFunc

That works OK. My problem is re-setting the directory path after I use FileOpenDialog. I would think that

FileChangeDir ( "@AutoItExe" )

would work but it doesn't.

I may be missing something in your response, but I was unable to get either SWITCH or LOCAL to be of any help. Thanks for taking the time to write and post this. I hope I have not missed the point.

@BigDod:

Thanks. I found out that I needed to have Jave or Activex turned on to make it work, and I had them turned off.

Share this post


Link to post
Share on other sites

Try

FileChangeDir(@ScriptDir)


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

@BigDod:

Thanks. I think it must be something like that. But I haven't found it yet. I have tried FileChangeDir with @ScriptFullPath, "@ScriptFullPath", @ScriptDir, "@ScriptDir", @ScriptFullPath, "@ScriptFullPath", and everything else I can think of. Hopefully, someone will have done this although I guess there aren't a lot of people using sloppy coding like relative addresses (but it works good for what I am doing). If I don't solve this today, I am going to set up temp files on the C: drive.

@MSLx Fanboy:

I saw you edit. I am still working with your code.

Share this post


Link to post
Share on other sites

@MSLx Fanboy:

I don't get it. When I add @ScriptDir to the FileOpenDialog statement I get an error. Like I said, I am not an experienced programmer so it is hard for me to see what you are doing. Thanks for posting, but I just don't know how to get it to work.

Share this post


Link to post
Share on other sites

Problem solved. Thanks for the replys. Solution is:

$path=FileGetLongName ( @ScriptDir)
FileChangeDir ($path)

Share this post


Link to post
Share on other sites

The @ScriptDir I put in there just sets focus for the current directory to look at. I could well have set @WorkingDir, which is essentially the same thing, unless a previous function I had called changed it from the default (default being @ScriptDir)

;)

Feel free to post any other questions you might have, I might be around tomorrow, and I'm sure more experienced scripters will be around too :P


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

I am new at this, and do make mistakes. After thinking about it for a while, I thought that BigDod suggestion should work. So I tried it again, and this time it worked. I don't know why it did not work before when I tried it. I think this is the best solution. I added it to my function so that the function is now:

FUNC UPDATE()
$return = FileOpenDialog ( "SEARCH", "", "All (*.*)"   )  
IF @error<>1 then 
  $default1=$return
EndIf
FileChangeDir (@ScriptDir)
EndFunc

This works well. For general use the function should probably be called "Get File Name".

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
Sign in to follow this  
Followers 0