Results 1 to 21 of 21

Thread: Changing the size of an opened window

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72

    Changing the size of an opened window

    Can anyone give me a clue on how to adjust the size of an active window?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    If it in your app then its just changing the width and height properties but if its not your app then you need to use APIs. FindWindow to get the main window handle to that apps window to be resized. Then SetWindowLong or SetWindowPlacement or even SetWindowPos.

    Search the forums as I have code examples.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Changing the size of an opened window

    If you put code in your resize event, you can force a minimum size by checking the size inside the event. If less than your set minimum (if me.width < 400 then me.width = 400) it resizes it.
    There is a much more complex way involving subclassing the windows message handler that actually prevents the window from becoming smaller than the set size, but it is beyond the scope of my answer
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Changing the size of an opened window

    That won't work for other windows from other applications.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    I think maybe he was replying to that other thread or had it on his mind

    The ods are that its a third party app window in question which is why I posted both scenerios. The APIs are probablygoing to be the solution here.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Changing the size of an opened window

    never claimed it would... The question doesn't specify, so i chose one possible scenario and answered for it.
    Robdog888, what other thread? If there are 2, merge them.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    It was another recent thread on resizing a window but it was hell lord that was in it and not you. My mistake. Dont pay any attention to me tonight lol. (Except my quality posts).
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72
    ^Yep, its a window opened by a VB app. To be more specific and to give you more light on my question, I have a code that opens a PuTTY window using 'WScript.shell'. I am successful in opening the window but what I want is for that window to have a specific size already instead of having to resize it manually everytime I open a new PuTTY window...

    Thank you in advance....

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    Yes, you will have to use the APIs I posted in #2 then.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72

    Re: Changing the size of an opened window

    I'll look into that.. thanks for the help...

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72

    Re: Changing the size of an opened window

    I have yet to try them out but it looks like the appropriate APIs to use for my problems are the 'FindWindow' and 'SetWindowPos' API...

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72

    Re: Changing the size of an opened window

    Is the 'GetActiveWindow' API a good alternative for 'FindWindow'?

    BTW, FindWindow requires a class name, how should I know the class name of for example, a PuTTY window?

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    Use MS Spy++. Its a window finder tool that exposes the window heirarchy and class names etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72
    I also found an API which is 'GetForegroundWindow' and tried that one... it worked somehow since it was able to change the puTTY window's position using 'SetWindowPos' API but the only problem is I still can't change its dimensions...why is that? Is the Putty window the one that has the problem?

  15. #15
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Changing the size of an opened window

    are you able to change the window dimensions in any other fashion, such as dragging the borders?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72
    ^Yes, I can... that was the manual resizing I mentioned earlier... I want the window to already have a custom size so I don't have to adjust it everytime I open it...

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Changing the size of an opened window

    here's another api to try:
    [code]
    Declare Function MoveWindow& Lib "user32" (ByVal hwnd As Long, ByVal x As Long, _
    ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As _
    Long)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72
    Thanks, I tried it out but produces the same results as the 'SetWindowPos' API, it was only able to change the puTTY window's position... jeez, I'm really beginning to think the puTTY window is the problem... I'll try it with the command prompt and compare its results...

  19. #19
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing the size of an opened window

    Or you could try SetWindowPlacement
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  20. #20
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Changing the size of an opened window

    I might be able to help if i had a little more info? For example: i am not familiar with the putty window. Is it a graphics program?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Location
    Philippines
    Posts
    72

    Re: Changing the size of an opened window

    ^It's a terminal window much like a command prompt window....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width