Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

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
0
janineo
Asked:
janineo
  • 4
  • 4
  • 3
1 Solution
 
damiaanCommented:
dim w as long
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
0
 
damiaanCommented:
or set your bordersize to thin

in form_load:
Me.BorderStyle = 1
0
 
janineoAuthor Commented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
gwgawCommented:
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
0
 
damiaanCommented:
>Please tell me if this is even possible!
don't know about gwgaw's solution.  
but with api's it will be possible!
0
 
damiaanCommented:
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!
0
 
gwgawCommented:
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
0
 
gwgawCommented:
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.hWndAccessApp, GWL_STYLE)
dl = (382664704 And Not WS_THICKFRAME Or WS_BORDER)
lgStyle = SetWindowLong(Application.hWndAccessApp, GWL_STYLE, dl)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim dl As Long
'Reset Access window style
dl = SetWindowLong(Application.hWndAccessApp, GWL_STYLE, lgStyle)
End Sub

gaw
0
 
janineoAuthor Commented:
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
0
 
gwgawCommented:
>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?<

No

ptMinPosition
Specifies the coordinates of the window's upper-left corner when the window is minimized.
ptMaxPosition
Specifies the coordinates of the window's upper-left corner when the window is maximized.
rcNormalPosition
Specifies the window's coordinates when the window is in the restored position.

There is no SetWindowRect api.

Take a look at this one.
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=8281&lngWId=1

gaw
0
 
janineoAuthor Commented:
That's a great link, gwgaw!
Just what I wanted.
Thanks!
Janine
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now