Thread: Program Crashing, overuse of CreateBitmap() ?

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    31

    Program Crashing, overuse of CreateBitmap() ?

    Hi, I have a program that's really simple, it just creates a window and fills the screen with the color red. It does this by having a global HBITMAP that is defined in a function that uses CreateBitmap() in my WinMain() function and it is also called when handling the WM_SIZE message. Now, I've made workarounds for this that are simple and only really involve removing the call to CreateBitmap(). Now, I'm not entirely familiar with structs and am VERY new to windows programming, and I'm not sure if I have to free up the space formerly used by the HBITMAP before creating a new one. I would have thought that some sort of garbage collection would take care of this for me? Any thoughts are appreciated.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You need to call DeleteObject on the HBITMAP to free the memory used by the bitmap. If you asign something else to your HBITMAP variable without freeing it then the memory used by the previous bitmap is leaked.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    31
    Awesome, things seem to be working fine now. Thanks a bunch.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. need help program crashing
    By tunerfreak in forum C++ Programming
    Replies: 14
    Last Post: 05-22-2006, 11:29 AM
  3. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM