
How to hide the minimize, restore and close button on a maximized form
> Thanks for posting this solution. I had to abandon Microsoft's solution
> in Q210299 and Q128196. Regards Geoff
Hello,
The code in Q210299 needed a slight fix to make it work, and the
explanation of how to use it didn't really make sense. I prefer resizing
the form, rather than clunking about with a phantom toolbar that hides
the close button.
My solution and fix is as follows:
The error in Microsoft's code is on the 2nd last line, which contains
the "MoveWindow" command. Their original code had the parameters ending
with "+ 4", where they should have been "- 4", as I have them.
Also - don't forget to save and close your form and run it from the
closed state, or you will run into that Access quirk where it cannot
correctly resize a form if it is run by transitioning directly from
design view to form view. And in this case there is an additional depth
to this quirk in that the form resize takes place before the design
toolbars are removed, so there is a gap between the top of the form and
the bottom of the default toolbars. So you must run the form from the
closed state when using this code.
Overview of how to use this:
1) Put the code in the Form_Load event.
2) Set the form properties as follows: Border Style = None Control Box =
No Min Max Buttons = None Close Button = No
3) Make sure the form is closed when you run it.
NOTE: If you cut and paste this, take out all the line wraps so each
line of code is on its own line.
Type Rect X1 As Long Y1 As Long X2 As Long Y2 As Long End Type
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect
As Rect) As Long 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
Public Const SW_MAXIMIZE = 3 Public Const SW_SHOWNORMAL = 1
Sub Main(F As Form) Dim MDIRect As Rect If IsZoomed(F.hwnd) <> 0 Then
ShowWindow F.hwnd, SW_SHOWNORMAL End If GetWindowRect GetParent(F.hwnd),
MDIRect MoveWindow F.hwnd, 0, 0, MDIRect.X2 - MDIRect.X1 - 4, MDIRect.Y2
- MDIRect.Y1 - 4, True End Sub
Hope this helps everyone, Matt
--
Posted via dBforums
http://dbforums.com