anixon Posted September 24, 2007 Share Posted September 24, 2007 This code opens but does not centre the dialog box as required: $path = FileOpenDialog("Select the Data File", @HomeDrive, "Text Files (*.txt)") WinWaitActive("Select the Data File","",5) WinMove("Select the Data File", "", -1, -1) Help is always appreciated Ant.. Link to comment Share on other sites More sharing options...
maqleod Posted September 24, 2007 Share Posted September 24, 2007 from the help file: "Negative values are allowed for the x and y coordinates. In fact, you can move a window off screen" in other words, the -1,-1 you are using for the x and y are acting as actual coordinates, not as default indicators as used in GuiCreate() so that will not center the dialog [u]You can download my projects at:[/u] Pulsar Software Link to comment Share on other sites More sharing options...
Generator Posted September 24, 2007 Share Posted September 24, 2007 The problem is the script will not continue until a file is chosen or the dialog is closed. To do this you need to use FileWrite and create a temp au3 and use Run() to execute it and move the window Link to comment Share on other sites More sharing options...
ryantollefson Posted September 24, 2007 Share Posted September 24, 2007 How about: $WinPos = WinGetPos("Select the Data File") WinMove("Select the Data File", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2) This is pretty close, but it isn't in exactly the same position as when you do GuiCreate - this is because WinMove gets the title bar as part of the size. Link to comment Share on other sites More sharing options...
Nahuel Posted September 24, 2007 Share Posted September 24, 2007 How about: $WinPos = WinGetPos("Select the Data File") WinMove("Select the Data File", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2) This is pretty close, but it isn't in exactly the same position as when you do GuiCreate - this is because WinMove gets the title bar as part of the size. This won't work because the script pauses until you press OK or Cancel in the dialog window. Link to comment Share on other sites More sharing options...
ryantollefson Posted September 24, 2007 Share Posted September 24, 2007 This won't work because the script pauses until you press OK or Cancel in the dialog window.Yeah, you're right... However, if used as the temp script as Generator suggests, then it should work - just put a Sleep(3000) in front to give the open box a chance to come up. Link to comment Share on other sites More sharing options...
Nahuel Posted September 24, 2007 Share Posted September 24, 2007 (edited) Using Generator's idea and using ryantollefson's script: Main script: ShellExecute("moveopen.au3","","","Run") $path = FileOpenDialog("Select the Data File", @HomeDrive, "Text Files (*.txt)") moveopen.au3: while 1 If WinExists("Select the Data File") Then $WinPos = WinGetPos("Select the Data File") WinMove("Select the Data File", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2) Exit EndIf WEnd Edited September 24, 2007 by Nahuel Link to comment Share on other sites More sharing options...
anixon Posted September 24, 2007 Author Share Posted September 24, 2007 Thanks for the help. I have tried the code but I am not able to get it to open the dialog box in screen centre without selecting an actual file perhaps I am missing something. Cheers Ant.. Link to comment Share on other sites More sharing options...
Nahuel Posted September 24, 2007 Share Posted September 24, 2007 Thanks for the help. I have tried the code but I am not able to get it to open the dialog box in screen centre without selecting an actual file perhaps I am missing something. Cheers Ant.. Yes, you are missing something something. You need to scripts: Script one (Your main script) ShellExecute("moveopen.au3","","","Run") $path = FileOpenDialog("Select the Data File", @HomeDrive, "Text Files (*.txt)") And the moveopen.au3 'auxiliary' script. You have to save it in the same directory as your main script (or change the path in ShellExecute) while 1 If WinExists("Select the Data File") Then $WinPos = WinGetPos("Select the Data File") WinMove("Select the Data File", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2) Exit EndIf WEnd Using two scripts just to make a window center is kinda pointless though... Link to comment Share on other sites More sharing options...
ResNullius Posted September 24, 2007 Share Posted September 24, 2007 Or try this from /dev/null _MoveFileOpenDialog(). It does the same thing as what Nahuel is suggesting, only you don't need to create the secondary script as the function does it for you! Link to comment Share on other sites More sharing options...
anixon Posted September 24, 2007 Author Share Posted September 24, 2007 Yes, you are missing something something. You need to scripts: Script one (Your main script) ShellExecute("moveopen.au3","","","Run") $path = FileOpenDialog("Select the Data File", @HomeDrive, "Text Files (*.txt)") And the moveopen.au3 'auxiliary' script. You have to save it in the same directory as your main script (or change the path in ShellExecute) while 1 If WinExists("Select the Data File") Then $WinPos = WinGetPos("Select the Data File") WinMove("Select the Data File", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2) Exit EndIf WEnd Using two scripts just to make a window center is kinda pointless though... That works perfectly. Thanks for pointing out how it works. Why was it necessary well apart from the esthetics the idea is to have the screen containing the next function control pretty much fall under the position of the mouse pointer that called that function. This way you are not forcing the user to refocus the mouse pointer from one point on the screen to another. If you have control over the position of both windows (not necessarily in the centre) then you can decide on what the positioning relationship should be between them. I guess that this may well be a time and motion issue where esthetics, workflow, logical steps, speed and efficiency are all issues to be considered. Least of all its not an unreasonable requirement to be able to have control over every aspect of the application irrespective of whether it is needed or necessary. More importantly not every solution needs to be elegant. I am not trying to convince anyone that the requirement is necessary rather share the rational. Once again thanks for you help. It does exactly what I want it to do and if the aux script is the only solution then thats fine and to the author what can I say but its very clever. Cheers and best wishes Ant.. Link to comment Share on other sites More sharing options...
Nahuel Posted September 24, 2007 Share Posted September 24, 2007 Glad you got it working. Also, look at ResNullius' idea.Yes, you are missing something something. You need to scripts:God was I drunk this morning? Link to comment Share on other sites More sharing options...
anixon Posted September 24, 2007 Author Share Posted September 24, 2007 Or try this from /dev/null _MoveFileOpenDialog(). It does the same thing as what Nahuel is suggesting, only you don't need to create the secondary script as the function does it for you! Thanks for the information very much appreciated Ant.. Link to comment Share on other sites More sharing options...
anixon Posted September 24, 2007 Author Share Posted September 24, 2007 Glad you got it working. Also, look at ResNullius' idea. God was I drunk this morning? This addition to your idea and that of ResNullius works CODE;Center the Select a Data File Window $ScriptFileName = @scriptdir & "\Centrewindow.au3" FileDelete($ScriptFileName) $sFile = 'While 1' & @CRLF & _ ' If WinExists("Make a Selection") Then'& @CRLF & _ ' $WinPos = WinGetPos("Make a Selection")'& @CRLF & _ ' WinMove("Make a Selection", "", @DesktopWidth/2 - $WinPos[2]/2, @DesktopHeight/2 - $WinPos[3]/2)'& @CRLF & _ ' Exit'& @CRLF & _ ' EndIf'& @CRLF & _ 'WEnd' FileWrite($ScriptFileName, $sFile) Cheers Ant.. 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