Solved

Form Resizing Limits

Posted on 2003-12-01
8
403 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 50 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
Industry Leaders: 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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