Microsoft KB Archive/117234

{| = BUG: WCOLS and WROWS Do Not Match SIZE Clause =
 * width="100%"|

ID: Q117234

The information in this article applies to:


 * Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
 * Microsoft FoxPro for Macintosh, version 2.5b, 2.5c

SYMPTOMS
The value returned by WCOLS or WROWS is not consistent with the values specified after the SIZE clause of a DEFINE WINDOW command.

CAUSE
When the SIZE clause of the DEFINE WINDOW command is used to define a window, the resulting window will be one pixel higher and one pixel wider than expected. The difference between the values reported by WCOLS or WROWS and the specified size will vary if the window contains a scroll bar or if clauses other than SIZE, FROM, and FONT are specified after the DEFINE WINDOW command.

RESOLUTION
When the SIZE clause is used with the DEFINE WINDOW command, the resulting window will always be one pixel higher and one pixel wider than specified. If the additional pixel is not desired, you must specify lower values after the SIZE clause so a window of the desired height and width can be defined. Since the FONTMETRIC function can be used to determine the size of the differential, you can calculate the values that must be used to compensate for this behavior. For examples of how to perform these calculations, see the "More Information" section below.

NOTE: This solution applies only to windows that are defined with the DEFINE WINDOW clause and for which no clauses other than SIZE, FROM, and FONT are specified. This solution does not apply to windows with scroll bars.

STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here as it becomes available.

MORE INFORMATION
The following code sample demonstrates and explains the difference between the values returned by WCOLS and WROWS and the values specified after the SIZE clause of the DEFINE WINDOW command:

mfont = "Courier New" msize = 10

mbegcol = 2 mbegrow = 2 msizerow = 30 msizecol = 50

* A window is defined. This window will have the size, * coordinates, and font attributes specified above.

DEFINE WINDOW test ; FROM mbegcol,mbegrow ; SIZE msizerow,msizecol ; FONT mfont,msize

ACTIVATE WINDOW test

* The value returned by WROWS will be larger than the * value specified for the size of the window. In this * particular example, WROWS will be 30.063. This is  * larger than the specified size by a value of 0.063.

? "WROWS   = "+STR(WROWS,10,3) ? "SIZE ROWS = "+STR(msizerow,10,3) ? "DIFFERENCE = "+STR(WROWS-msizerow,10,3) ?

* The value returned by WCOLS will be larger than the * value specified for the size of the window. In this * particular example, WCOLS will be 50.125. This is  * larger than the specified size by a value of 0.125.

? "WCOLS   = "+STR(WCOLS,10,3) ? "SIZE COLS = "+STR(msizecol,10,3) ? "DIFFERENCE = "+STR(WCOLS-msizecol,10,3) ?

* These lines are used to show the height and width for * the font that was specified after the FONT clause of  * the DEFINE WINDOW command for this window. In this * example, we see that Courier New has a width of 8 pixels * and a height of 16 pixels.

? "WIDTH(Pixels) = "+STR(FONTMETRIC(6,mfont,msize),2,0) ? "HEIGHT(Pixels) = "+STR(FONTMETRIC(1,mfont,msize),2,0) ?

* The "DIFFERENCE" numbers shown above were calculated by  * subtracting the value returned by WROWS from the number * of rows specified after the SIZE clause and by subtracting * the value returned by WCOLS from the number of columns * specified after the SIZE clause. The same difference * values can be calculated with the formulas shown below. * The difference between the value returned by WROWS and * the value specified after the SIZE clause is equal to  * 1/pixel width. In this case, 1/8 = .125, which is  * precisely the value shown as the "row difference" above.

? "DIFFERENCE/ROWS (1/Pixels) = " + ; STR(1/FONTMETRIC(1,mfont,msize),10,3) ? "DIFFERENCE/COLS (1/Pixels) = " + ; STR(1/FONTMETRIC(6,mfont,msize),10,3)

?

= INKEY(0)

RELEASE WINDOW test The following code samples can be used to convert between the expected values and the actual values. The code samples shown below assume that a window is defined in the manner illustrated above; that is, the memory variable names used in the example above are used in these code samples. Actual numeric or character values can be used instead of variables. To determine the number of rows that were specified after the SIZE clause of the DEFINE WINDOW command, this code can be executed when the window is active:

? WROWS - 1/FONTMETRIC(1,mfont,msize) To determine the number of columns that were specified after the SIZE clause of the DEFINE WINDOW command, this code can be executed when the window is active: ? WCOLS - 1/FONTMETRIC(6,mfont,msize) The following code produces a window of the desired size when the SIZE clause of the DEFINE WINDOW command is used to specify the size of the window: mfont = "Courier New" msize = 10 mbegcol = 2 mbegrow = 2 msizerow = 30 msizecol = 50

msizerow = msizerow - 1/FONTMETRIC(1,mfont,msize) msizecol = msizecol - 1/FONTMETRIC(6,mfont,msize)

DEFINE WINDOW test ; FROM mbegcol,mbegrow ; SIZE msizerow,msizecol ; FONT mfont,msize Additional reference words: FoxMac FoxWin 2.50 2.50a 2.50b 2.50c 2.60 buglist2.50 buglist2.50a buglist2.50b buglist2.50c buglist2.60 KBCategory: kbenv kbprg kbbuglist KBSubcategory: FxenvMemory
 * }