Is it possible with the Word object model to determine what text is
visible onscreen at any particular time?

Thanks,
John

Re: Determine visible text on screen by Klaus

Klaus
Mon May 09 19:12:22 CDT 2005

"John Rodgers" <john@eco-online.com> wrote:
> Is it possible with the Word object model to determine=20
> what text is visible onscreen at any particular time?


Hi John,

Not easily, as far as I can see. The code below doesn't work too well: =
It's off by a few lines, and doesn't perfectly catch what's visible of =
those lines. Maybe I have made an error you can correct, or maybe =
.RangeFromPoint is a bit buggy.

Greetings,
Klaus


Dim pLeft As Long
Dim pTop As Long
Dim pWidth As Long
Dim pHeight As Long
Dim rngStart As Range, rngEnd As Range
Dim myDoc As Document
Set myDoc =3D ActiveDocument
With myDoc.ActiveWindow
pLeft =3D PointsToPixels(.Left)
pTop =3D PointsToPixels(.Top)
pWidth =3D PointsToPixels(.Width)
pHeight =3D PointsToPixels(.Height)
=20
Set rngStart =3D .RangeFromPoint(pLeft, pTop)
Set rngEnd =3D .RangeFromPoint(pLeft + pWidth, pTop)
rngStart.End =3D rngEnd.End
MsgBox rngStart.Text, , "First line"
Set rngStart =3D .RangeFromPoint(pLeft, pTop + pHeight)
Set rngEnd =3D .RangeFromPoint(pLeft + pWidth, pTop + pHeight)
rngStart.End =3D rngEnd.End
MsgBox rngStart.Text, , "Last line"
End With


Re: Determine visible text on screen by Klaus

Klaus
Mon May 09 21:19:23 CDT 2005

> It's off by a few lines [...]

My screen was set to 120 dpi. After I changed to 96 dpi, the results =
were much better.
Don't know if there's a setting for the screen resolution that I have =
missed, or if you'd have to do some additional calculations with 120 =
dpi.

Regards,
Klaus


Re: Determine visible text on screen by John

John
Tue May 10 12:13:38 CDT 2005

Klaus Linke wrote:
> "John Rodgers" <john@eco-online.com> wrote:
>
>>Is it possible with the Word object model to determine
>>what text is visible onscreen at any particular time?
>
>
>
> Hi John,
>
> Not easily, as far as I can see. The code below doesn't work too well: It's off by a few lines, and doesn't perfectly catch what's visible of those lines. Maybe I have made an error you can correct, or maybe .RangeFromPoint is a bit buggy.
>
> Greetings,
> Klaus
>
>
> Dim pLeft As Long
> Dim pTop As Long
> Dim pWidth As Long
> Dim pHeight As Long
> Dim rngStart As Range, rngEnd As Range
> Dim myDoc As Document
> Set myDoc = ActiveDocument
> With myDoc.ActiveWindow
> pLeft = PointsToPixels(.Left)
> pTop = PointsToPixels(.Top)
> pWidth = PointsToPixels(.Width)
> pHeight = PointsToPixels(.Height)
>
> Set rngStart = .RangeFromPoint(pLeft, pTop)
> Set rngEnd = .RangeFromPoint(pLeft + pWidth, pTop)
> rngStart.End = rngEnd.End
> MsgBox rngStart.Text, , "First line"
> Set rngStart = .RangeFromPoint(pLeft, pTop + pHeight)
> Set rngEnd = .RangeFromPoint(pLeft + pWidth, pTop + pHeight)
> rngStart.End = rngEnd.End
> MsgBox rngStart.Text, , "Last line"
> End With
>
Thanks Klaus,

I'll give it a try later today - I totally missed the PointsToPixels /
RangeFromPoint when searching thru the documentation (guess my eyes must
have glazed over...)

Thanks,
John

Re: Determine visible text on screen by Klaus

Klaus
Tue May 10 19:13:23 CDT 2005

John wrote:
> I'll give it a try later today - I totally missed the PointsToPixels / =

> RangeFromPoint when searching thru the documentation=20
> (guess my eyes must have glazed over...)


Don't think I ever used -- or even noticed -- RangeFromPoint either!
What I have used a few times is ScrollIntoView to make sure a certain =
Range or Shape is on screen.

Regards,
Klaus

Re: Determine visible text on screen by John

John
Thu May 12 15:44:18 CDT 2005

Klaus Linke wrote:
>>It's off by a few lines [...]
>
>
> My screen was set to 120 dpi. After I changed to 96 dpi, the results were much better.
> Don't know if there's a setting for the screen resolution that I have missed, or if you'd have to do some additional calculations with 120 dpi.
>
> Regards,
> Klaus
>
Hi Klaus,

I spent some time playing with this yesterday and today. I'm running my
laptop at 96 dpi and it was still off sometimes - mostly at the top but
at the bottom as well. So I snagged the HWND for the window and used
GetWindowInfo to adjust the top and heights. Things are now working
well. Thanks for your help.

Thanks,
John