Jump to content

Opening a Window


Recommended Posts

:"> Hey everyone. As with most people, I'm feeling stupid for having to post here for something that seems so simple. But, I'm at a lost and need some help.

I work in the printing industry where workflows are very important and huge! Most of the customers I work with and help are almost always looking at multiple windows at a time. They usually have about 10-20 different windows open and at specific positions and sizes to watch files as they move automatically from one position to another until they reach there final destination. One of the most aggrevating things for them is when someone has closed one or more of these windows.

So, onto the script. I've written a small and very easy script for them to record and recall the window positions and size all from a key combo. They love it and it has made setting up the specific windows a flash. But, the problem is, that these windows have to be already open in order for my script to position and size them.

Different key combinations will allow for them to do one window at a time, or all open windows. What they are asking for is a way to hit a key combination to also open all the windows and then place and size them.

I've gotten everything except for the last part, opening the folders. I came close, or at least I thought by using _RunDoS(). I thought I could put ("Start " & $WinTitle) to get it to open the window in explorer, then I would move and position from there. But, this isn't working because of the spaces in some of the dirctory structures. I save all of these window positions and sizes in an .ini file. I manually put the quotes around one of the directory's but to my dismay, I still had problems.

Any help is much appreciated. I'm sure there is an easy answer to this and I have been searching the forum all evening with no luck so far. So I thanks in advance to all those that reply. ;)

; Control + Alt + Shift + s to save window size and position
; Control + Alt + Shift + r to restore window size and position
; Control + Alt + Shift + a to restore all open window size and position
; Control + Alt + Shift + o to open and restore all window size and position

Opt("WinTitleMatchMode", 3)
Opt("WinWaitDelay", 50)

#Include "Process.au3"
HotKeySet("+!^s", "SavePos")          ; Save Window Position
HotKeySet("+!^r", "PosRecall")      ; Recall Window Position and Size
HotKeySet("+!^a", "AllPosRecall")   ; Recall all of the Window Size/Positions for windows already open
HotKeySet("+!^o", "OpenPosRecall")  ; Recalls all of the Window Size/Positions even if they are closed

While 1
;constant loop
Sleep(1000)
Wend

Func SavePos()
    $WinTitle = WinGetTitle("")
    $winsize = WinGetPos("")
    $MousePos = MouseGetPos()
    If $WinTitle = "" Then
    Return
    Else
       If $WinTitle = "Program Manager" Then
       Return
       Else
          ToolTip("Window Size/Position Saved", $MousePos[0] - 25, $MousePos[1] - 25)
          IniWrite (@ScriptDir & "\WindowMapPositions.ini", "Window Size Positions", $WinTitle, $WinSize[0] & " " & $WinSize[1] & " " & $WinSize[2] & " " & $WinSize[3])
           Sleep(2000)
          ToolTip("")
       EndIf
    EndIf
EndFunc

Func PosRecall()
    $WinTitle = WinGetTitle("")
    $ActivePos = IniRead (@ScriptDir & "\WindowMapPositions.ini", "Window Size Positions", $WinTitle, "0")
    If $WinTitle = "Program Manager" Then
    Return
    Else
        If $ActivePos = "0" Then
        Return
        Else
           $SizPos = StringSplit($ActivePos, " ")
           $MousePos = MouseGetPos()
             ToolTip("Window Size/Position Restored", $MousePos[0] - 25, $MousePos[1] - 25)
             WinMove($WinTitle, "", $SizPos[1], $SizPos[2], $SizPos[3], $SizPos[4])
               Sleep(2000)
             ToolTip("")
    EndIf
    EndIf
EndFunc

Func AllPosRecall()
$file = FileOpen(@ScriptDir & "\WindowMapPositions.ini", 0)
$Line = 1
   While 1
      $Line = $line + 1
      $LineRead = FileReadLine($file, $Line)
      If @error = -1 Then ExitLoop
         $LineSplit = StringSplit($LineRead, "=")
         $WinTitle = $LineSplit[1]
         $WinTitlePos = $LineSplit[2]
         $SizPos = StringSplit($WinTitlePos, " ")
         $MousePos = MouseGetPos()
            ToolTip("All Window Size/Positions Restored", $MousePos[0] - 25, $MousePos[1] - 25)
            WinActivate($WinTitle)
            WinMove($WinTitle, "", $SizPos[1], $SizPos[2], $SizPos[3], $SizPos[4])
   Wend
            Sleep(2000)
            ToolTip("")
