?
Solved

Form Resizing Limits

Posted on 2003-12-01
8
Medium Priority
?
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

743 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