Maximize or minimize form with button

G

Graham Mandeno

Hi Imran

I have tested Call ShowAccessSystemButtons( False ) in both Access 2003 and
Access 2007.

In A2003 it works perfectly - all three buttons (minimize, maximize/restore,
and close) at the right-hand side of the title bar disappear as expected.
This also works the same on A2007.

However, in A2003, the system menu (including the icon) at the top left also
disappears, but in A2007 the "pizza" (MS Office button) and QAT (quick
access toolbar) remain. I think it is possible to remove the QAT by using a
custom ribbon (I am not an expert in this!) but I don't think you can remove
or hide the Pizza.

Also, in both A2003 and A2007, double-clicking the title-bar still
maximizes/restored the window. I don't think their is any way to change
that either - it is intrinsic to Windows.

Sorry I can't be of more help!

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Graham (Apologies for the previous mistake and thanks for correction)
I do appreciate much your great help. I am able to change my application
title of the main window. I have applied the Call ShowAccessSystemButtons(
False ) on the form and a button also for hiding/showing the system
buttons
at the top of the main application but upto now with no success. Please do
guide in this respect where should I put my code for it to get working.


Graham Mandeno said:
Hi Imran

[you can call me "Graham" --- "Mandeno" is my family name :) ]

To hide the system buttons:
Call ShowAccessSystemButtons( False )

and to show them again:
Call ShowAccessSystemButtons( True )

Sorry, Tools > Startup in for Access 97-2003.

For Access 2007:

1. Click the round "pizza" button at the top left.

2. Click "Access Options" near bottom right.

3. Click "Current Database" in the list on the left.

You will see "Application Title" (and other things you can experiment
with)
on that screen.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

Imran Ghani said:
Hi Mandeno

Thanks a lot indeed for your very helpful code. My Application window
is
maximizing and minimizing perfectly. I'd like to appreciate for the
valuable
time which you are sharing with me. Please advise me where to put the
code
for hiding/showing the system buttons at the top of the main
application
window for it to work. Please also guide me where to find the tools
and
startup options in Access 2007. Thanks again.

:

Hi Imran

For a novice, you seem to enjoy a good challenge!

To maximize/restore the main Access window, you can use the RunCommand
method:

Application.RunCommand acCmdAppMaximize
Application.RunCommand acCmdAppRestore

To change the window title text of a form, use the form's Caption
property.

To change the title text of the main Access window, go to
Tools>Startup
and
change the "Application Title".

For hiding/showing the system buttons at the top of the main
application
window, use the code below...

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand


============ start code ==============
Option Explicit

Private Const GWL_STYLE = (-16)

Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

Private Declare Function apiSetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long _
) As Long

Private Declare Function apiGetWindowLong _
Lib "user32" _
Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long _
) As Long

Public Sub ShowAccessSystemButtons(fShow As Boolean)
Dim lStyle As Long
lStyle = apiGetWindowLong(hWndAccessApp, GWL_STYLE)
If fShow Then
lStyle = lStyle Or WS_SYSMENU
Else
lStyle = lStyle And Not WS_SYSMENU
End If
Call apiSetWindowLong(hWndAccessApp, GWL_STYLE, lStyle)
End Sub
============ end code ==============

Hi Mandeno!
Thanks again for your helpful notes. Please guide me if we can also
maximize
or restore the main window of the MS Access with some sort of code
or
settings apart from clicking at the top of the window, and also
whether
we
can change the heading coming at the top of the window, which I
think,
is
called as Forms MDI window. Can we give a title of ours own at the
top?
and
further can we remove the windows icons and buttons of all sorts
also
from
the main window. I being a novice would appreciate much your kind
help.

:

Hi Imran (or if that is your family name, then "Hi Ghani" :)

The controls on a form are always positioned from the top left-hand
corner.
This does not change if you maximize the form, so you would expect
that
everything will appear to crowd up near the corner when you
maximize
the
form. This is unavoidable.

If you want to position the contents of the form in the centre then
every
control (textbox/label/combo box/etc) will need to be repositioned
individually - not an easy task.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

message
Hi Mandeno!
Thanks a lot for your very helpful code. The code is indeed
working
great
when the form is in the Restored state, but when it is maximized
again
the
contents do not come in the center. Please do guide me for what
type
of
settings I have to look for. Are there any specific settings I
have
to
have,
apart from the function call. I am having my call function code
in
the
form
current code. I'd appreciate your kind help in this regards.

:

Hi Imran

Well, I warned you the code was serious! :)

Copy the code below and paste it into a new, empty module.

Then you can call the function winCenterInMDI from your form
code,
passing
the handle of the form's window like this:

Call winCenterInMDI(Me.hWnd)

If the form is already maximized or minimized, then it will be
restored,
then it will be centered in the Access window.

--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand

========== start code ===============
Option Compare Text
Option Explicit

Private Const cMaxBuffer = 255

Private Declare Function apiGetClassName _
Lib "user32" _
Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long

Private Declare Function apiGetWindow _
Lib "user32" _
Alias "GetWindow" _
(ByVal hWnd As Long, _
ByVal wCmd As Long) _
As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Private Declare Function apiShowWindow _
Lib "user32" _
Alias "ShowWindow" _
(ByVal hWnd As Long, _
ByVal nCmdShow As Long) _
As Long

Private Const SW_RESTORE = 9

Private Declare Function apiIsZoomed _
Lib "user32" _
Alias "IsZoomed" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiIsIconic _
Lib "user32" _
Alias "IsIconic" _
(ByVal hWnd As Long) _
As Long

Private Declare Function apiMoveWindow _
Lib "user32" _
Alias "MoveWindow" _
(ByVal hWnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) _
As Long

Private Type winRECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function apiGetWindowRect _
Lib "user32" _
Alias "GetWindowRect" _
(ByVal hWnd As Long, _
lpRect As winRECT) _
As Long

Public Function winGetHWndMDI(Optional hWndApp As Long) As Long
Dim hWnd As Long
winGetHWndMDI = 0
If hWndApp = 0 Then hWndApp = Application.hWndAccessApp
hWnd = apiGetWindow(hWndApp, GW_CHILD)
Do Until hWnd = 0
If winGetClassName(hWnd) = "MDIClient" Then
winGetHWndMDI = hWnd
Exit Do
End If
hWnd = apiGetWindow(hWnd, GW_HWNDNEXT)
Loop
End Function

Public Function winGetClassName(hWnd As Long) As String
Dim sBuffer As String, iLen As Integer
sBuffer = String$(cMaxBuffer - 1, 0)
iLen = apiGetClassName(hWnd, sBuffer, cMaxBuffer)
If iLen > 0 Then
winGetClassName = Left$(sBuffer, iLen)
End If
End Function

Public Function winCenterInMDI(hWnd As Long)
Dim MDIRect As winRECT, WndRect As winRECT
Dim lNewTop As Long, lNewLeft As Long
Dim lHeight As Long, lWidth As Long
' If the form is maximized, restore it.
If apiIsZoomed(hWnd) <> 0 Or apiIsIconic(hWnd) <> 0 Then
apiShowWindow hWnd, SW_RESTORE
End If
' Get the window size of the MDIClient window.
apiGetWindowRect winGetHWndMDI, MDIRect
' Get the window size of the MDIClient window.
apiGetWindowRect hWnd, WndRect
' Calculate Height and Width of window we are moving
With WndRect
lHeight = .Bottom - .Top
lWidth = .Right - .Left
End With
' Calculate new Top and Left coordinates
With MDIRect
lNewTop = (.Bottom - .Top - lHeight) / 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top