Results 1 to 28 of 28

Thread: [RESOLVED] How to prevent a Sizable Form from being resized

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] How to prevent a Sizable Form from being resized

    The Form has Border Style = 2 (Sizable) but I need to prevent it from being resized manually just as if it was a Fixed Single. I have used the approach in the Form_Resize() event to always make the Width and Height equal to a fixed value and this does prevent resizing however it also shows the Form being resized but just not allowing it.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: How to prevent a Sizable Form from being resized

    Okay, I'll bite. If you don't want a sizable form being resized, why wouldn't you just use Fixed Single instead?

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How to prevent a Sizable Form from being resized

    So you have a form set to allow resizing but you don't want it re sized?
    Is this the same form that you want an active min and max button but do not want them to min or max the form?

    Really, it makes no sense to do any of this, why would you want the user to see the sizing icon and then not be able to use it?
    Why would you want to show a min and max button and not be able to use them?

    As for the sizable border the only difference that makes is a tiny tiny larger border, so small of an amount that you could only tell the difference if you look at them side by side and even then you would have to look very close. Seems like a waste of time to even try.

    You can btw add the min and max button to a non sizable form so it really looks the same as a sizable one if that is what you are after you just won't get the sizing arrows when you hover over the edge

  4. #4
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: How to prevent a Sizable Form from being resized

    Not even a nibble, unless this counts...

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: How to prevent a Sizable Form from being resized

    Wow this gets weirder and weirder. Such weird requests you're getting lol.

    Bonnie's code from your other thread should work also with a slight alteration. Use that code but discard the SC_SIZE sub-message of WM_SYSCOMMAND along with the minimize and close messages. The value of SC_SIZE is 0xF000 or &HF000 in VB.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: How to prevent a Sizable Form from being resized

    Quote Originally Posted by Niya View Post
    Bonnie's code from your other thread should work also with a slight alteration. Use that code but discard the SC_SIZE sub-message of WM_SYSCOMMAND along with the minimize and close messages. The value of SC_SIZE is 0xF000 or &HF000 in VB.
    Yes, I've tested it and it does work.

    An alternative to WM_SYSCOMMAND is the WM_GETMINMAXINFO message. It has the advantage of being able to prevent window resizing through Windows 7's Aero Snap feature.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: How to prevent a Sizable Form from being resized

    But why?
    Really, this is perhaps above my brain's limited capacity. I can see no reason why any of this is even needed. Bonnie's code is excellent ( as always ), but why not design the forms correctly in the first place?

    Sorry, if I sound a bit harsh ( I hope not ), but I really cannot comprehend the need to do unnecessary things
    VB.NET MVP 2008 - Present

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: How to prevent a Sizable Form from being resized

    Quote Originally Posted by HanneSThEGreaT View Post
    But why?
    Really, this is perhaps above my brain's limited capacity. I can see no reason why any of this is even needed. Bonnie's code is excellent ( as always ), but why not design the forms correctly in the first place?

    Sorry, if I sound a bit harsh ( I hope not ), but I really cannot comprehend the need to do unnecessary things
    I agree with this wholeheartedly. This is quite ridiculous in my opinion but its what he wants so I think we should help as best we can.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to prevent a Sizable Form from being resized

    Quote Originally Posted by Niya View Post
    Bonnie's code from your other thread should work also with a slight alteration. Use that code but discard the SC_SIZE sub-message of WM_SYSCOMMAND along with the minimize and close messages. The value of SC_SIZE is 0xF000 or &HF000 in VB.
    You're saying to use Bonnie's code from the other thread but discard the SC_SIZE sub-message

    There is no SC_SIZE message in that code

    There is SC_CLOSE, SC_MAXIMIZE, SC_MINIMIZE, and SC_RESTORE

    and you are saying in addition to the SC_SIZE message also discard the SC_MINIMIZE message

    Exactly what do you expect that to do?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to prevent a Sizable Form from being resized

    I found that WM_SIZING is the one that can prevent manual sizing


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  11. #11
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    The subclassing code here is now also able to prevent window resizing via the aforementioned WM_GETMINMAXINFO message.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  12. #12
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,899

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Code:
    Public Sub Form_Resize()
        With Form1
            .Height = 100
            .Width = 100
        End With
    End Sub
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Event's Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Bar | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Bonnie West View Post
    The subclassing code here is now also able to prevent window resizing via the aforementioned WM_GETMINMAXINFO message.
    So is one way any better than the other, ie. WM_SIZING vs SC_SIZE

    What's the purpose of using WM_GETMINMAXINFO? It causes my app to crash!


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by ThEiMp View Post
    Code:
    Public Sub Form_Resize()
        With Form1
            .Height = 100
            .Width = 100
        End With
    End Sub
    No, that doesn't work good it still shows the outline of the Form as it is being resized


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  15. #15
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by jmsrickland View Post
    So is one way any better than the other, ie. WM_SIZING vs SC_SIZE
    SC_SIZE would be the simplest option because you just add that constant to the cases being checked in the WM_SYSCOMMAND case. Only problem I see with it is that it can't prevent the Aero Snap feature of Windows 7 from resizing the Form.

    I've tried handling the WM_SIZING message but I could not get the Form to maintain its size. I'm probably calculating something wrong with the RECT structure's members.

    Quote Originally Posted by jmsrickland View Post
    What's the purpose of using WM_GETMINMAXINFO? It causes my app to crash!
    The WM_GETMINMAXINFO message allows you "to override the window's default maximized size and position, or its default minimum or maximum tracking size". By specifying the same values for the minimum and maximum tracking size (the smallest and largest window dimensions allowed for a window), the window is effectively constrained to one size only.

    Can you describe how to replicate the crash? One possible culprit could be the CallWindowProcW call. You can replace it with a direct call to the GetMinMaxInfo function, but then you would have to use CopyMemory in order to copy the MINMAXINFO structure being pointed to by lParam.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Bonnie West View Post
    I've tried handling the WM_SIZING message but I could not get the Form to maintain its size. I'm probably calculating something wrong with the RECT structure's members.

    It doesn't use a RECT structure.


    Quote Originally Posted by Bonnie West View Post
    Can you describe how to replicate the crash? One possible culprit could be the CallWindowProcW call. You can replace it with a direct call to the GetMinMaxInfo function, but then you would have to use CopyMemory in order to copy the MINMAXINFO structure being pointed to by lParam.

    This is what I have. As soon as the app is started it immediately crashes. I am running VB6 on XP/SP2

    Code:
    Option Explicit     'In modSubclass.bas
    
    Private Const SC_CLOSE As Long = &HF060&
    Private Const SC_MAXIMIZE As Long = &HF030&
    Private Const SC_MINIMIZE As Long = &HF020&
    Private Const SC_RESTORE As Long = &HF120&
    Private Const SC_SIZE As Long = &HF000&
    
    Private Const WM_DESTROY As Long = &H2
    Private Const WM_GETMINMAXINFO As Long = &H24
    Private Const WM_SYSCOMMAND As Long = &H112
    
    Private Type POINT
      X As Long
      Y As Long
    End Type
    
    Private Type MINMAXINFO
      ptReserved As POINT
      ptMaxSize As POINT
      ptMaxPosition As POINT
      ptMinTrackSize As POINT
      ptMaxTrackSize As POINT
    End Type
    
    Private Const WM_MOVING As Long = &H216
    Private Const WM_MOVE As Long = &H3
    Private Const WM_ACTIVATE As Long = &H6
    Private Const WM_SIZE As Long = &H5
    Private Const WM_SIZING As Long = &H214
    
    Private Declare Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
    
    Private Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
    
    Public Function Subclass(ByRef Form As VB.Form) As Boolean
     Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, ObjPtr(Form), AddressOf SubclassProc):  Debug.Assert Subclass
    End Function
    
    Private Function SubclassProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, _
                                  ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
     Select Case uMsg
       'USE THIS OR SC_SIZE BELOW
       'Case WM_SIZING
       '  MsgBox "You are not permitted to resize this application"
       '  Exit Function
       
       'NOT USED FOR NOW
       'Case WM_MOVE
       '  MsgBox "You are not permitted to move this application"
       '  Exit Function
     
       'BELOW CAUSES APP TO CRASH
       'Case WM_GETMINMAXINFO
       '  SubclassProc = CallWindowProcW(uIdSubclass, hWnd, uMsg, wParam, lParam)
       '  Exit Function
       
       Case WM_SYSCOMMAND
         Select Case wParam And &HFFF0&
           Case SC_CLOSE
             MsgBox "You are not permitted to close this application"
             Exit Function
           Case SC_MAXIMIZE
             MsgBox "You are not permitted to maximize this application"
             Exit Function
           Case SC_MINIMIZE
             MsgBox "You are not permitted to minimize this application"
             Exit Function
           Case SC_SIZE
             MsgBox "You are not permitted to move this application"
             Exit Function
           Case SC_RESTORE
             MsgBox "You are not permitted to restore this application"
             Exit Function
         End Select
    
       Case WM_DESTROY
         dwRefData = RemoveWindowSubclass(hWnd, dwRefData, uIdSubclass): Debug.Assert dwRefData
     End Select
    
     SubclassProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
    End Function


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  17. #17
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by jmsrickland View Post
    It doesn't use a RECT structure.
    Yes it does. The WM_SIZING message says:

    Quote Originally Posted by MSDN
    lParam
    A pointer to a RECT structure with the screen coordinates of the drag rectangle. To change the size or position of the drag rectangle, an application must change the members of this structure.
    Quote Originally Posted by jmsrickland View Post
    This is what I have. As soon as the app is started it immediately crashes. I am running VB6 on XP/SP2
    Replace the highlighted part:

    Code:
    Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, ObjPtr(Form), AddressOf SubclassProc)
    with:

    Code:
    Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, AddressOf GetMinMaxInfo, AddressOf SubclassProc)
    What happened was that CallWindowProcW was accessing an invalid memory address (ObjPtr(Form)), hence the GPF.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Bonnie West View Post
    Yes it does.

    OK, but in one of my apps I use WM_SIZING and I have no RECT structure even in the code and it does the same thing (meaning it prevents resizing). Maybe because I am not changing the size of the drag rectangle whatever that means


    Quote Originally Posted by Bonnie West View Post
    Replace the highlighted part:

    Code:
    Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, ObjPtr(Form), AddressOf SubclassProc)
    with:

    Code:
    Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, AddressOf GetMinMaxInfo, AddressOf SubclassProc)
    What happened was that CallWindowProcW was accessing an invalid memory address (ObjPtr(Form)), hence the GPF.
    If I use exactly your 2nd SetWindowSubclass I get Compile error: Variable not defined.

    Now if I...

    Dim GetMinMaxInfo As MINMAXINFO

    ...then I get Compile error: Expected Sub, Function, or Property
    Last edited by jmsrickland; Nov 6th, 2013 at 02:19 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  19. #19
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by jmsrickland View Post
    If I use exactly your 2nd SetWindowSubclass I get Compile error: Variable not defined.

    Now if I...

    Dim GetMinMaxInfo As MINMAXINFO

    ...then I get Compile error: Expected Sub, Function, or Property
    I thought you have copied everything in the subclassing code I posted in the other thread.

    You'll need to copy the GetMinMaxInfo function from that code and then you can do whatever you need to do inside that function (like popup a MsgBox).
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  20. #20
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by jmsrickland View Post
    So is one way any better than the other, ie. WM_SIZING vs SC_SIZE
    WM_SIZING events are fired while the user drags window edges. SC_SIZE is only sent after the user releases the mouse. If you want to make changes *during resizing*, you need to use WM_SIZING.

    Quote Originally Posted by Bonnie West View Post
    SC_SIZE would be the simplest option because you just add that constant to the cases being checked in the WM_SYSCOMMAND case. Only problem I see with it is that it can't prevent the Aero Snap feature of Windows 7 from resizing the Form.
    You can use SC_MOVE (&HF010&) to detect Aero Snap events and adjust behavior accordingly. (I have no idea why Snap features don't fire SC_SIZE...)

    Quote Originally Posted by Bonnie West View Post
    I've tried handling the WM_SIZING message but I could not get the Form to maintain its size. I'm probably calculating something wrong with the RECT structure's members.
    Here is code I use for handling the WM_SIZING rect, assuming a rect variable called "curWinRect" and a desired minimum size of 640x480:

    Code:
    Dim userSizeTooSmall as Boolean
    userSizeTooSmall = False
                        
    'wParam contains a value that identifies the edge being used for the resize.
    Dim resizeHandle as Long
    resizeHandle = wParam
    
    'lParam contains a pointer to the window's rect location.  Retrieve it now.
    CopyMemory curWinRect, ByVal lParam, Len(curWinRect)
    
    'If the user has set the window size too small, force the window to a minimum size (640x480).
    If (curWinRect.x2 - curWinRect.x1) < 640 Then
        userSizeTooSmall = True
        If (resizeHandle = WMSZ_BOTTOMLEFT) Or (resizeHandle = WMSZ_LEFT) Or (resizeHandle = WMSZ_TOPLEFT) Then
            curWinRect.x1 = curWinRect.x2 - 640
        Else
            curWinRect.x2 = curWinRect.x1 + 640
        End If
    End If
    
    If (curWinRect.y2 - curWinRect.y1) < 480 Then
        userSizeTooSmall = True
        If (resizeHandle = WMSZ_TOPLEFT) Or (resizeHandle = WMSZ_TOP) Or (resizeHandle = WMSZ_TOPRIGHT) Then
            curWinRect.y1 = curWinRect.y2 - 480
        Else
            curWinRect.y2 = curWinRect.y1 + 480
        End If
    End If
    
    If userSizeTooSmall Then
    
        'Copy the new rect into place
        CopyMemory ByVal lParam, curWinRect, Len(curWinRect)
            
    End If
    One quirk of doing it this way is that you need to check the wParam value, which tells you which edge of the window the user is dragging. Left-edge resizing needs to be handled differently from right-edge resizing (e.g. whether you modify the x1 or x2 component of the rect). Similarly for top-edge vs bottom-edge resizing.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Bonnie West View Post
    I thought you have copied everything in the subclassing code I posted in the other thread.

    You'll need to copy the GetMinMaxInfo function from that code and then you can do whatever you need to do inside that function (like popup a MsgBox).
    Ooops! I missed that

    Ok, I copied the Function as well as the two declare statements

    It still crashes

    Here is what I have now

    Code:
    Option Explicit     'In modSubclass.bas
    
    Private Const SC_CLOSE As Long = &HF060&
    Private Const SC_MAXIMIZE As Long = &HF030&
    Private Const SC_MINIMIZE As Long = &HF020&
    Private Const SC_RESTORE As Long = &HF120&
    Private Const SC_SIZE As Long = &HF000&
    
    Private Const WM_DESTROY As Long = &H2
    Private Const WM_GETMINMAXINFO As Long = &H24
    Private Const WM_SYSCOMMAND As Long = &H112
    
    Private Type POINT
      X As Long
      Y As Long
    End Type
    
    Private Type MINMAXINFO
      ptReserved As POINT
      ptMaxSize As POINT
      ptMaxPosition As POINT
      ptMinTrackSize As POINT
      ptMaxTrackSize As POINT
    End Type
    
    Private m_FixedWidth  As Long
    Private m_FixedHeight As Long
    
    Private Const WM_MOVING As Long = &H216
    Private Const WM_MOVE As Long = &H3
    Private Const WM_ACTIVATE As Long = &H6
    Private Const WM_SIZE As Long = &H5
    Private Const WM_SIZING As Long = &H214
    
    Private Declare Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
    
    Private Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
    
    Public Function Subclass(ByRef Form As VB.Form) As Boolean
     'Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, ObjPtr(Form), AddressOf SubclassProc):  Debug.Assert Subclass
     Subclass = SetWindowSubclass(Form.hWnd, AddressOf SubclassProc, AddressOf GetMinMaxInfo, AddressOf SubclassProc)
    End Function
    
    Private Function SubclassProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, _
                                  ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
     Select Case uMsg
       'Case WM_SIZING
       '  MsgBox "You are not permitted to resize this application"
       '  Exit Function
       
       'Case WM_MOVE
       '  MsgBox "You are not permitted to move this application"
       '  Exit Function
     
       'BELOW CAUSES APP TO CRASH
       Case WM_GETMINMAXINFO
         SubclassProc = CallWindowProcW(uIdSubclass, hWnd, uMsg, wParam, lParam)
         Exit Function
       
       Case WM_SYSCOMMAND
         Select Case wParam And &HFFF0&
           Case SC_CLOSE
             MsgBox "You are not permitted to close this application"
             Exit Function
           Case SC_MAXIMIZE
             MsgBox "You are not permitted to maximize this application"
             Exit Function
           Case SC_MINIMIZE
             MsgBox "You are not permitted to minimize this application"
             Exit Function
           Case SC_SIZE
             MsgBox "You are not permitted to move this application"
             Exit Function
           Case SC_RESTORE
             MsgBox "You are not permitted to restore this application"
             Exit Function
         End Select
    
       Case WM_DESTROY
         dwRefData = RemoveWindowSubclass(hWnd, dwRefData, uIdSubclass): Debug.Assert dwRefData
     End Select
    
     SubclassProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
    End Function
    
    Private Function GetMinMaxInfo(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByRef lParam As MINMAXINFO) As Long
        lParam.ptMinTrackSize.X = m_FixedWidth
        lParam.ptMinTrackSize.Y = m_FixedHeight
        lParam.ptMaxTrackSize.X = m_FixedWidth
        lParam.ptMaxTrackSize.Y = m_FixedHeight
    End Function


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  22. #22
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Tanner_H View Post
    You can use SC_MOVE (&HF010&) to detect Aero Snap events and adjust behavior accordingly.
    When I added SC_MOVE to the cases in the WM_SYSCOMMAND case, the Form became immoveable. So, how do I detect Aero Snap events?

    Quote Originally Posted by Tanner_H View Post
    Here is code I use for handling the WM_SIZING rect, ...
    I see. I didn't realize handling that message would be that complicated.



    Quote Originally Posted by jmsrickland View Post
    It still crashes
    Your code runs fine on my system. I just had to add the declaration for the CallWindowProcW API and the initialization of the m_FixedWidth and m_FixedHeight variables in the Subclass function. I compiled your code and it runs perfectly in Windows 7.

    Have you tried compiling the code I posted in your other thread without modifying any part of it? Did it work? If it did, what differences does it have with your current code?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Your code from other thread as is, untouched, runs correct.

    So it only needed the API declaration and the initializing of the two variables.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    I use WM_SIZING just to prevent user from re-sizing app so I didn't need all that other stuff.


    WM_SIZING events are fired while the user drags window edges. SC_SIZE is only sent after the user releases the mouse. If you want to make changes *during resizing*, you need to use WM_SIZING.

    I don't think so. I used both during testing and I was stopped from manually re-sizing the Form immediately on mouse down on either WM_SIZING or SC_SIZE.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  25. #25
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Bonnie West View Post
    When I added SC_MOVE to the cases in the WM_SYSCOMMAND case, the Form became immoveable. So, how do I detect Aero Snap events?
    In this case, I imagine you could check the window's size via GetWindowRect upon receiving an SC_MOVE message. If the window size is acceptable, forward the message (to still allow moving the window), but if the size is unacceptable, assume an Aero Snap function has fired (so exit the function to prevent it).
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  26. #26
    Fanatic Member
    Join Date
    Aug 2013
    Posts
    806

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by jmsrickland View Post
    WM_SIZING events are fired while the user drags window edges. SC_SIZE is only sent after the user releases the mouse. If you want to make changes *during resizing*, you need to use WM_SIZING.

    I don't think so. I used both during testing and I was stopped from manually re-sizing the Form immediately on mouse down on either WM_SIZING or SC_SIZE.
    WM_SYSCOMMAND messages (SC_SIZE, etc) are technically only supposed to be sent when "the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button." That's straight from MSDN. It's possible for these message to fire at other times, dependent on a variety of circumstances, but I'd strongly recommend against relying only on them. For accurate results, it's best to check WM_MOVE/WM_MOVING for move events, and WM_SIZE/WM_SIZING for size events.
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

  27. #27
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Quote Originally Posted by Tanner_H View Post
    In this case, I imagine you could check the window's size via GetWindowRect upon receiving an SC_MOVE message. If the window size is acceptable, forward the message (to still allow moving the window), but if the size is unacceptable, assume an Aero Snap function has fired (so exit the function to prevent it).
    Ah I see. That would indeed work.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  28. #28
    PowerPoster ThEiMp's Avatar
    Join Date
    Dec 2007
    Location
    Take The PCI Bus Across To The CPU!!
    Posts
    3,899

    Re: [RESOLVED] How to prevent a Sizable Form from being resized

    Then change the WindowsStyle for being the Border to be a nothing, or then something without. eg: None or Nothing, is there inside the Property Window, you just have to select the Form in that Property Window Box and then it will also be un resizeable, to just about anything under the sun. For example, mouse and also keyboard interactions, for example mouse clicks, mouse downs and also mouse ups. However I am still working on one myself to make it totally unmoveable, eg using the mouse move handler, to be working with a Form Sizeable property, in which the Form itself has a Border setup to as the Sizeable. Which is something of a great pain in the great behind. Cause I have to define the .Left and also the .Top properties when doing so and then being able to make the properties stick when the Form is being moved using either the keyboard or the mouse, in that type of thing...

    Code:
    Private Sub Form_Resize()
        With Form1
            .Appearance = 0
            .BorderStyle = 0
            .Caption = ""
            .Left = 100
            .Top = 100
            .Height = 100
            .Width = 100
        End With
    End Sub
    Last edited by ThEiMp; Nov 9th, 2013 at 10:47 AM.
    I have a huge free products range, of computer software in which you can download using any kind of 64-Bit Web Browser. Also there is coming a Social Networking section that I am making on my Website...

    |Ambra Productions Inc. | The Black Sun Society | The Black Shield | Ambra College | Church of the Black Sun | Ambra Productions Inc's Homepage | Boomtick Event's Venues: Ambar Nightclub, Jack Rabbit Slim's, Villa Nightclub and Lucy's Bar | Pasta Ambra | Fish Feast Company | Wallet Wizard | Ambrose Liquor | Ambar Tavern | Ambra University |

    Do you wish to do unpaid work for me??? If so, the PM me on this Forum, and then we can get to work, programming for the future of computers go by the name of ThEiMp. This is my ghost writers name. Also my nickname, means that I am: The Imperial of the Technology Industry, so then to make it really short, I just then wrote: The Imp, which is where I get the nickname from...

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