从tagRECT/CRect转换为Gdiplus :: Rect

4
什么是将RECT结构体(tagRECT)或CRect转换为Gdiplus::Rect的最简单方法?
Gdiplus::Rect tmpRect(rect.top, rect.left, rect.Width(), rect.Height());

虽然可行,但需要大量键入。

2个回答

3

签名是 Rect([in] INT x, [in] INT y, [in] INT width, [in] INT height); 所以应该是:

Gdiplus::Rect CopyRect(RECT &rect)
{
    return Gdiplus::Rect(rect.left, rect.top, rect.Width(), rect.Height());
}

2
很好的发现;但是:你应该将这个作为评论添加到另一个问题中,而不是将其作为单独的答案添加(然后删除此答案)。 - BrendanMcK

2
如果Gdiplus :: Rect的接口没有方便的构造函数,您可以自己编写一个函数,并在任何地方使用它。
Gdiplus::Rect CopyRect(const RECT &rect)
{
    return Gdiplus::Rect(rect.left, rect.top, rect.Width(), rect.Height());
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接