Results 1 to 18 of 18

Thread: Prevent Maximizing Window

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Question Prevent Maximizing Window

    How do I ensure that clicking the Maximize button on the title bar doesn't maximize the window?

    Setting the ControlBox of the Form to False or setting the BorderStyle of the Form to Fixed Single, Fixed Dialog or Fixed ToolWindow isn't the solution! Trying to set MaxButton.Visible = False generates an error.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    272
    DONT RUN EXECUTABLE FILES FROM UNKNOWN SOURCES.

  3. #3
    Member
    Join Date
    May 2006
    Posts
    32

    Re: Prevent Maximizing Window

    On the Form's properties, set MaxButton to False. You can't do it in code because its read-only, i think.

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Prevent Maximizing Window

    You can use SetWindowLong to remove the Maximize button from the Window style at runtime.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

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

    Re: Prevent Maximizing Window

    Use the SetWindowPlacement API so you can specify the maximum size, normal size and other positioning/placement properties. Then when they "Maximize it will only max to the size you specify.

    http://www.vbforums.com/showpost.php...0&postcount=18
    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

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Prevent Maximizing Window

    Tried using the suggestion given by cutepraba (thread #2)....it removes Maximize from the system menu but it doesn't disable/remove the Maximize button from the titlebar.

    Also tried using SetWindowLong as shown in this post but it too doesn't disable/remove the Maximize button from the titlebar but removes Maximize from the system menu.

    Finally tried RobDog's suggestion as well but it hangs the app (which is a web browser). Where does IEFrame (passed to the FindWindow function) come from?

    Any other suggestions, friends?
    Last edited by arpan_de; Jan 22nd, 2008 at 10:58 PM.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  7. #7

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

    Re: Prevent Maximizing Window

    If your program "hangs" then you must have something wrong. You cant just give up on things without trying to fix them. That is what programmers do, debug code.

    Post code of what you are having trouble with
    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

  9. #9

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Prevent Maximizing Window

    Very simple - set the MaxButton property in the IDE to False.
    I can't do that because I need to set the MaxButton to False at runtime which VB doesn't allow.

    If your program "hangs" then you must have something wrong. You cant just give up on things without trying to fix them. That is what programmers do, debug code
    Yes...yes...I tried to debug it (otherwise I wouldn't have posted my follow-up question after 4 days) but couldn't find a way out

    Actually this pertains to opening new browser windows when a button or a link is clicked in a web page (for e.g. the Manage Attachments button which exists in the page where users type their questions). Using the WebBrowser control's events ClientToHostWindow, WindowSetHeight, WindowSetLeft, WindowSetTop & WindowSetWidth, I have succeeded in opening new browser windows to the position & dimensions in which the new browser window has been programmed (by the website programmer) to open. This is how I did it:

    Code:
    Dim blnCH As Boolean
    Dim iH    As Integer
    Dim iW    As Integer
    
    Private Sub Form_Activate()
        'adjust the position & dimension of the new browser window only if a
        'new browser window is programmed to open; not if user right-clicks a 
        'link & then selects Open in New Window
        If (blnCH = True) Then
            wWeb.Top = 0
            wWeb.Left = 0
            wWeb.Height = iH * Screen.TwipsPerPixelY
            wWeb.Width = iW * Screen.TwipsPerPixelX
        End If
    End Sub
    
    Private Sub wWeb_ClientToHostWindow(CX As Long, CY As Long)
        blnCH = True
        Me.WindowState = vbNormal
    
        'this is where I added your code RobDog
    End Sub
    
    Private Sub wWeb_WindowSetHeight(ByVal Height As Long)
        iH = Height
        Me.Height = Height * Screen.TwipsPerPixelY
    End Sub
    
    Private Sub wWeb_WindowSetLeft(ByVal Left As Long)
        Me.Left = Left * Screen.TwipsPerPixelX
    End Sub
    
    Private Sub wWeb_WindowSetTop(ByVal Top As Long)
        Me.Top = Top * Screen.TwipsPerPixelY
    End Sub
    
    Private Sub wWeb_WindowSetWidth(ByVal Width As Long)
        iW = Width
        Me.Width = Width * Screen.TwipsPerPixelX
    End Sub
    What could be causing the browser to hang?

    EDIT:

    Forgot to add that it opens a new IE window as well.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  10. #10

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Prevent Maximizing Window

    The Do While loop is causing the browser to hang.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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

    Re: Prevent Maximizing Window

    OK now we are getting somewhere. The do loop is looking for the window handle. For whatever reason its not finding it. Is it a different string or different language perhaps?

    When you place a breakpoint, what are the values? Caption to look for on the window and the actual caption of the window as reported by Spy++?

  12. #12

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Prevent Maximizing Window

    Yes you are right RobDog. The title of the new browser window gets assigned in the WebBrowser's DocumentComplete event which fires after the ClientToHostWindow event & I have put your code in the ClientToHostWindow event which means that when the Do loop executes, no title has been assigned to the new browser window which I think causes the browser to hang. Earlier the Do loop looked like this:

    Code:
    Do While lRet = 0
        lRet = FindWindow(vbNullString, wWeb.LocationName)
    Loop
    I changed the code within the Do loop slightly:

    Code:
    Do While lRet = 0
        lRet = FindWindow(vbNullString, vbNullString)
    Loop
    Now the app doesn't hang but users can still maximize the new browser window by clicking the icon on the titlebar.

    What would you suggest?


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  13. #13
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Prevent Maximizing Window

    What about using a hook?
    Have a look at the Module in this sample,
    http://www.Planet-Source-Code.com/vb...68724&lngWId=1

    If you change the ptMaxSize to something like,
    mm.ptMaxSize.X = 500
    mm.ptMaxSize.Y = 500
    When you maximize the form it will only be 500 by 500.

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

    Re: Prevent Maximizing Window

    Well by changing the Findwindow to both nullstrings you will be obtaining any open window of any class and title.

    There should be a way for you enumerate all the child windows of your browser window. The only problem again is to know which is the new window.

    The first thing I can think of is to populate a string array of all the open windows titles. Then when you click on the new window link you can enumerate the windows again and check for the one that is different which will be one additional and the defferent caption will be the new wndow.
    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

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

    Re: Prevent Maximizing Window

    Quote Originally Posted by Edgemeal
    What about using a hook?
    Have a look at the Module in this sample,
    http://www.Planet-Source-Code.com/vb...68724&lngWId=1

    If you change the ptMaxSize to something like,
    mm.ptMaxSize.X = 500
    mm.ptMaxSize.Y = 500
    When you maximize the form it will only be 500 by 500.
    But you would have to know what window to hook and thats the problem.
    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

  16. #16
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Prevent Maximizing Window

    Oh sorry, from the 1st post I thought it was a VB form you wanted to stop from maximizing.

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

    Re: Prevent Maximizing Window

    Well it is but its got a webbrowser control on it which in part of his stuff is opening another window from the html code which isnt a vb form.
    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

  18. #18

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: Prevent Maximizing Window

    There's one very stupid way to ensure that maximizing the window doesn't maximize the window & this is that stupid approach (using the blnCH boolean variable shown in thread #9):

    Code:
    Private Sub Form_Resize()
        If (blnCH = False) Then
            'do resizing here for normal windows
        Else
            If Not (Me.WindowState = vbMinimized) Then
                Me.WindowState = vbNormal
                If (Me.Height > iH * Screen.TwipsPerPixelY) Then
                    Me.Height = iH * Screen.TwipsPerPixelY
                End If
    
                If (Me.Width > iW * Screen.TwipsPerPixelX) Then
                    Me.Width = iW * Screen.TwipsPerPixelX
                End If
            End If
        Ed If
    End Sub
    When you try to maximize such a new browser window, then you can see the window maximizing momentarily after which it reverts back to the original height & width in the restored state! It looks sort of funny....gives an animated look to the window......

    The 3rd & 4th If conditions aren't necessary but the 2nd one is a must otherwise even if users minimize the window, the window will refuse to minimize & restore its state back to normal.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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