June 12, 1995
This article explains how you can create a multiple-document interface (MDI) form that has a fixed border in a Microsoft® Visual Basic® application.
Every form you create when designing a Microsoft® Visual Basic® application can have one of four border styles. Just set the form's BorderStyle property to one of the following styles.
Property | Style |
0 | None |
1 | Fixed Single |
2 | Sizeable |
3 | Fixed Double |
An MDI child form, however, does not have a BorderStyle property. But by using the Microsoft Windows® GetWindowLong and SetWindowLong application programming interface (API) functions , you can change an MDI form's border style to a fixed border style.
The GetWindowLong function retrieves information about the specified window's style attributes and the SetWindowLong function modifies the specified window's style attributes.
GetWindowLong requires only two arguments. The first argument is the target window's handle. The second argument specifies the type of information you want to retrieve, which is the style settings for the window.
After retrieving the window's current style settings, use the bitwise And Not function to remove the WS_THICKFRAME attribute from the style settings value. Next, issue a call to the SetWindowLong function to set the new style settings for the specified window. This creates an MDI form that has a fixed border style.
This program shows how to create an MDI form that has a fixed border. Run the example program by pressing F5. The MDI form will be displayed with a fixed border.
Private Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal
nIndex As Integer) As Long
Private Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal
nIndex As Integer, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Private Sub MDIForm_Load()
Dim CurStyle As Long
Dim NewStyle As Long
CurStyle = GetWindowLong(MDIForm1.hWnd, GWL_STYLE)
NewStyle = SetWindowLong(MDIForm1.hWnd, GWL_STYLE, CurStyle And
Not (WS_THICKFRAME))
End Sub
"GetSystemMenu." (MSDN Library Archive, Product Documentation, SDKs, Windows 3.1 SDK, Programmer's Reference, Volume 2: Functions)
Knowledge Base Q118376. "How to Lock a Form So It Cannot Be Moved."
Knowledge Base Q110393. "How to Remove Menu Items from a Form's Control-Menu Box."
Knowledge Base Q77930. "Modifying the System Menu of an MDI Child Window."
Knowledge Base Q71669. "Preventing an MDI Child Window from Changing Size."