0

我想获得当前使用HGDIOBJ的LOGPEN结构(实际上是HPEN)。假设我们有这样的东西:

CPen ColoredPen;
ColoredPen.Create(...);
...
HGDIOBJ PriorPen = SelectObject(PaintingDC, ColoredPen);

现在我需要从 PriorPen 获取LOGPEN结构。我尝试了两种方式:

1. LOGPEN LogPen;
CPen* pPen = CPen::FromHandle((HPEN)PriorPen);
pPen->GetLogPen(&LogPen);

2. LOGPEN LogPen;
GetObject(PriorPen, sizeof(LogPen), &LogPen);

这些都没有给我一个正确的 LOGPEN 结构对象,因为所有字段都是 0。我还尝试为实际的 CPen 获取 LOGPEN,它工作得很好:

ColoredPen.GetLogPen(&LogPen);

但我只需要使用 HPEN。所以我的问题是如何从 HPEN 获得 LOGPEN?

4

1 回答 1

2

You can do the following:

LOGPEN LogPen;     
CPen* pTempPen = CPen::FromHandle(hPen);
pTempPen->GetLogPen(&LogPen);

Please note that this temporary CPen object is valid only until the next time the application has idle time in its event loop, at which time all temporary graphic objects are deleted. In other words, the temporary object is only valid during the processing of one window message.

于 2015-04-08T19:36:42.427 回答