janineo
asked on
Set Minimum size for a form
Hi,
I have a main form which is maximized to the Access window.
The access window is set to a certain size when the form is opened, but the size can be changed.
I would like to stop users making the access window (and hence the form) smaller than the first size it is opened at.
I have tried using the API calls suggested in other threads, but it just goes into a sort of loop and doesn't respond to anything.
Please help!
Janine
I have a main form which is maximized to the Access window.
The access window is set to a certain size when the form is opened, but the size can be changed.
I would like to stop users making the access window (and hence the form) smaller than the first size it is opened at.
I have tried using the API calls suggested in other threads, but it just goes into a sort of loop and doesn't respond to anything.
Please help!
Janine
or set your bordersize to thin
in form_load:
Me.BorderStyle = 1
in form_load:
Me.BorderStyle = 1
ASKER
Sorry, this isn't what I need.
It works on the form, but when the Access Window itself is sized, it seems to overule the form settings.
Maybe I didn't explain myself properly.
When I say Access Window, I do not mean the Database Window, but the instance of Access itself in which all the other windows sit, and to which the menus are attached.
I have a main form that opens when my Access mdb is opened. This form has no border and is maximized to the Access Window. The Access Window is then sized programmatically to what will be it's minimum size.
I need to stop the Access Window getting any smaller. Stopping a form getting too small has no effect on the Access Window.
Please tell me if this is even possible!
Janine
It works on the form, but when the Access Window itself is sized, it seems to overule the form settings.
Maybe I didn't explain myself properly.
When I say Access Window, I do not mean the Database Window, but the instance of Access itself in which all the other windows sit, and to which the menus are attached.
I have a main form that opens when my Access mdb is opened. This form has no border and is maximized to the Access Window. The Access Window is then sized programmatically to what will be it's minimum size.
I need to stop the Access Window getting any smaller. Stopping a form getting too small has no effect on the Access Window.
Please tell me if this is even possible!
Janine
Add variables to your main form's declaration section.
Dim accWidth As Long
Dim accHeight As Long
Set accWidth or accHeight to Access window size on form open.
In the form's on timer event check if accWidth or accHeight is equal to 0. If they are then get Access window size into variables and exit sub.
If they are greater than 0 then get Access window size and compare to these variables and resize Access window as needed. You may also want to check if Access is minimized or maximized and react accordingly.
gaw
Dim accWidth As Long
Dim accHeight As Long
Set accWidth or accHeight to Access window size on form open.
In the form's on timer event check if accWidth or accHeight is equal to 0. If they are then get Access window size into variables and exit sub.
If they are greater than 0 then get Access window size and compare to these variables and resize Access window as needed. You may also want to check if Access is minimized or maximized and react accordingly.
gaw
>Please tell me if this is even possible!
don't know about gwgaw's solution.
but with api's it will be possible!
don't know about gwgaw's solution.
but with api's it will be possible!
my guess is
Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
and SetWindowRect / SetWindowPlacement
...
good luck!
Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
and SetWindowRect / SetWindowPlacement
...
good luck!
To maintain Access window position and size.
Add this to your main form's declaration section. Set the form's TimerInterval to 100.
Dim rcAcc As RECT
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Form open and timer events.
Private Sub Form_Open(Cancel As Integer)
Dim WP As WINDOWPLACEMENT
'Get Access position and size into rcAcc
WP.Length = Len(WP)
GetWindowPlacement Application.hWndAccessApp, WP
rcAcc = WP.rcNormalPosition
End Sub
Private Sub Form_Timer()
Dim rc As RECT, WP As WINDOWPLACEMENT
Dim lgWid As Long, lgHgt As Long
WP.Length = Len(WP)
'Get Access position and size
GetWindowPlacement Application.hWndAccessApp, WP
'If Access is maximized or minimized then quit
If WP.showCmd = SW_MAXIMIZE Or WP.showCmd = SW_MINIMIZE Then Exit Sub
'Check if rcAcc has been set
If rcAcc.Right = 0 Or rcAcc.Bottom = 0 Then
rcAcc = WP.rcNormalPosition
Exit Sub
End If
WP.rcNormalPosition = rcAcc
SetWindowPlacement Application.hWndAccessApp, WP
End Sub
gaw
Add this to your main form's declaration section. Set the form's TimerInterval to 100.
Dim rcAcc As RECT
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Form open and timer events.
Private Sub Form_Open(Cancel As Integer)
Dim WP As WINDOWPLACEMENT
'Get Access position and size into rcAcc
WP.Length = Len(WP)
GetWindowPlacement Application.hWndAccessApp,
rcAcc = WP.rcNormalPosition
End Sub
Private Sub Form_Timer()
Dim rc As RECT, WP As WINDOWPLACEMENT
Dim lgWid As Long, lgHgt As Long
WP.Length = Len(WP)
'Get Access position and size
GetWindowPlacement Application.hWndAccessApp,
'If Access is maximized or minimized then quit
If WP.showCmd = SW_MAXIMIZE Or WP.showCmd = SW_MINIMIZE Then Exit Sub
'Check if rcAcc has been set
If rcAcc.Right = 0 Or rcAcc.Bottom = 0 Then
rcAcc = WP.rcNormalPosition
Exit Sub
End If
WP.rcNormalPosition = rcAcc
SetWindowPlacement Application.hWndAccessApp,
End Sub
gaw
Here's another way.
Place this in form's declaration section
Dim lgStyle As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Const WS_THICKFRAME = &H40000
Then in form's open and unload events.
Private Sub Form_Open(Cancel As Integer)
Dim dl As Long
'Get Access window style and change border style to allow no sizing
dl = GetWindowLong(Application. hWndAccess App, GWL_STYLE)
dl = (382664704 And Not WS_THICKFRAME Or WS_BORDER)
lgStyle = SetWindowLong(Application. hWndAccess App, GWL_STYLE, dl)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim dl As Long
'Reset Access window style
dl = SetWindowLong(Application. hWndAccess App, GWL_STYLE, lgStyle)
End Sub
gaw
Place this in form's declaration section
Dim lgStyle As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 Const GWL_STYLE = (-16)
Private Const WS_BORDER = &H800000
Private Const WS_THICKFRAME = &H40000
Then in form's open and unload events.
Private Sub Form_Open(Cancel As Integer)
Dim dl As Long
'Get Access window style and change border style to allow no sizing
dl = GetWindowLong(Application.
dl = (382664704 And Not WS_THICKFRAME Or WS_BORDER)
lgStyle = SetWindowLong(Application.
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim dl As Long
'Reset Access window style
dl = SetWindowLong(Application.
End Sub
gaw
ASKER
gwgaw,
Thanks, but this isn't quite what I'm after. Your first solution allowed a user to make the form smaller than the minimum, and then sprang it back to the minimum after they let go of the mouse. The second solution didn't allow the user to make it larger, which I do want to allow.
Is there a way of combining them, so the user can make it bigger, but not allow the form size to move with the mouse after a minimum size has been reached?
I can use the GetWindowPlacement function to get the size of the window at the beginning.
I just need somewhere to put some code so that the minimum size is not gone past.
Is the 'ptMinPosition As POINTAPI' in the WINDOWPLACEMENT type a minimum size, or a minimum position where the top left of the window can go?
Damiaan,
I couldn't find a SetWindowRect API call. Can you provide one for me?
Thank you,
Janine
Thanks, but this isn't quite what I'm after. Your first solution allowed a user to make the form smaller than the minimum, and then sprang it back to the minimum after they let go of the mouse. The second solution didn't allow the user to make it larger, which I do want to allow.
Is there a way of combining them, so the user can make it bigger, but not allow the form size to move with the mouse after a minimum size has been reached?
I can use the GetWindowPlacement function to get the size of the window at the beginning.
I just need somewhere to put some code so that the minimum size is not gone past.
Is the 'ptMinPosition As POINTAPI' in the WINDOWPLACEMENT type a minimum size, or a minimum position where the top left of the window can go?
Damiaan,
I couldn't find a SetWindowRect API call. Can you provide one for me?
Thank you,
Janine
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's a great link, gwgaw!
Just what I wanted.
Thanks!
Janine
Just what I wanted.
Thanks!
Janine
dim h as long
Private Sub Form_Load()
w = me.width
h = me.height
End Sub
Private Sub Form_Resize()
if me.height < h then me.height = h
If Me.Width < w Then Me.Width = w
End Sub
(or was it Me.WindowHeight / me.WindowWidth ?)
kind regards