Disappearing Bitmap
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Disappearing Bitmap

  1. #1
    Join Date
    Oct 2010
    Posts
    38

    Disappearing Bitmap

    Hi.
    A little trouble here, help needed.
    Basically what happens in my program is that after a little time, the bitmaps from my program simply disappear!.. leaving behind a very blank and naked background with just the GDI figures left behind... (colours from the rectangles also disappear, probably deleting the brushes).
    Why is this happening ?

    I am guessing some sort of a memory glitch..

    Any help will be appreciated.
    Thank You

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,380

    Re: Disappearing Bitmap

    Quote Originally Posted by vinayak4gargya View Post
    Hi.
    A little trouble here, help needed.
    Basically what happens in my program is that after a little time, the bitmaps from my program simply disappear!.. leaving behind a very blank and naked background with just the GDI figures left behind... (colours from the rectangles also disappear, probably deleting the brushes).
    Why is this happening ?
    I guess it is because of some bug(s) in your program.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2010
    Posts
    38

    Re: Disappearing Bitmap

    It would of help if you could tell me what might cause such behaviour...
    Any experience with this problem?

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,380

    Re: Disappearing Bitmap

    What happens with my car is that after a little time it stops running... its engine doesn't work anymore and I cannot more drive it!

    It would of help if you could tell me what might cause such behaviour...
    Any experience with this problem?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Disappearing Bitmap

    Seriously, vinayak4gargya, there's about a million things that could be wrong. You'll need to provide a lot more information on what you're doing. My guess would be that you are painting somewhere outside of the WM_PAINT handler.

  6. #6
    Join Date
    Oct 2010
    Posts
    38

    Re: Disappearing Bitmap

    I m sorry my bad my bad!

    Yes actually well i think the problem stems from the fact that i was using the same brush variable (hBrush) and initializing it again and again.

    like i was doing this ::
    ################

    hBrush = CreateSolidBrush(RGB(255,0,0));
    SelectObject(hdc,hBrush);
    .
    .
    .

    hBrush = CreateSolidBrush(RGB(255,0,0));
    SelectObject(hdc,hBrush);
    .
    .
    .
    hBrush = CreateSolidBrush(RGB(255,0,0));
    SelectObject(hdc,hBrush);
    ...
    ################
    and so on....
    so this is wrong right?? i cannot initialize the same brush again and again?

  7. #7
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Disappearing Bitmap

    Hi,

    you can initialize it for 1000 times and more, but:

    you have to Deselect it from the HDC and you have to delete it!

    Code:
    hBrush = CreateSolidBrush(RGB(255,0,0));
    HBRUSH hOldBrush = SelectObject(hdc,hBrush);
    // do something with that brush here ...
    SelectObject(hdc,hOldBrush);
    DeleteObject(hBrush);
    With regards
    Programartist

  8. #8
    Join Date
    Oct 2010
    Posts
    38

    Re: Disappearing Bitmap

    Aha so thats it!
    Thank you so much !

    And sorry for being vague in the beginning , as you can guess , i am a newbie

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center