質問

I'm using MFC (but this would also apply to Win32) and I have a view I want to draw. So I am overriding the OnDraw method. Here's a bit of psuedocode, I'm coding like this:

void OnDraw(DC* pDC)
{
  foreach(Node n in nodes)
  { 
    n->DrawOnCanvas(pDC)
  }
}

I thought this was a nice OO solution. But I've run into a problem. I now want to draw a border around the initial DC, but I don't want the nodes to know about this. I want the nodes to still draw relative to a full canvas size starting from 0,0 (and not know about an offset). If I give the nodes knowledge about the border in the parent window it seems messy.
How do you solve problems like this? How can I define a new DC that is relative to an existing one?

役に立ちましたか?

解決

You don't make a new DC, you set the origin on the existing one. So in your loop, before DrawOnCanvas(), you'd use CDC::SetViewportOrg() and friends. See http://msdn.microsoft.com/en-us/library/46t66w7t.aspx . You can also implement scaling, scrolling etc this way.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top