Jump to content

FileOpenDialog-box position on the screen


Recommended Posts

Hi everybody,

I searched like crazy to find a solution without success :P

I want to use the 'FileOpenDialog' but would like to see the dialogBox (for instance) at the centre of the screen. Now it always appears at the top-left corner of my screen. Does anybody know what to do ?

Do you know the answer, please help.

Thank you,

Peter

Script_problem_with_OpenDialogBox.au3

Link to comment
Share on other sites

Nice adaption of the code, odklizec. :P

Optional:

Just one safeguard I should have added earlier, to prevent the second instance from possibly continuing as a unmanaged process. Just to Return it's PID and ProcessClose it when finished, if it has not already done so.

The script could use ProcessClose within OnAutoItExit instead, if either of you want it to run through the duration of the main script.

From previous example given:

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
    Sleep(30000)
    Exit
EndIf

; Main Script Below

$pid = _WinOnTop(); <--- PID Returned.
FileSelectFolder("Choose a folder with plugins..", "","4","c:\")
ProcessClose($pid); <--- PID Closed.

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

4 Lines above using <--- Comment as a pointer show the changes to manage the 2nd process better.

Sleep(30000) added just to show a run on effect for testing the ProcessClose

Edited by MHz
Link to comment
Share on other sites

odklizec nice little trick thanks for share. I modify your script a little bit so now you can pass the window titlle, this way you can used the same function with FileOpenDialog, FileSaveDialog or FileSelectFolder also add MHz safeguard using ProcessClose.

If StringInStr($cmdlineraw, '/MoveWin') Then
    $cmdlineraw = StringSplit(StringMid($cmdlineraw, StringInStr($cmdlineraw, '/MoveWin')), ':')
    While 1
        Select
        Case WinExists($cmdlineraw[2])
            $size=WinGetPos ($cmdlineraw[2])
            $PosX=@DesktopWidth/2 - $size[2]/2
            $PosY=@DesktopHeight/2 - $size[3]/2
            WinMove($cmdlineraw[2], "", $PosX, $PosY)
            WinActivate($cmdlineraw[2])
            ExitLoop
        EndSelect
        Sleep(50)
    WEnd
    Exit
EndIf

$Message_1 = "Does anybody know how to make the 'FileOpenDialog'-Box appear in the middle of the screen" & @CRLF & "instead of at the top-left corner of the screen ?" & @CRLF & "If you click 'OK' you'll see what I mean."
$Message_2 = "Did you notice ? The 'FileOpenDialog'-Box always appears on the top-left corner of the screen."

MsgBox(4096, "Please Help", $Message_1)

$PID = _FindBrowseWin('Open file Dialog Box')
$Read_File = FileOpenDialog ( "Open file Dialog Box", @ScriptDir & "\", "AutoIt Files (*.au3)",3,@ScriptFullPath)
ProcessClose($PID)
$PID = _FindBrowseWin('Save file Dialog Box')
$Save_File = FileSaveDialog( "Save file Dialog Box", @ScriptDir, "Scripts (*.aut;*.au3)", 3)
ProcessClose($PID)
$PID = _FindBrowseWin('Browse for Folder')
FileSelectFolder("Choose a folder with plugins..", "","4","c:\")
ProcessClose($PID)

MsgBox(4096, "Please Help", $Message_2)
Exit

Func _FindBrowseWin($sTitle)
    If @Compiled Then
        Return(Run(@ScriptFullPath & ' /MoveWin:' & $sTitle))
    Else
        Return(Run(@AutoItExe & ' "' & @ScriptFullPath & '" /MoveWin:' & $sTitle))
    EndIf
EndFunc
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

@Danny35d

Very nice demonstration with your example. I do find this trick of starting a 2nd instance of the script very useful at regular times to achieve almost impossible goals. It is like asking a friend to help you with a heavy task which you cannot do on your own. :P

Link to comment
Share on other sites

  • 1 month later...

Nice adaption of the code, odklizec. :P

I wrote an alternative soltuion to this, before I found these threads.

My main app, the one which calls FileOpenDialogue() runs another progrma immediately before calling FileOpenDialogue(), which waits for the window text in FileOpenDIalogue to be active, then centers it, and exits.

the main app call looks like this

Run("C:\Automation\waitcenter.exe " & $WindowTitle, "", @SW_HIDE)

$SelectedPath = FileOpenDialog($WindowTitle, $DefaultDir, $Filter, 8, "PatchBankXXX")

The source for WaitCenter is below. I sneed to implement a timeout in this.

The strange thing that happens- when I run it the first tome, the FileOpenDIalogue() is centered, when I run the main app subsequently, a runtime error occurrs whic states WaitCenter.exe could not be found.

It's not an elegant solution, but it was all I could come up with at 12:30 AM

;############################################################################

Func WaitForWindowandCenter($WindowTitle)

While 1

Sleep(20)

WindowActiveCenter($WindowTitle)

WEnd

EndFunc ;==>WaitForWindowandCenter

;############################################################################

Func CenterThisWindow($WindowTitle, $WindowText)

Local $Size

Local $X = 0

Local $Y = 0

$Size = WinGetClientSize($WindowTitle, "")

$Y = (@DesktopHeight / 2) - ($Size[1] / 2)

$X = (@DesktopWidth / 2) - ($Size[0] / 2)

Return WinMove($WindowTitle, $WindowText, $X, $Y)

EndFunc ;==>CenterThisWindow

;############################################################################

Func WindowActiveCenter($WindowTitleText)

If WinActive($WindowTitleText, "") Then

CenterThisWindow($WindowTitleText, "")

Exit

EndIf

EndFunc ;==>WindowActiveCenter

;############################################################################

Func main()

;WaitForWindowandCenter("SELECT-DESTINATION-DIRECTORY...")

WaitForWindowandCenter($CmdLine[1])

EndFunc ;==>main

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