PDA

Visualizza la versione completa : come limitare il ridimensionamento di un form?


micR
12-09-2002, 21:23
Salve ragazzi vorrei realizzare un form tipo le palette mobili di dreamweaver, che si possono ridimensionare, ma fino ad una certa dimensione, come faccio ad implementare una cosa simile con vb?
grazie
:ciauz:

bDaniele
13-09-2002, 09:05
non conosco vb ma credo che senz'altro c' un evento onResize o qualcosa di simile, quindi qui dovresti imporre le dimensioni massime solo se vengono superate.

triky
13-09-2002, 11:01
un modo che conosco, ma piuttosto bruttino da vedere inserire una consizione nell'evento resize:
if form.height < 1000 then exit sub
se nn trovi altro usa questo

Utente Standard
13-09-2002, 11:48
Nella procedura callback della finestra cattura il messaggio "WM_GETMINMAXINFO" e passagli una struttura "MINMAXINFO" che contiene la dimesione MIN/MAX

Utente Standard
13-09-2002, 11:51
ECCO IL CODICE per VB.



Option Explicit

Private Sub Form_Load()
'Save handle to the form.
gHW = Me.hwnd

'Begin subclassing.
Hook
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Stop subclassing.
Unhook
End Sub

'''''''''''''''''''''
'IN THE MODULE WRITE:
'''''''''''''''''''''

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

Global lpPrevWndProc As Long
Global gHW 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 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 Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Sub CopyMemoryToMinMaxInfo Lib "KERNEL32" Alias _
"RtlMoveMemory" (hpvDest As MINMAXINFO, ByVal hpvSource As Long, _
ByVal cbCopy As Long)
Private Declare Sub CopyMemoryFromMinMaxInfo Lib "KERNEL32" Alias _
"RtlMoveMemory" (ByVal hpvDest As Long, hpvSource As MINMAXINFO, _
ByVal cbCopy As Long)

Public Sub Hook()
'Start subclassing.
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub

Public Sub Unhook()
Dim temp As Long

'Cease subclassing.
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Dim MinMax As MINMAXINFO

'Check for request for min/max window sizes.
If uMsg = WM_GETMINMAXINFO Then
'Retrieve default MinMax settings
CopyMemoryToMinMaxInfo MinMax, lParam, Len(MinMax)

'Specify new minimum size for window.
MinMax.ptMinTrackSize.x = 200
MinMax.ptMinTrackSize.y = 200

'Specify new maximum size for window.
MinMax.ptMaxTrackSize.x = 500
MinMax.ptMaxTrackSize.y = 500

'Copy local structure back.
CopyMemoryFromMinMaxInfo lParam, MinMax, Len(MinMax)

WindowProc = DefWindowProc(hw, uMsg, wParam, lParam)
Else
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, _
wParam, lParam)
End If
End Function

triky
13-09-2002, 15:53
mhh interessante

questo potra essere utila anche a me
thx:metallica

micR
14-09-2002, 20:45
grazie per il codice.... lo stesso che ho trovato su MSDN, ma sinceramente speravo di trovare qualcosa che funzionazza altrettanto bene, ma senza subclassing!!!

cmq quello sopra funge bene!:ciauz:

Loading