Solved

Form Resizing Limits

Posted on 2003-12-01
8
385 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
 

Author Comment

by:kwickway
ID: 9852011
Thanks
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now