【问题标题】:How get object value?如何获取对象值?
【发布时间】:2015-11-02 17:13:01
【问题描述】:

我的程序必须通过#import 指令与另一个程序进行通信。它创建一个新文档并使用默认参数将 TextFrame 放置在其上

HRESULT hr = CoInitialize(NULL);
_ApplicationPtr myApp("InDesign.Application");

DocumentPtr myDoc = myApp->ActiveDocument;
PagePtr myPage = myDoc->Pages->Item[1L];
TextFramePtr myTextFrame = myPage->TextFrames->Add(); // create frame on Page
TextFramePtr myTextFrame_2 = myPage->TextFrames->Item[2L]; // Get second frame on Page;

TextFrame 对象具有改变帧大小的 GeometricBounds 方法。这是我设置帧大小的代码:

double mySize[4] = {12.7, 12.7, 66.7, 83.2};
SAFEARRAY * Bound;
VARIANT Array;
Array.vt =   VT_ARRAY | VT_R8;
Bound = SafeArrayCreateVector(VT_R8, 1, 4); 
for (int i = 0; i < 4; i++)
{
long index = i + 1;
SafeArrayPutElement(Bound, &index, &mySize[i]); 
}
Array.parray = Bound; 
myTextFrame->GeometricBounds = Array;

这是我创建的框架,但如何获取另一个框架的大小,已经存在于文档中?

Property GeometricBounds As Variant TextFrame 的边界(不包括笔划宽度),格式为 [y1, x1, y2, x2],给出边界框左上角和右下角的坐标。作为 4 个单元的数组(双精度或字符串)

TLB文件中方法的描述:

Frame : IDispatch
{
// Property data
__declspec(property(get=GetGeometricBounds,put=PutGeometricBounds))
_variant_t GeometricBounds;
...

// Methods: 
void PutGeometricBounds (
const _variant_t & _arg1 );
_variant_t GetGeometricBounds ( );
....
}

【问题讨论】:

  • 什么是myTextFrame
  • myTextFrame - 集合 TextFrames(Interface TextFrames)的元素。我更新了问题

标签: c++ com


【解决方案1】:

访问SAFEARRAY 的元素只需调用:

【讨论】:

  • 我需要将“GeometricBounds”转换为 SafeArray?
  • 既然我们不知道myTextFrame-&gt;GeometricBounds 是什么,那你就得自己解决了。
猜你喜欢
  • 2019-08-08
  • 2011-05-14
  • 2012-12-16
  • 1970-01-01
  • 1970-01-01
  • 2011-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多