Click here to Skip to main content
16,013,730 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problems with drawing Pin
S O S26-Dec-02 11:04
S O S26-Dec-02 11:04 
GeneralFor Mr.Locked Ghost Pin
HellShrimp4free26-Dec-02 11:22
HellShrimp4free26-Dec-02 11:22 
GeneralRe: For Mr.Locked Ghost Pin
S O S26-Dec-02 21:47
S O S26-Dec-02 21:47 
GeneralRe: Problems with drawing Pin
Neville Franks26-Dec-02 13:00
Neville Franks26-Dec-02 13:00 
GeneralRe: Problems with drawing Pin
S O S26-Dec-02 21:49
S O S26-Dec-02 21:49 
GeneralRe: Problems with drawing Pin
Iain Clarke, Warrior Programmer27-Dec-02 7:43
Iain Clarke, Warrior Programmer27-Dec-02 7:43 
GeneralRe: Problems with drawing Pin
S O S27-Dec-02 8:18
S O S27-Dec-02 8:18 
GeneralRe: Problems with drawing Pin
Iain Clarke, Warrior Programmer28-Dec-02 13:11
Iain Clarke, Warrior Programmer28-Dec-02 13:11 
I should have spotted this in my first reply. CDC::SelectObject (CBitmap *) returns a pointer
to a temporary CBitmap. To quote:

This function may return a pointer to a temporary object. This temporary object is only valid
during the processing of one Windows message. For more information, see CGdiObject::FromHandle


After a while, the CBitmap pointed to by bmpOld is deleted by MFC; so when you try to delete it,
an exception is raised. This is one of the reasons I use HANDLES...

You could change your class to

<br />
class CTestDC : public CDC<br />
{<br />
    ....<br />
    CBitmap    bmpOld;<br />
    ....<br />
<br />
    CTestDC (....)<br />
    {<br />
        ....<br />
        bmpOld.Attach (SelectObject (&bmpNew)->Detach ());<br />
        ....<br />
    }<br />
<br />
    ~CTestDC ()<br />
    {<br />
        SelectObject (&bmpOld);<br />
        bmpOld.Detach (); // <-- If you don't do this, then ~CBitmap will call DeleteObject, which we don't to be purist...<br />
    }<br />
}<br />


I hope this helps.

Iain.
GeneralMetafile Pin
Anthony988726-Dec-02 7:48
Anthony988726-Dec-02 7:48 
GeneralSendMessage and BN_CLICKED doesn't work Pin
User 665826-Dec-02 6:40
User 665826-Dec-02 6:40 
GeneralRe: SendMessage and BN_CLICKED doesn't work Pin
AlexO26-Dec-02 6:51
AlexO26-Dec-02 6:51 
GeneralRe: SendMessage and BN_CLICKED doesn't work Pin
User 665826-Dec-02 7:17
User 665826-Dec-02 7:17 
GeneralRe: SendMessage and BN_CLICKED doesn't work Pin
Brian Delahunty26-Dec-02 8:07
Brian Delahunty26-Dec-02 8:07 
GeneralOwner of a process Pin
Nish Nishant26-Dec-02 6:09
sitebuilderNish Nishant26-Dec-02 6:09 
GeneralRe: Owner of a process Pin
AlexO26-Dec-02 6:35
AlexO26-Dec-02 6:35 
GeneralRe: Owner of a process Pin
Nish Nishant26-Dec-02 7:19
sitebuilderNish Nishant26-Dec-02 7:19 
GeneralRe: Owner of a process Pin
Mike Nordell26-Dec-02 7:35
Mike Nordell26-Dec-02 7:35 
GeneralRe: Owner of a process Pin
Nish Nishant26-Dec-02 8:18
sitebuilderNish Nishant26-Dec-02 8:18 
GeneralRe: Owner of a process Pin
Nish Nishant26-Dec-02 8:28
sitebuilderNish Nishant26-Dec-02 8:28 
GeneralRe: Owner of a process Pin
Mike Nordell27-Dec-02 1:36
Mike Nordell27-Dec-02 1:36 
GeneralRe: Owner of a process Pin
User 665826-Dec-02 8:40
User 665826-Dec-02 8:40 
GeneralRe: Owner of a process Pin
Nish Nishant26-Dec-02 8:52
sitebuilderNish Nishant26-Dec-02 8:52 
GeneralRe: Owner of a process Pin
retZ26-Dec-02 10:45
retZ26-Dec-02 10:45 
GeneralRe: Owner of a process Pin
Nish Nishant26-Dec-02 11:38
sitebuilderNish Nishant26-Dec-02 11:38 
GeneralRe: Owner of a process Pin
AlexO26-Dec-02 11:00
AlexO26-Dec-02 11:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.