Solved

Set Minimum size for a form

Posted on 2003-10-24
11
653 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
  • 4
  • 4
  • 3
11 Comments
 

Expert Comment

by:damiaan
Comment Utility
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
Comment Utility
or set your bordersize to thin

in form_load:
Me.BorderStyle = 1
0
 

Author Comment

by:janineo
Comment Utility
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
 
LVL 5

Expert Comment

by:gwgaw
Comment Utility
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
Comment Utility
>Please tell me if this is even possible!
don't know about gwgaw's solution.  
but with api's it will be possible!
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:damiaan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
>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
Comment Utility
That's a great link, gwgaw!
Just what I wanted.
Thanks!
Janine
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now