ID Number: Q80825
1.00
WINDOWS
buglist1.00
Summary:
The Windows 3.0 GetWindowRect application programming interface (API)
will give the accurate width and height of a child window created with
the MDI Child custom control in a Visual Basic application. This is
useful because the width and height property of the MDI child window
can be set to values that are too large and no longer reflect the
actual size of the MDI child window.
MDIChild.Height and Width properties will always maintain accurate
values if the mouse is used to size the MDI child window. On the other
hand, these properties can be set to values that are too large (in
code) at run time. At this point, the MDI child window will not get any
larger then the parent form, but the height and width properties will
continue to have the illegal value that was assigned to them. Using
the Windows GetWindowRect API is then an accurate way to get the
actual size and height of the MDI child window.
Microsoft has confirmed this problem with the MDI Child control in
Microsoft Professional Toolkit for Microsoft Visual Basic programming
system version 1.0 for Windows. We are researching this problem and
will post new information here as it becomes available.
More Information:
The following code example demonstrates both how to use the
GetWindowRect API and the problem with the MDIChild.width retaining an
incorrect width after being set to a large value. The width property
can be set to a larger value than the parent form, but the child
window's width will not reflect any changes in the width that makes it
larger than the container.
1. In the Visual Basic 1.0 programming environment, choose Add File
from the File menu, and select the MDICHILD.VBX custom control.
2. Select the MDI Child tool from the Toolbox.
3. Click and drag on the form to place an MDI child window control.
4. Double-click on the form to bring up the Form_Load () Code window.
From the Code window Procedure box, select the Load event.
5. Add the following code:
Sub Form_Load ()
scalemode = 3 'pixel
MdiChild1.left = 0 'this will move the MDIChild window as far
'to the left as possible
End Sub
6. From the Procedure box, select the Click event, and add the
following:
Sub Form_Click ()
'prints headings to the immediate window
Debug.Print "counter", "mdi.width", "getrect x2 - x1"
'change the width property 100 pixels at a time
For i% = 100 To 2000 Step 100
MdiChild1.width = i% 'set the width property
'Fill rectangle with the physical coordinates of the MDIChild
'window by calling an API with the handle to the MdiChild1 window
Call GetWindowRect(MdiChild1.hwnd, rectangle)
Debug.Print i%, MdiChild1.width, rectangle.x2 - rectangle.x1
Next i%
End Sub
7. In the general Declarations area for the form, dimension one
variable as follows:
Dim rectangle As rectshort
8. In the global module, add the following:
Type rectshort
x1 As Integer
y1 As Integer
x2 As Integer
y2 As Integer
End Type
Declare Sub GetWindowRect Lib "user" (ByVal thwnd%, rectangle As rectshort)
6. From the Run menu, choose Start, and click on the form outside the
child window to trigger printing to the Immediate window.
7. Click on the Immediate window to bring it into view.
The following is sample output to the Immediate window. The number
"getrect x2 - x1" will be only as big as the MDIChild1 window was able
to get. If the width of the parent form is not very large, the child
window width cannot be very large. The MDIChild1.width figure should
not be allowed to be set to a number larger than the width of the
parent form, and thus the problem.
Note: MDI.width figures represent increasing values of the
MDIChild1.width property. This property continues to get as large as
the loop counter, but the window's true width is really equal to the
figure in the getrect x2-x1 column
counter mdi.width getrect x2 - x1
100 100 100
200 200 200
300 300 300
400 400 400
500 486 486
600 600 486
700 700 486
800 800 486
900 900 486
1000 1000 486
1100 1100 486
1200 1200 486
1300 1300 486
1400 1400 486
1500 1500 486
1600 1600 486
1700 1700 486
1800 1800 486
1900 1900 486
2000 2000 486
Additional reference words: 1.00 MDIChild