ACC1x: How to Remove the Caption Bar from a FormID: Q103261
|
There is no built-in mechanism in Microsoft Access version 1.x for removing
the caption bar from a form. The caption bar runs across the top of the
window and includes the Control menu and the minimize and maximize buttons.
Microsoft Access version 2.0 has properties you can use to remove the
minimize and maximize buttons and the Control menu. For more information,
search for "MinButton, MaxButton, and ControlBox" using the Help menu in
Microsoft Access 2.0. Or you can set the BorderStyle property to None to
remove the caption bar from the form.
This article demonstrates a sample user-defined Access Basic function
called RemoveCaptionBar() that you can use to remove the caption bar from a
form. Procedures for creating a form with no caption bar are also listed.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools
provided with Microsoft Access. For more information on Access Basic,
please refer to the "Introduction to Programming" manual.
'**************************************************************
' MODULE DECLARATION SECTION
'**************************************************************
Option Explicit
' Windows API Rect structure
Type RECT
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type
' Windows API Declarations
Declare Function SetWindowLong& Lib "User" (ByVal hwnd%, _
ByVal iindex%, ByVal style&)
Declare Function GetWindowLong& Lib "User" (ByVal hwnd%, _
ByVal iindex%)
Declare Function GetSystemMetrics% Lib "User" (ByVal iIndex%)
Declare Function GetWindowRect% Lib "User" Alias "GetWindowRect" _
(ByVal hwin%, rectangle As RECT)
Declare Function MoveWindow% Lib "User" Alias "MoveWindow" _
(ByVal hwin%, ByVal x%, ByVal y%, ByVal dx%, _
ByVal dy%, ByVal fRepaint%)
' GetWindowLong Constants
Const GWL_STYLE = -16
' Window Styles Constants
Global Const WS_CAPTION = &HC00000
' System Metrics Constants
Global Const SM_CYCAPTION = 4
'**************************************************************
' FUNCTION: RemoveCaptionBar
'
' PURPOSE:
' Removes the caption bar, which includes the system menu
' and minimize and maximize buttons, from a form.
'
' ARGUMENTS:
' F - The form object from which to remove the caption bar.
'
' USAGE:
' Enter the following for the OnOpen property of a form called
' MyForm:
'
' =RemoveCaptionBar(Forms![MyForm])
'
' SIDE AFFECTS:
' With a normal form, the form opens slightly lower than
' expected. With a dialog form (PopUp=Yes, Modal=Yes), the form
' opens slightly higher than expected. Also, you cannot close the
' form using the Microsoft Access menu; you must close it
' programmatically.
'
' If the form property Popup=No, a form is created that has a
' sizable border. Since Captions are required for sizable windows,
' screen painting problems may occur. For instance, if the frame
' of the Window is a light color, the division lines for the frame
' will display, creating an undesirable effect.
'
'***************************************************************
Function RemoveCaptionBar (F As Form)
Dim OldStyle As Long, NewStyle As Long
Dim R As RECT
Dim RetVal As Integer
Dim dx As Integer, dy As Integer
' Get the current window style of the form.
OldStyle = GetWindowLong(F.hwnd, GWL_STYLE)
' Set the window style to be the same, minus the caption bar.
NewStyle = OldStyle And Not WS_CAPTION
'Change the window style of the form.
OldStyle = SetWindowLong(F.hwnd, GWL_STYLE, NewStyle)
' The caption is removed, but the border has not snapped down
' .. onto the smaller window. We will call the Windows API to
' .. move and size the window to the same location and size,
' .. with the window shortened by the length of the caption bar.
RetVal = GetWindowRect(F.hwnd, R)
dx = R.x2 - R.x1
dy = R.y2 - R.y1 - GetSystemMetrics(SM_CYCAPTION)
RetVal = MoveWindow(F.hwnd, R.x1, R.y1, dx%, dy%, True)
End Function
Additional query words: menu bar
Keywords : kbprg
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 25, 1999