FileClose($file)
EndFunc

Func OpenPosRecall()
$file = FileOpen(@ScriptDir & "\WindowMapPositions.ini", 0)
$Line = 1
   While 1
      $Line = $line + 1
      $LineRead = FileReadLine($file, $Line)
      If @error = -1 Then ExitLoop
         $LineSplit = StringSplit($LineRead, "=")
         $WinTitle = $LineSplit[1]
         $WinTitlePos = $LineSplit[2]
         $SizPos = StringSplit($WinTitlePos, " ")
         $MousePos = MouseGetPos()
            ToolTip("All Window Opened. Size/Positions Restored", $MousePos[0] - 25, $MousePos[1] - 25)
            _RunDOS("Start " & $WinTitle)
            WinWaitActive($WinTitle)
            WinMove($WinTitle, "", $SizPos[1], $SizPos[2], $SizPos[3], $SizPos[4])
   Wend
            Sleep(2000)
            ToolTip("")
FileClose($file)
EndFunc
jason7237
Link to comment
Share on other sites

_RunDOS("Start " & $WinTitle) <--- that is what you used

What works for me would be _RunDOS ("Start " & ' " ' & $WinTitle & ' " ')

Notice I used the two types of quotes, single quotes on the outside of the double quote - this makes the window print out the " character when it's typing, which is exactly what you want. Example: if $WinTitle = "Program Manager" (got from above), and you do the rundos like I have it, then it starts a new command prompt window titled Program Manager. I am assuming this is what you're looking for.

One more thing I almost forgot. When I use the quotes back-to-back, I don't put any spaces.. I just added them to let you know what I was typing. Thus, it looks like '"' instead of ' " '. Hope that helps.

Edit 2 - if you were not trying to start another command prompt window, and instead meant to start a program, don't use the start command within the command prompt. Hmm.. if you want to start a program, just put the location of the program in quotes, such as "C:\Windows\system32\sol.exe" to start solitaire. If it is a common/registered program (I think that's what I'm trying to say, but solitaire is, regardless), you can just type in "sol.exe" and it will run. I dunno about opening folders yet.. still working on that part.

Edit 3 - If you want to open a folder, such as "C:\Program Files\", this is a good way to do it:

$obj = ObjCreate ("Shell.Application")

$obj.Open ("C:\Program Files\")

What this does is create a shell object and tell it to open a folder. Simple as that.

Edited by greenmachine
Link to comment
Share on other sites

_RunDOS("Start " & $WinTitle) <--- that is what you used

What works for me would be _RunDOS ("Start " & ' " ' & $WinTitle & ' " ')

Notice I used the two types of quotes, single quotes on the outside of the double quote - this makes the window print out the " character when it's typing, which is exactly what you want. Example: if $WinTitle = "Program Manager" (got from above), and you do the rundos like I have it, then it starts a new command prompt window titled Program Manager. I am assuming this is what you're looking for.

One more thing I almost forgot. When I use the quotes back-to-back, I don't put any spaces.. I just added them to let you know what I was typing. Thus, it looks like '"' instead of ' " '. Hope that helps.

Edit 2 - if you were not trying to start another command prompt window, and instead meant to start a program, don't use the start command within the command prompt. Hmm.. if you want to start a program, just put the location of the program in quotes, such as "C:\Windows\system32\sol.exe" to start solitaire. If it is a common/registered program (I think that's what I'm trying to say, but solitaire is, regardless), you can just type in "sol.exe" and it will run. I dunno about opening folders yet.. still working on that part.

Edit 3 - If you want to open a folder, such as "C:\Program Files\", this is a good way to do it:

$obj = ObjCreate ("Shell.Application")

$obj.Open ("C:\Program Files\")

What this does is create a shell object and tell it to open a folder. Simple as that.

Thanks Green for the suggestion. It looks like you are suggesting vbs for this particular issue unless this is new syntax for a beta version. I didn't think to try vbs though. That should actually do the trick. See, it was an easy problem that I couldn't yank out of my head. I will give this a try. Thanks again. ;)

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