Jump to content

Problem with setting FileSelectFolder on top


 Share

Recommended Posts

Hello folks,

Does anyone have a solution how to set the FileSelectFolder dialog (or FileOpenDialog) on top of GUI? Or even better, make this system windows modal?

I've tried to use adlibenable just before calling FileSelectFolder. The function called with adlibenable checks for availability of "Browse for Folder" window, but it seems, it doesn't work :P The adlib script seems to be paused while the "FileSelectFolder" is open and it's running after closing that dialog.

Does anyone have a good solution for that? I simply need "Browse for Folder" (or Open File) dialog on top of GUI and with disabled GUI control. Then if the dialog is closed, GUI control is again ebabled.

Here is my script, which unfortunately doesn't work as it should and even worse, the script must be terminated via terminating the process in task manager :lmao:

#NoTrayIcon
#include <GUIConstants.au3>

Global $PathToFile
$Form6 = GUICreate("dll tester", 292, 110, 192, 125)
GUICtrlCreateLabel("Select dll file..", 10, 10, 127, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("...", 250, 10, 33, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("", 8, 58, 276, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
AutoItSetOption("WinTitleMatchMode", 2)
AutoItSetOption("WinSearchChildren", 1)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        MsgBox(0, "exit","exit")
        ExitLoop
    Case $msg = $Button1
    ;show select folder dialog
        SelectFolder()
    EndSelect
WEnd
Exit

Func SelectFolder()
;disable GUI button
    GUICtrlSetState($Button1,$GUI_DISABLE)
;start adlib function to detect the availability of "Browse for Folder" dialog and set it on top
    AdlibEnable("SetSelFoderWinOnTop")
; start "Browse for Folder" dialog
    $SelectedFolder = FileSelectFolder("Choose a folder with plugins..", "","4","c:\")
    If @error Then
        MsgBox(4096,"","No Folder chosen")
    Else
        $NumOfFiles = DirGetSize($SelectedFolder,1)
        MsgBox(4096,"","Num of files in sel. dir.. " & $NumOfFiles[1])
    EndIf           
;enable GUI button
    GUICtrlSetState($Button1,$GUI_ENABLE)
EndFunc 

Func SetSelFoderWinOnTop()
    While 1
        If WinExists("Browse for Folder") Then
            WinSetOnTop("Browse for Folder", "", 1)
            AdlibDisable()
            ExitLoop
        Else
        ;ConsoleWrite("window not exist")
        EndIf
    WEnd
EndFunc
Link to comment
Share on other sites

Unfortunately, FileSelectFolder() does block AdlibEnable() :P .

AdlibEnable('_Adlib')
Sleep(2000)
FileSelectFolder('title', @HomeDrive)
Sleep(2000)
Exit

Func _Adlib()
    MouseMove(100, 400, 2)
    MouseMove(400, 400, 2)
EndFunc

AdlibEnable() does pause while certain blocking functions are running :lmao: .

I have added an edit to that linked post to mention the block that occurs.

Link to comment
Share on other sites

Thanks for clarifying! So maybe it would be a good idea to add a Modal/OnTop flags for these File/Folder system dialogs in any next version :P I'm sure I'm not alone who want these dialogs on top of the rest of UI. I will add a feature request to the appropriate forum thread. Thanks for helping guys!

Link to comment
Share on other sites

Unfortunately, FileSelectFolder() does block AdlibEnable() :P .

AdlibEnable('_Adlib')
Sleep(2000)
FileSelectFolder('title', @HomeDrive)
Sleep(2000)
Exit

Func _Adlib()
    MouseMove(100, 400, 2)
    MouseMove(400, 400, 2)
EndFunc

AdlibEnable() does pause while certain blocking functions are running :lmao: .

I have added an edit to that linked post to mention the block that occurs.

as MsgBox do it too.
Link to comment
Share on other sites

OK, I've found a solution to my problem. The trick is to create new au3 file with just window detection procedure and WinSetOnTop function. Now I can install this second au3 via FileInstall and run it just before FileSelectFolder/FileOpenDialog function.

So far so good :lmao: It works great if running from scite4autoit (via Beta Run) but unfortunately, it doesn't work from compiled exe :P The problem is that instead of running external au3 file, it always runs second instance of the main exe and not the external au3 script from another (Temp) folder?

Could you, please, check these two attached files if there is something wrong with my script or if I just found an AutoIt bug?

Main file.. testdialog.au3Detection procedure.. SetWinOnTop.au3

BTW, I tried to follow this solution..

http://www.autoitscript.com/forum/index.ph...topic=17050&hl=

Edited by odklizec
Link to comment
Share on other sites

Maybe this working example may help you. See if I can do better this time round. :P

If StringInStr($cmdlineraw, '/WinOnTop') Then
    MsgBox(4096,"Set win on top","OK")
    While 1
        Select
        Case WinExists("Browse for Folder")     
            WinSetOnTop("Browse for Folder", "", 1)
            ExitLoop
        Case WinExists("Select dll file to test..") 
            WinSetOnTop("Select dll file to test..", "", 1)
            ExitLoop
        EndSelect
        Sleep(50)
    WEnd
    Exit
EndIf

; Main Script Below

$pid =_WinOnTop()
FileSelectFolder("Choose a folder with plugins..", "","4","c:\")
ProcessClose($pid)

Func _WinOnTop()
    If @Compiled Then
        Return Run(@ScriptFullPath & ' /WinOnTop')
    Else
        Return Run(@AutoItExe & ' "' & @ScriptFullPath & '" /WinOnTop')
    EndIf
EndFunc

It seems to work fine. Just use the same script to do it.

Edit: Added Return the PID to ProcessClose the PID for management of the second instance of the script.

Edited by MHz
Link to comment
Share on other sites

Fantastic! Thank you MHz!

Hehe..it's like playing old school adventure games..after hours of hair-pulling and banging head against monitor you find one small item and the game continues..

But still.. shouldn't the solution I suggested work in compiled exe?

Link to comment
Share on other sites

But still.. shouldn't the solution I suggested work in compiled exe?

Run(@AutoItExe & ' "' & @TempDir & '\SetWinOnTop.au3"')

Your code will only work for an uncompiled script. As soon as you compile it fails as the internal interpreter cannot run a script with that line of code. That is why I use a If @Compiled then...Else...

Only the the last version or two of the beta version of AutoIt has support with running an Au3 by using a compiled script using /AutoIt3ExecuteScript switch.

Link to comment
Share on other sites

So, it should work using the latest beta and /AutoIt3ExecuteLine parameter in Run command..like that..

Run(@AutoItExe & ' /AutoIt3ExecuteLine' & ' "' & @TempDir & '\SetWinOnTop.au3"')

But it doesn't work too. It returns "Error: Unable to parse line."

It starts the "SetWinOnTop.au3" but then it fails (both in compiled or uncompiled 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...