Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

emileej

Paint fails

This topic is 5229 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

When I need my window repainted I use InvaludateRect(hWnd,NULL,TRUE); when I paint my window I CreateCompatibleBitmap for double buffering - remembering to DeleteObject afterwards. When my application has repainted a couple of times the paint suddently fails without crashing the program. This is where I go "hmm..."

Share this post


Link to post
Share on other sites
Advertisement
It simply doesnt paint anything. I just get a standard window - total blank, but I can still drag it around and minimize etc.

Share this post


Link to post
Share on other sites
Why do you CreateCompatibleBitmap everytime you paint your window? I usually only create it on a WM_SIZE (don''t know if that''s good or bad, but it works for me).
Anyway show us the code and we might spot something, this is otherwise too much of a guesswork.

Share this post


Link to post
Share on other sites
Here is the code:

//From my WndProc

case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc=BeginPaint(hwnd,&ps);
curr->Render(dc);
EndPaint(hwnd,&ps);
}
break;

//From the Render() function:

void CPage::Render(HDC dc){
RECT rt;
GetClientRect(hWnd,&rt);
HDC hdc=CreateCompatibleDC(dc);
HBITMAP bmp=CreateCompatibleBitmap(dc,rt.right-rt.left,rt.bottom-rt.top);
SelectBitmap(hdc,bmp);
FillRect(hdc,&rt,(HBRUSH)COLOR_BACKGROUND);

//- Here lots of other FillRect, LineTo etc. are done on ''hdc'' -


GetClientRect(hWnd,&rt);
BitBlt(dc,rt.left,rt.top,rt.right,rt.bottom,hdc,0,0,SRCCOPY);
DeleteObject(bmp);
}

Share this post


Link to post
Share on other sites
1) you allocated a DC and a Bitmap but you only delete the Bitmap later on, so the DC gdi-mem-leaks.

2) you have not stored the original object away the first time you call SelectObject. you have to keep the object returned by the first SelectObject (cause it''s the default object) and set it back before you delete. otherwise the system refused to delete the Bitmap silently and it gdi-mem-leaks again.

so here the correct thing:

HBITMAP vOld = SelectObject(dc, newbmp);
...
SelectObject(dc, vOld);
DeleteObject(vOld);
DeleteDC(dc)

Share this post


Link to post
Share on other sites
Lol! Sure! Thanks
My brain is so fried from long hours that I just went into a mental deadlock on the problem
Note: The ''dc'' is the HDC gained from BeginPaint(); I shouldnt delete that, should I?

Share this post


Link to post
Share on other sites
quote:
Original post by emileej
Note: The ''dc'' is the HDC gained from BeginPaint(); I shouldnt delete that, should I?


He''s referring to the one you created with HDC hdc = CreateCompatibleDC(dc);

Share this post


Link to post
Share on other sites
Ye I figured, but thanks for the highlight - thats the stuff I need when running low on brain capacity

Share this post


Link to post
Share on other sites

  • 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!