How does one determine the number of lines per page in a Richedit control?
Currently I'm using the following code to determine the lines per page:
Sub GetFontMetrics(ByVal hCtl As Dword, _
ByVal sText As String, _
CX As Long, _
CY As Long, _
Optional ByVal sPad As String)
LOCAL hDC AS DWORD
LOCAL hFnt AS DWORD
LOCAL uSize AS SIZEL
'-----------------------------------------------------------------------
sText = sText + sPad 'Pad text, make sure we have enough width.
hDC = GetDC(hCtl)
DIALOG SEND hCtl, %WM_GETFONT, 0, 0 TO hFnt
hFnt = SelectObject(hDC, hFnt)
GetTextExtentPoint32 hDC, BYVAL STRPTR(sText), LEN(sText), uSize
SelectObject hDC, hFnt
ReleaseDC hCtl, hDC
CX = uSize.cx
CY = uSize.cy
END SUB
And...
Function GetLinesPerPage(ByVal hCtl As Dword) As Long
LOCAL CX AS LONG
LOCAL CY AS LONG
LOCAL lPageRows AS LONG
LOCAL rc AS RECT
'-----------------------------------------------------------------------
GetWindowRect hCtl, rc
Call GetFontMetrics(hCtl, "Dummy", CX, CY)
lPageRows = FIX((rc.nBottom - rc.nTop) / CY)
FUNCTION = lPageRows
END FUNCTION
The only problem is the value returned is just about 60% of the total lines per page for the Richedit control. Obviously the uSize.CY value being returned is too large to calculate the correct value. Tried looking in POFFS and on line, but nothing I found seems to cover this issue.
TIA
I haven't researched your question but your code does look good except for the DIALOG SEND message. Have you tried using the SendMessage instead:
DIALOG SEND hCtl, %WM_GETFONT, 0, 0 TO hFnt
hFnt = SendMessage( hCtl, %WM_GETFONT, 0, 0 )