?
Solved

Set Minimum size for a form

Posted on 2003-10-24
11
Medium Priority
?
776 Views
Last Modified: 2008-01-09
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
Comment
Question by:janineo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
11 Comments
 

Expert Comment

by:damiaan
ID: 9614624
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
 

Expert Comment

by:damiaan
ID: 9614655
or set your bordersize to thin

in form_load:
Me.BorderStyle = 1
0
 

Author Comment

by:janineo
ID: 9614758
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 5

Expert Comment

by:gwgaw
ID: 9615031
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
 

Expert Comment

by:damiaan
ID: 9615132
>Please tell me if this is even possible!
don't know about gwgaw's solution.  
but with api's it will be possible!
0
 

Expert Comment

by:damiaan
ID: 9615167
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
 
LVL 5

Expert Comment

by:gwgaw
ID: 9615716
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
 
LVL 5

Expert Comment

by:gwgaw
ID: 9616236
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
 

Author Comment

by:janineo
ID: 9625809
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
 
LVL 5

Accepted Solution

by:
gwgaw earned 1000 total points
ID: 9628807
>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
 

Author Comment

by:janineo
ID: 9632635
That's a great link, gwgaw!
Just what I wanted.
Thanks!
Janine
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question