Sign in to follow this  
Followers 0
qwert

How to control location and size of Win dialog?

7 posts in this topic

When I use FileSelectFolder, for instance, it always opens toward the top left of the screen and in a rather small format (small, considering the size of directory trees on most computers).

I would like to have it open much larger (say 600 x 600) and in the center of the screen ... but there aren't x, y positions listed like with InputBox. Is there a way to override a dialog's defaults?

On a related note, is there any way to increase the size of the font that the dialog uses? The standard becomes pretty small on a 1600-pixel monitor.

Thanks for any assistance.

Share this post


Link to post
Share on other sites



I also would like to know.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If you look in the help file for FileOpenDialog, and FileSelectFolder, you'd see that the last parameter for each of those is hwnd. What that parameter does is it causes the dialog box to open where the GUI that calls it is located.

An example:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("Test GUI", 300, 200, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU))
Global $Browse = GUICtrlCreateButton("browse", 20, 20)
GUISetState()
Do
    If GUIGetMsg() = $Browse Then FileOpenDialog("title", "c:\", "All (*.*)", Default, "", $hGUI)
    Sleep(10)
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Unfortunately there doesn't seem to be an easy way to resize the window, or position it where you want it, other than right on top of the current GUI.

EDIT:

Hit Submit instead of preview post LOL

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Well, that's certainly a step in the right direction. It brings up the dialog centered on the parent GUI.

But here's an interesting twist: the user can resize the dialog prior to making their selection. Then, the next time they run the same script, Windows remembers the last size and uses it for the new dialog. Granted, it appears shifted down and to the right because it doesn't adjust the origin x, y ... but at least is saves the user a couple of steps.

Thanks for the suggestion. Now, if I could only get to those default sizes ...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What about controlling it from a temp file?

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
$hGUI = GUICreate("Test GUI", 300, 200, -1, -1, BitOR($WS_POPUP, $WS_CAPTION, $WS_SYSMENU))
Global $Browse = GUICtrlCreateButton("browse", 20, 20)
Global $Browse2 = GUICtrlCreateButton("MSG", 20, 50)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Browse
            MoveWin("title", "", 150, 150, 850, 550, 10)
            Sleep(500)
            FileOpenDialog("title", "c:\", "All (*.*)", Default, "", $hGUI)
        Case $msg = $Browse2
            MsgBox(0, 'Testing', 'Button 2 was pressed')
    EndSelect
    Sleep(11)
WEnd

Func MoveWin($Title, $Text, $x, $y, $w, $h, $speed)
    Local $file = FileOpen("e:\temp\MoveTitle.au3", 10)
    If $file = -1 Then Return
    Local $line0 = ';#NoTrayIcon'
    Local $line1 = 'AutoItSetOption(' & '"WinWaitDelay", 0' & ')'
    Local $line2 = 'WinWait("' & $Title & '", "' & $Text & '")'
    Local $line3 = 'WinMove("' & $Title & '", "' & $Text & '"' & ', ' & $x & ', ' & $y & ', ' & $w & ', ' & $h & ', ' & $speed & ')'
    Local $line4 = 'Sleep(200)'
    FileWrite($file, $line0 & $line1 & @CRLF & $line2 & @CRLF & $line3 & @CRLF & $line4)
    FileClose($file)
    Run(@AutoItExe & " e:\temp\MoveTitle.au3")
    WinWaitClose($Title, $Text)
    FileDelete("e:\temp\MoveTitle.au3")
EndFunc   ;==>MoveWin
Edited by JoHanatCent

Share this post


Link to post
Share on other sites

You might tweak those "remembered sizes" of the parent with _WinAPI_SetWindowPlacement() before opening the dialog. I haven't tried it for this purpose, but it might be worth a shot.

;)


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

Share this post


Link to post
Share on other sites

Thanks to you both.

While I admit that what I was hoping for was some easy "MoveDialog" command or such, your suggestions open up new areas of possibilities.

Having a running script actually write an AutoIt script into a temporary file and run it as a parallel task is a very interesting technique (although it requires AutoIt to be installed on the target computer). But it made me realize how a compiled utility script could also perform these operations in a supporting role.

Get/Set Windows Placement provide a level of control that I just wasn't aware of.

Between these two techniques, I think I'll be able to get a useful result.

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