Ich hab mir mal gedacht ich poste euch diesen source, da es sicher einige gibt die ihn gebrauchen können.
Hiermit kann man also ein Minumum und Maximum der Fenstergröße festlegen.
Code in ein Modul einfügen.
Code:
Option Explicit
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 CopyMemory1 Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Sub CopyMemory2 Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Any, Source As Any, ByVal Length As Long)
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
Public Type SIZEPAR
xMin As Long
yMin As Long
xMax As Long
yMax As Long
End Type
Private Const GWL_WNDPROC As Long = -4&
Private Const WM_GETMINMAXINFO As Long = &H24&
Private WinOldProc As Long
Private spR As SIZEPAR
Private Frm As Form
Public Sub Init(F As Form, R As SIZEPAR)
spR = R
Set Frm = F
WinOldProc = SetWindowLong(Frm.hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnHook()
Call SetWindowLong(Frm.hWnd, GWL_WNDPROC, WinOldProc)
End Sub
Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam&) As Long
Dim Result As Long
Dim MM As MINMAXINFO
If uMsg = WM_GETMINMAXINFO And Frm.WindowState = 0 Then
Call CopyMemory1(MM, lParam, Len(MM))
Call CopyMemory2(lParam&, MM, Len(MM))
Result = DefWindowProc(hWnd, uMsg, wParam, lParam)
Else
Result = CallWindowProc(WinOldProc, hWnd, uMsg, wParam, lParam)
End If
WindowProc = Result
End Function
Benutzung:
Code in Form_Load einfügen.
Code:
'Form limitieren
'#######################
Dim R As SIZEPAR
With R
.xMax = Screen.Width
.yMax = Screen.Height
.xMin = 725
.yMin = 560
End With
Call Init(main_frm, R)
'#######################
Bei xMin und yMin könnt ihr dann die Größe festlegen.
xMax und yMax wird in diesem Fall die Maximale Größe des Bildschirmes übergeben.
Achtung
Beim debuggen verursacht diese Funktion Probleme. Vb6 hängt, bzw. stürzt dann ab.
Am besten beim coden als Kommentar einfügen und erst vorm kompilieren aktivieren.
mfg, ZiG _________________ Wer nicht auf seine Weise denkt, denkt überhaupt nicht. (Oscar Wilde)
Es gibt nur ein Problem mit der maximalen Größe: Die Funktion erwartet die Größenangaben in Pixel, Screen.Width und Screen.Height geben aber die Bildschirm Größe in Twips zurück, man kann das Fenster also wesentlich größer machen als den Bildschirm (bei mir 15 mal weil bei mir 1 Pixel 15 Twips entspricht). Bei dem Funktionsaufruf müsste also stehen:
Code:
'Form limitieren
'#######################
Dim R As SIZEPAR
With R
.xMax = Screen.Width / Screen.TwipsPerPixelX
.yMax = Screen.Height / Screen.TwipsPerPixelY
.xMin = 725
.yMin = 560
End With
Call Init(main_frm, R)
'#######################
Und generell gilt: die Größenangaben, die die Funktion erwartet sind in Pixel und VB arbeitet fast Immer mit Pixeln, wenn also Größen angaben von VB verwendet werden müssen sie fast immer erst durch Screen.TwipsPerPixelX oder Screen.TwipsPerPixelY geteilt werden.
Was mir noch auffällt ist das die Funktion immer nur mit einer Form funktioniert, wenn man versucht die Funktion von mehreren Formen gleichzeitig zu benutzen gibt es Probleme. Bevor die Funktion von einer anderen Form aufgerufen wird sollte immer erst die Funktion UnHook aufgerufen werden. _________________
ZiG_ Überflieger
Anmeldedatum: 07.03.2007 Beiträge: 1248
Verfasst am: 04.02.2008, 16:30
Stimmt. Daran hab ich nicht gedacht. _________________ Wer nicht auf seine Weise denkt, denkt überhaupt nicht. (Oscar Wilde)