怎么得到word中一个range在页面的物理位置?

Mutalisk 2008-12-29 02:00:00
如题,比如我要知道一个链接或指定词句在页面的物理地址。
...全文
195 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mutalisk 2008-12-29
  • 打赏
  • 举报
回复
嗯,我理解有问题,Range.GetInformation和ActiveWindow.GetPoint配合能取到坐标,但是必须到翻页,效率低。

我保留1天,没有更好的答案的话,就把分都给yjgx007了。
Mutalisk 2008-12-29
  • 打赏
  • 举报
回复
谢谢,但好像和我要的不太一样,我要的是range相对于word页面的坐标,不是窗体坐标。

x = range->GetInformation(wdHorizontalPositionRelativeToPage);

y = range->GetInformation(wdVerticalPositionRelativeToPage);

现在我能得到range开始的坐标,怎么能得到range的高和宽?
yjgx007 2008-12-29
  • 打赏
  • 举报
回复
http://groups.google.com/group/microsoft.public.word.vba.general/browse_thread/thread/a4aab83eca83ddc3/7793412e01a43bc8?tvc=2#7793412e01a43bc8

逻辑 是: 选选择range,得到当前active window,再得到窗体坐标(c#代码,大同小异):

            //position dialog relative to word insertion point (caret)
int left = 0;
int top = 0;
int width = 0;
int height = 0;
MSWord.Range r = Globals.ThisDocument.Application.Selection.Range;
MSWord.Window w = Globals.ThisDocument.ActiveWindow;

w.GetPoint( out left, out top, out width, out height, r );

frmPopUp newForm = new frmPopUp();
newForm.SetDesktopLocation( left + width + 2, top -
newForm.Height + height );


Mutalisk 2008-12-29
  • 打赏
  • 举报
回复
对,就是坐标
yjgx007 2008-12-29
  • 打赏
  • 举报
回复
应该是做坐标吧?

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