Removing RESTORE and CLOSE options on maximized forms 
Author Message
 Removing RESTORE and CLOSE options on maximized forms

Q: When maximizing forms within access I always have the RESTORE and
CLOSE commands on the command bar.  I want to disable or remove or
disable those option but haven't found a way to programmatically do
that.  Any help would be appreciated.

Thanks,

Phin.



Sun, 09 Apr 2000 03:00:00 GMT  
 Removing RESTORE and CLOSE options on maximized forms

Hi Michael
The behaviour you describe is typical of an MDI interface and occurs in
Access2 and Access97 (although curiously not in Access95, see I remembered
James<g>)

James Esposito and I had a discussion about this recently and the following
code came out of that.  What the code does is resize the form to fit inside
the Access window exactly without actually maximizing it.

The method is not perfect:
    1) you have to set the form to have no border to get the best effect
    2) If you resize Access the form will not automatically resize with it,
as a maximized form does.

To call the code, in the form load event us the following call
    MaximizeRestoredForm Me

'************** Code Start *************************
  Type Rect
    x1 As Long
    y1 As Long
    x2 As Long
    y2 As Long
  End Type

  Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
  Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal _
         nCmdShow As Long) As Long
  Declare Function MoveWindow Lib "user32" (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
  Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
'Use following instead of GetWindowRect
  Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect
As Rect) As Long

  Public Const SW_MAXIMIZE = 3
  Public Const SW_SHOWNORMAL = 1

Sub MaximizeRestoredForm(F As Form)
  Dim MDIRect As Rect
  ' If the form is maximized, restore it.
  If IsZoomed(F.hwnd) <> 0 Then
    ShowWindow F.hwnd, SW_SHOWNORMAL
  End If
  ' Get the screen coordinates and window size of the
  ' MDIClient area.
'This is the line which is different
  GetClientRect GetParent(F.hwnd), MDIRect
  ' Move the form to the upper left corner of the MDIClient
  ' window (0,0) and size it to the same size as the
  ' MDIClient window.
  MoveWindow F.hwnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 -
MDIRect.y1, True
End Sub
'************** Code End ***************************

Quote:

>Q: When maximizing forms within access I always have the RESTORE and
>CLOSE commands on the command bar.  I want to disable or remove or
>disable those option but haven't found a way to programmatically do
>that.  Any help would be appreciated.

>Thanks,

>Phin.



Mon, 10 Apr 2000 03:00:00 GMT  
 Removing RESTORE and CLOSE options on maximized forms

This should work
Declare Function GetSystemMenu Lib "USER" Alias "GetSystemMenu" (ByVal hWnd
As Integer, ByVal fRevert As Integer) As Integer
Declare Function DeleteMenu Lib "USER" Alias "DeleteMenu" (ByVal hMenu As
Integer, ByVal idItem As Integer, ByVal fuFlags As Integer) As Integer
Declare Function GetActiveWindow Lib "USER" Alias "GetActiveWindow" () As
Integer

Function Mill_DeleteSystemMenu (ByVal AFlag As Integer, AForm As Form) As
Integer
'****AFlag = 0 : Child Window
'****AFlag = 1 : Parent Window
    Dim hWnd As Integer
    Dim SysMenu As Integer
    Dim I As Integer

    Mill_DeleteSystemMenu = False

    If AFlag Then
        '****Parent Window...
        '****get the Window Handle
        hWnd = GetActiveWindow()
        '****Get the system menu
        SysMenu = GetSystemMenu(hWnd, False)

        Mill_DeleteSystemMenu = True

        '****delete the last 2 entries in the menu
        For I = 0 To 1
            If DeleteMenu(SysMenu, 5, 1024) = 0 Then
                Mill_DeleteSystemMenu = False
            End If
        Next I
    Else
        '****child window...
        '****get the Window Handle
        hWnd = AForm.hWnd

        '****Get the system menu
        SysMenu = GetSystemMenu(hWnd, False)

        Mill_DeleteSystemMenu = True

        '****delete the first 3 entries in the menu
        For I = 0 To 8
            If DeleteMenu(SysMenu, 0, 1024) = 0 Then
                Mill_DeleteSystemMenu = False
            End If
        Next I
    End If

Exit Function



Quote:
> Q: When maximizing forms within access I always have the RESTORE and
> CLOSE commands on the command bar.  I want to disable or remove or
> disable those option but haven't found a way to programmatically do
> that.  Any help would be appreciated.

> Thanks,

> Phin.



Mon, 10 Apr 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to hide the maximize/restore and close-button on a maximized form

2. How to hide the maximize/restore and close-button on a maximized form

3. Help on removing the restore button on a maximized form

4. Help on removing the restore button on a maximized form

5. Disable Close, Restore Buttons on Maximized Form

6. How to hide the minimize, restore and close button on a maximized form

7. Maximized form shows Restore button when maximized

8. Maximized forms - remove close button

9. Remove restore option on forms?

10. Removing the minimize/maximize and restore buttons


 
Powered by phpBB® Forum Software © phpBB Group