How to Disable Maximize on Fixed Tool Window Form

mohsinjk

Member
Joined
Aug 1, 2007
Messages
11
Programming Experience
1-3
Hi;
When we change the form border style to Fixed tool window then on double click in form title bar he become Maximized. I want to disable this functionality.

reply me soon.:confused:
 
A FixedToolWindow doesn't have a MaximizeBox. There are two ways to handle it, either set MaximumSize equal to current Size in Designer properties, or add this code:
VB.NET:
Expand Collapse Copy
    Private Shared WM_SYSCOMMAND As Integer = &H112
    Private Shared SC_MAXIMIZE As Integer = &HF030
    Protected Overloads Overrides Sub WndProc(ByRef m As Message)
        If m.Msg = WM_SYSCOMMAND AndAlso (m.WParam.ToInt32() And 65520) = SC_MAXIMIZE Then
            Return
        End If
        MyBase.WndProc(m)
    End Sub
The behavior is "by design", while the tool window is not resizable the window state (Normal, Maximized, Minimized) is considered different states and not sizes. The title bar of the window is managed by the operating system common for all windows, so it is very limited what you can do independently for different windows.
 
Yes, you are correct, I must have double-clicked the wrong property when I tested last time and it didn't.
 
You guys should keep in mind that with Logitech mice you can still maximize a window regarless if the MaximizeBox is disabled or removed from the title bar

My fix for this is to use the Resize event to check the WindowState property if it's equal to Maximize then set it back to Normal

Same for Minimize if you don't want the form to be minimized and the user has a Logitech mouse
 
You guys should keep in mind that with Logitech mice you can still maximize a window regarless if the MaximizeBox is disabled or removed from the title bar

You mean if i set MaximizeBox=False or if I use JohnH's code, still no effect?
For my knowledge can you name the model of that mouse?

as you said i tried this piece of code but it will maximize first and then it will become to normal state. I even tried ResizeBegin and ResizeEnd events but still the same.

VB.NET:
Expand Collapse Copy
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Maximized Then
            Me.WindowState = FormWindowState.Normal
        End If
    End Sub
 
You mean if i set MaximizeBox=False or if I use JohnH's code, still no effect?
For my knowledge can you name the model of that mouse?

All of them that have the "Maximize Window" option for any of the buttons, which is every model since 1999

I also found out it can be done with the Microsoft and Belkin mice as well

as you said i tried this piece of code but it will maximize first and then it will become to normal state. I even tried ResizeBegin and ResizeEnd events but still the same.

VB.NET:
Expand Collapse Copy
    Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Maximized Then
            Me.WindowState = FormWindowState.Normal
        End If
    End Sub

That is how it works, I haven't found a better solution to the problem yet.
 
All of them that have the "Maximize Window" option for any of the buttons, which is every model since 1999

I also found out it can be done with the Microsoft and Belkin mice as well

The mice are obviously calling Win API functions. Thus, a program could force a resize of your application by using simple Win API functions.
 
Looking into this I discover the SetWindowPlacement function can be used to maximize a window, it will not send WM_MAXIMIZE but send a WM_GETMINMAXINFO with default measures for max window size and location, if the app doesn't override these values the window will be maximized, details at MSDN Window Features.
I collected all the declarations in a module:
VB.NET:
Expand Collapse Copy
Module Win32

    Declare Function SetWindowPlacement Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpwndpl As WINDOWPLACEMENT) As Int32
    Declare Function GetWindowPlacement Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpwndpl As WINDOWPLACEMENT) As Int32
    Structure WINDOWPLACEMENT
        Public Length As Int32
        Public flags As Int32
        Public showCmd As Int32
        Public ptMinPosition As POINTAPI
        Public ptMaxPosition As POINTAPI
        Public rcNormalPosition As RECT
    End Structure
    Structure POINTAPI
        Public x As Int32
        Public y As Int32
    End Structure
    Structure RECT
        Public Left As Int32
        Public Top As Int32
        Public Right As Int32
        Public Bottom As Int32
    End Structure
    Public Const SW_SHOWMAXIMIZED As Int32 = 3

    Public Const WM_SYSCOMMAND As Integer = &H112
    Public Const SC_MAXIMIZE As Integer = &HF030
    Public Const WM_GETMINMAXINFO As Int32 = &H24
    Structure MINMAXINFO
        Public ptReserved As POINTAPI
        Public ptMaxSize As POINTAPI
        Public ptMaxPosition As POINTAPI
        Public ptMinTrackSize As POINTAPI
        Public ptMaxTrackSize As POINTAPI
    End Structure
End Module
Here is the code to test it, disable MaximizeBox and the window won't maximize when you double-click the titlebar, add a button and this code and the window will maximize:
VB.NET:
Expand Collapse Copy
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim wp As WINDOWPLACEMENT
    GetWindowPlacement(Me.Handle.ToInt32, wp)
    wp.showCmd = SW_SHOWMAXIMIZED
    SetWindowPlacement(Me.Handle.ToInt32, wp)
End Sub
Here's how to override max size and location when that message arrives, now the window will not maximize: (I just left the WM_SYSCOMMAND there also)
VB.NET:
Expand Collapse Copy
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32() = SC_MAXIMIZE Then
        Return
    ElseIf m.Msg = WM_GETMINMAXINFO Then
        Dim mm As MINMAXINFO = Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, GetType(MINMAXINFO))
        mm.ptMaxSize.x = Me.Width
        mm.ptMaxSize.y = Me.Height
        mm.ptMaxPosition.x = Me.Location.X
        mm.ptMaxPosition.y = Me.Location.Y
        Runtime.InteropServices.Marshal.StructureToPtr(mm, m.LParam, True)
    End If
    MyBase.WndProc(m)
End Sub
 
Thanks JohnH your code worked perfectly.
All of them that have the "Maximize Window" option for any of the buttons, which is every model since 1999

I also found out it can be done with the Microsoft and Belkin mice as well

Thanks JuggaloBrotha you were right, the problem was that I didn't install proper drivers for my Logitech mouse. I installed Logitech mouse driver and Now I'm able to maximize windows using mouse also.
 
I have yet to test JohnH's code

I first noticed that "problem" back in VB 5, then in VB6 and in VS2003 and finally VS 2005

Also that "problem" appears to be with perl and java programs as well, but there may be some fix for it with those languages by now
 
Here is a ghetto solution:

VB.NET:
Expand Collapse Copy
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Me.WindowState = FormWindowState.Maximized Then
            Me.WindowState = FormWindowState.Normal
        End If
    End Sub

Put that in a timer w/ a small interval. ;)
 
Back
Top