?
Solved

Form Resizing Limits

Posted on 2003-12-01
8
Medium Priority
?
423 Views
Last Modified: 2010-05-01
Hello, regarding question: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Controls/Q_20413753.html 
how can I do it another way,The reasion why i don't want to use this, is because 1) its subclassing, but mostly 2) i am using this on a child form in a mdiform that makes it look strange when i maximize everything, I am pretty sure its incompatible with my other resize modules, however i just wanted to see if anyone can give me a diffrent metthod, (here is the code i have, but i don't want)
'===============Bas module code============
Type POINTAPI
     x As Long
     y As Long
End Type

Type MINMAXINFO
     ptReserved As POINTAPI
     ptMaxSize As POINTAPI
     ptMaxPosition As POINTAPI
     ptMinTrackSize As POINTAPI
     ptMaxTrackSize As POINTAPI
End Type

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Public Const GWL_WNDPROC = (-4)
Const WM_GETMINMAXINFO = &H24

Public OldProc As Long
Public MinWidth As Long
Public MinHeight As Long
Dim MMinfo As MINMAXINFO

Public Function WndProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  Select Case wMsg
    Case WM_GETMINMAXINFO
         CopyMemory MMinfo, ByVal lParam, LenB(MMinfo)
       ' Max/Min size when tracking
         MMinfo.ptMinTrackSize.x = MinWidth
         MMinfo.ptMinTrackSize.y = MinHeight
'         MMinfo.ptMaxTrackSize.x = MaxWidth
'         MMinfo.ptMaxTrackSize.y = MaxHeight
         CopyMemory ByVal lParam, MMinfo, LenB(MMinfo)
         Exit Function
    End Select
    WndProc = CallWindowProc(OldProc, hwnd, wMsg, wParam, lParam)
End Function

'===========Form code===========
Private Sub Form_Load()
   MinWidth = 128
   MinHeight = 128
   Me.AutoRedraw = True
   Me.Print "Minimum size of this form" & vbCrLf & "is limited to 128x128 pixels"
   OldProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call SetWindowLong(hwnd, GWL_WNDPROC, OldProc)
End Sub
'=================================
Note: this code use subclassing, so don't stop it with IDE stop button, use form [x] button to close form.
0
Comment
Question by:kwickway
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9851751
kwickway,
   It may be simpler to use VB to lock the form size

Private Sub Form_Resize()
    ' Enforcing either minimum or maximum is optional
    ' You can do one without the other
   
    'Enforce minimum size
    If Me.Height < 128 Then Me.Height = 128
    If Me.Width < 128 Then Me.Width = 128
   
    'Enforce maximum size
    If Me.Height > 3000 Then Me.Height = 3000
    If Me.Width > 3000 Then Me.Width = 3000
End Sub

Dang123


0
 

Author Comment

by:kwickway
ID: 9851821
I think i remember doing that, but it was messy looking.  Was it for you?
0
 
LVL 9

Accepted Solution

by:
Dang123 earned 150 total points
ID: 9851878
kwickway,
    I use it in a few programs to prevent the form from becoming too small and causing problems in my control resizing logic. I have had no problems, or complaints from my users. The only oddity I noticed was that you could see the resize line move smaller than allowed then "snap" back to the minimum size when the mouse was released. I would suggest you try it in your specific situation and see if you have problems. It is a small, simple snippet of code that should only take a few minutes to try.

Dang123



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:kwickway
ID: 9852011
Thanks
0
 

Author Comment

by:kwickway
ID: 9852096
do you know of any way that the form doesnt auto re-draw while your doing this?
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9852238
Sorry, I don't. I didn't need to do before.
0
 

Author Comment

by:kwickway
ID: 9853191
Ok, I accepted your awnser anyway, but if you do figure that out: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20813182.html
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9853232
Thank you.
I'll listen in on the other question so I'll know in the future.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question