|
-
May 2nd, 2003, 10:57 AM
#1
RESOLVED - Resize/repos controls with API form min width/height
I implemented a minimum form size by like so:
VB Code:
'An excerpt, not everything.
Private booResize
Private Sub Form_Resize()
If booResize Then 'To prevent an infinite loop due to Form_Resize().
If Me.WindowState <> vbMinimized Then
booResize = False
If Me.Height < 5400 Then
Me.Height = 5400
End If
If Me.Width < 6150 Then
Me.Width = 6150
End If
'blah blah code for controls
End If
End If
End Sub
Problem is, you can still drag the border to less than the minimum. And that causes a flicker. The effect I wanted was something similar to Yahoo chat windows, wherein you can't drag into the minimum. Can someone pls help me and give me code, especially if its API?
Last edited by leinad31; May 3rd, 2003 at 04:34 AM.
-
May 2nd, 2003, 11:50 AM
#2
-
May 2nd, 2003, 11:59 AM
#3
Fanatic Member
This has been answered numerous times.
-
May 2nd, 2003, 01:43 PM
#4
I couldn't get crptcblade's to work. I'm waiting for his reply.
I also couldn't get this to work.
http://www.vbforums.com/showthread.p...oto=nextoldest
I got "Invalid property value", but it hanged so I don't know where in the code.
What I need is the code that will apply to several instances of a template form. Its for a chat program, min dimensions for each chat form.
-
May 2nd, 2003, 01:50 PM
#5
Originally posted by leinad31
I couldn't get crptcblade's to work. I'm waiting for his reply.
If it can wait, then I'll be able to put together a more flexible version later on tonight.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 2nd, 2003, 01:54 PM
#6
-
May 2nd, 2003, 02:18 PM
#7
The code you're trying to use is setup to handle subclassing a single form/window.
In order to use this on multiple instances, you need to add handling for each window, i.e.
In a Module
VB Code:
Option Explicit
Private Const GWL_WNDPROC = (-4)
Private Const WM_GETMINMAXINFO = &H24
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type MINMAXINFO
ptReserved As POINTAPI
ptMaxSize As POINTAPI
ptMaxPosition As POINTAPI
ptMinTrackSize As POINTAPI
ptMaxTrackSize As POINTAPI
End Type
Private 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" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Public Sub SubClass(ByVal hwnd As Long)
Dim lPrevWndProc As Long
If GetProp(hwnd, "MinSizeHandler") <> 0 Then Exit Sub
lPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
Call SetProp(hwnd, "MinSizeHandler", lPrevWndProc)
End Sub
Public Sub RemoveSubClass(ByVal hwnd As Long)
If GetProp(hwnd, "MinSizeHandler") = 0 Then Exit Sub
Call SetWindowLong(hwnd, GWL_WNDPROC, GetProp(hwnd, "MinSizeHandler"))
Call SetProp(hwnd, "MinSizeHandler", 0)
End Sub
Private Function WindowProc(ByVal hwnd As Long, ByVal nMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tMINMAX As MINMAXINFO
Dim lPrevWndProc As Long
lPrevWndProc = GetProp(hwnd, "MinSizeHandler")
If nMsg = WM_GETMINMAXINFO Then
Call CallWindowProc(lPrevWndProc, hwnd, nMsg, wParam, lParam)
Call CopyMemory(tMINMAX, ByVal lParam, Len(tMINMAX))
tMINMAX.ptMinTrackSize.x = 200
tMINMAX.ptMinTrackSize.y = 200
Call CopyMemory(ByVal lParam, tMINMAX, Len(tMINMAX))
WindowProc = DefWindowProc(hwnd, nMsg, wParam, lParam)
Else
WindowProc = CallWindowProc(lPrevWndProc, hwnd, nMsg, wParam, lParam)
End If
End Function
Example Usage:
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim oForm As Form1
Set oForm = New Form1
oForm.Show
End Sub
Private Sub Form_Load()
SubClass hwnd
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
RemoveSubClass hwnd
End Sub
-
May 2nd, 2003, 02:38 PM
#8
Thanks. I think I figured out why I got the "Invalid property value". I hadn't deleted my Form_Resize() code, stupid me.
In my original code, I also resized and/or repositioned controls on the form. Where do I insert the code for this with your function? And how do I refer to the controls? I'm resizing/repositioning 2 frames and their contents: richtextbox, labels, command button, image controls (control arrays), and line controls (control arrays).
Last edited by leinad31; May 2nd, 2003 at 03:00 PM.
-
May 3rd, 2003, 02:04 AM
#9
-
May 3rd, 2003, 04:17 AM
#10
PowerPoster
VB Code:
Private Sub Form_Resize()
If Me.WindowState = vbNormal Then
Me.Width = 4800
Me.Height = 3600
End If
End Sub
Works for me
-
May 3rd, 2003, 04:32 AM
#11
Thanks, it does work. Strangely I kept getting erros last night.
-
May 3rd, 2003, 04:37 AM
#12
PowerPoster
Perphaps u were just checking for the windowstate = vb minimzed and not for vbmaximized...I have put for vbnormal....hence it works...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|