Device Contexts

Started by
1 comment, last by saisoft 23 years, 5 months ago
I know you should release a device context when you are done with it, but do you also have to release compatible DC''s. I am loading a bitmap using GDI and I have a call: HDC hDc = CreateCompatibleDC(NULL); Do I have to release hDc along with my Display DC. Also I put all my code into one function to Display a bitmap on a WM_PAINT message. Everything works fine, but after minimizing and maximizing the window a few times, the image does not show up anymore, the background color(white) is just there. Maybe this has something to do with not releasing the compatible DC, but if I do I have to release that, I am not sure how to? Would it be like this, ReleaseDC(NULL,hDc2); I just tried the line ReleaseDC(NULL, hDc2) and I kept minimizing and mazimizing the application and a message popped up saying 90 percent of your resources are in use, I also used SelectObject and GetObject, do I have to Do something with those also? thanks alot, SaiSoft
Advertisement
Update - Instead of using GetDC and ReleaseDC, I used BeginPaint and EndPaint, now my resources did not continuosly go down. It worked fine, but can someone explain why using GetDC with ReleaseDC sucked up all the resources.

thanks, Saisoft
Use DeleteDC() to free a DC created with CreateCompatibleDC() (or any other non-window DC).

This topic is closed to new replies.

Advertisement