Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Drawing Grid Lines on MFC

This topic is 2912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 
void CPinterView::InitializeGrid()
{
DrawGrid();
}

void CPinterView::DrawGrid()
{
int Spacing = gEnd / gGridNum;
int i;
CDC *dc = GetDC();
CPen newPen(PS_SOLID, 5, RGB(0,0,255));
CPen *oldPen = dc->SelectObject(&newPen);
for (i = 0; i < gEnd; i+=Spacing);
{

dc->MoveTo(i,0);
dc->LineTo(i,gEnd);
}
for (int j = 0; j < gEnd; j+=Spacing)
{
dc->MoveTo(0,j);
dc->LineTo(gEnd,j);
}

dc->SelectObject(oldPen);
Invalidate(true);

}



I have initialized gEnd(5000),Spacing and gGridNum(30)
I have called the function from OnCreate of CView
But I can't see anything from the view.
Any ideas?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement
The painting in a view should be called inside OnDraw. You should NOT draw onto its DC outside of a paint call.

Right now your grid drawing is done, and then you call InvalidateRect. MFC in turn will call the OnDraw function drawing over your grid lines again.

Put your DrawGrid call inside OnDraw near the end.

Share this post


Link to post
Share on other sites
Quote:
You should NOT draw onto its DC outside of a paint call.
Not always strictly true, but that's certainly the OP's problem in this case.

I have to ask the question though ... why on earth use MFC for a game? Using it for anything at all these days is bad enough, but for a game it's even more particularly ill-suited. Have you considered XNA, or even just a pure Win32 program?

Share this post


Link to post
Share on other sites
Quote:
Original post by Echkard
Quote:
You should NOT draw onto its DC outside of a paint call.
Not always strictly true, but that's certainly the OP's problem in this case.

I have to ask the question though ... why on earth use MFC for a game? Using it for anything at all these days is bad enough, but for a game it's even more particularly ill-suited. Have you considered XNA, or even just a pure Win32 program?


Just testing some pathfinding stuff...
Been fiddling around with Pinter's code. Because he has lost part of the source code, tried to rebuild that. So that's the story.
Thanks
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!