Zarkon has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I've got one question. I'm tring to make my life easy and try to made some script for loading multiple windows and logging by sending keystrokes. The target application is putty. So what is done till now. I'm using in main cases windows API. So i start the putty, find the handle and because there is protection against typing passwords need to type it with windows api functions. Everything is ok and works fine. I'm very, very glad, that i can use scripts to operate with Windows API. So powerfull. But where is the problem. As i mention in the begining i need to start multiple putty-s, but also i need to order them on the screen and to resize them. Well... i think i can realize the order with MoveWindow API. In the parameters of that function there is also "width" and "height". But this isn't work. The window can be only in its standart mode or on its minimum size. So it can't be resized. I also saw, that there is module Win32::Console and there is many ways to manipulate the console. Enough talk..to the question. I've got the handle of the putty window allready. Is there a way to manipulate its size with Win32::Console. How can i resize allready started console application. I want to tell you, that MoveWindow API works with cmd.exe, but not with putty. How can i use Win32::Console to manipulate the putty. Is there a way? Or it can't be done. Is there another way. Any suggestions will be most appreciated ! Thanks in advance... Best regards
  • Comment on ActivePerl - Console manipulation - Win32

Replies are listed 'Best First'.
Re: ActivePerl - Console manipulation - Win32
by BrowserUk (Patriarch) on Aug 09, 2006 at 19:04 UTC

    Have you checked the Putty Configuration panel? Under the Window category, there is an option, "Forbid resizing completely". If this is enabled, you will not be able to resize the window either manually or programmically.

    If you are able to resize the window manually, but doing so programmically does not seem to work, it may be that you will have to force a refresh (update) of the window for the new size to take. Are you setting the last parameter to MoveWindow()?

    Win32::Console does not provide for any mechanism for attaching to a console attached to another application, so I am doubtful that it could be used for this purpose.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Yep...that option is disabled. I read first in google also. Didn't find anything. Also read tons of documentation, but nothing. This ... $MoveWindow->Call($targetHandle,1,1,500,500,1); doesn't do anything. This ... $MoveWindow->Call($targetHandle,1,1,10,10,1); .. make the widow in its minimum size with height 0; After this ... $MoveWindow->Call($targetHandle,1,1,500,500,1); ... its restores the window in its default size, but not 500x500. Any suggestions ? Do you think this will work if i use API's like ... GetConsoleScreenBufferInfo SetConsoleScreenBufferSize ???

        It would appear that Putty is selective about which messages it responds to, as it has several modes in which it constrains the users atempts to size the window. You might try SetWindowPos, but I think you might be be out of luck in trying to automate this. If the application doesn't want to let you do it, it doesn't have to.

        You could try using Win32::GuiTest and sending the appropriate sequence of messages to the frame window to adjust it size; ie. emulate the message sequence that would be generated when doing this manually. Something like BUTTON_1_DOWN on the lower right corner, MOUSE_MOVE to the required position, BUTTON_1_UP.

        That's a guess. You'd need to use a message spy to log the manual process and then attempt to emulate it by using SendMessage(). This would probably work, but would be quite laborious to work out the right sequence.

        As I said previously, I do not see any easy way of obtaining a handle to a console belonging to another process, and then persuading Win32::Console to use it.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.