Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MSHFlexGrid Cell Resize under Win 2000
Message
From
12/06/2001 04:25:13
Jon Nelson
Trader Systems Limited
Reading, United Kingdom
 
 
To
07/06/2001 04:49:06
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00514827
Message ID:
00518234
Views:
17
>>>Hi,
>>>
>>>I have a form that uses the MSHFlexGrid control. The grid has a number of columns some of which are re-sized to accommodate all the text. The cells are re-sized using SENDMESSAGE and a RichText control. See MSDN HOWTO: Adjust RowHeight of MSFlexGrid to Accommodate WordWrap ID: Q178127.
>>>
>>>The form works fine under Windows NT 4.0 but the cell resizing gives the wrong results under Windows 2000.
>>>
>>>The problem appears to be the number of lines of text returned by SendMessage is incorrect.
>>>
>>>Has anybody had the same problem - and found any solutions???
>>>
>>>Many thanks
>>>
>>>Jon Nelson
>>>
>>>The fragment of the code that resizes the cell is show:
>>>----------------------------------------------------------
>>>* MSHFlexGrid name gOrders
>>>* RichTX32 control name rtbText
>>>
>>>LPARAMETER lRow,lCol
>>>
>>>* Select the Cell
>>>thisform.gOrders.row=lRow
>>>thisform.gOrders.col=lCol
>>>
>>>lnColTwips=thisform.gOrders.cellwidth
>>>
>>>* set the width of the textbox to the width of the column (pixels)
>>>thisform.rtbText.width=lnColTwips/thisform.twipsperpixelX
>>>
>>>* set the Rich text control text to the grid cell text
>>>thisform.rtbText.text=ALLTRIM(thisform.gOrders.text)
>>>
>>>* Get the height of a line of text (Pixels)
>>>HeightOfLine=thisform.textheight(left(ALLTRIM(thisform.rtbText.text),1))
>>>
>>>* Get the number of lines of text in the Rich text control
>>>#DEFINE EM_GETLINECOUNT 186
>>>LinesOfText=SendMessage(thisform.rtbText.hWnd,EM_GETLINECOUNT,0,0)
>>>
>>>nHeightOfLineTwips=int(HeightOfLine * thisform.twipsperpixelY)
>>>
>>>* Calculate the required height of the Row
>>>lnReqHeight= LinesOfText*nHeightOfLineTwips
>>>
>>>IF thisform.gOrders.RowHeight(lRow) < lnReqHeight
>>> thisform.gOrders.RowHeight(lRow) = lnReqHeight
>>>ENDIF
>>
>>
>>I have tried to replace the SENDMESSAGE way of determining the number of lines of text by using the RichTx32 GetLineFromChar method. Again this works perfectly under Win NT4.0 but returns the wrong result under Win2000. I'm using VFP6 SP4 but see from MSDN that under VFP5.0 this was a problem. (PRB: GetLineFromChar Method Does Not Function in VFP 5.0 ID: Q198425)
>>
>>Any ideas???
>
>Jon,
>I didn't use rtbtext and don't know if it has purpose there other than getting linecount. This was working for me under w2k :
>
>
LPARAMETER tnRow,tnCol
>with thisform.Hflex
> .Row = tnRow
> .Col = tnCol
> lcText = .Text
> lcFontStyle = iif(.CellFontItalic or .CellFontBold, ;
>   iif(.CellFontBold,'B','')+iif(.CellFontItalic,'I',''), 'N')
> lnColWidthInChars = .CellWidth/thisform.nXTwips/;
>   fontmetric( 6, .CellFontName, .CellFontSize, lcFontStyle )
> lnOldMemoWidth = set('memowidth')
> set memowidth to lnColWidthInChars
> lnLines = memlines(lcText)+1
> set memowidth to lnOldMemoWidth
> lnLineHeight = fontmetric( 1, .CellFontName, .CellFontSize, ;
>  lcFontStyle ) * thisform.nYtwips
> .RowHeight(tnRow) = lnLines * lnLineHeight
>endwith
PS:If the fontname, size and style used for hflex is constant then code might greatly be optimized without setting to individual row-col. This would be important if you're doing this for all rows (see TextArray to get text and ColWidth to get width for a specific col of band). OTOH you could speed up with doing this before it's visible too.
>Cetin


Thanks - that is certainly better than the results I was getting on Win2k - although it is still not 'perfect'. Despite setting all fonts styles etc to the same values - this method still occationally mis-calculates the number of lines required (+/- 1 line)....

I would still like to know why the SENDMESSAGE or GetLineFromChar returns different results under Win2k and Win NT....


Thanks
Previous
Reply
Map
View

Click here to load this message in the networking platform