Win32 Programmer's Reference help file say: "An application should always replace a new object with the original, default object after it has finished drawing with the new object."
And if not?
Are the objects initialy selected deleted(?) when the DC is deleted, if they are no longer selected?
If not, can you use a syntax like this:
INVOKE SelectObject, MyhDC, MyObj
INVOKE DeleteObject, eax
.. and, at the end ...
INVOKE DeleteObject, MyObj
INVOKE DeleteDC, MyhDC
??
You will probably say :
Quote"Select a object after you create your DC, store the returned handle and, at the end, select the stored handle back, before deleting the DC".
BUt is there another way around?
AFAICT, that could be okay in some cases. I think you will run into trouble if the original object is being used elsewhere or is a stock object. Then deleting it (if that's possible) will cause problems on other DCs.
In general (re: Windows API), if it's documented that something should be done in a particular way, doing it some other way could break in the future.
Cheers,
Zooba :U
Quote from: zooba on June 29, 2006, 12:24:03 AM
AFAICT, that could be okay in some cases. I think you will run into trouble if the original object is being used elsewhere or is a stock object. Then deleting it (if that's possible) will cause problems on other DCs.
Attempts to delete stock objects will be ignored and are considered safe. Another elegant option:
Mem_Dc=CreateCompatibleDC(M_DC)
Sav_Dc=SaveDC(Mem_Dc)
... do your own stuff ...
RestoreDC(Mem_Dc,Sav_Dc)
No need to re-select old objects, Windows will do it for you: SaveDC stores all objects, RestoreDC selects them back. You will still have to destroy your own objects, of course.
yes, jojo, thanks. But will be a problem or not if I do <<Mem_Dc=CreateCompatibleDC(M_DC)>> and <<Sav_Dc=SaveDC(Mem_Dc)>> after CreateWindowEx and <<RestoreDC(Mem_Dc,Sav_Dc)>> in WM_DESTROY?
PS: This is a memory DC, not a window DC.