I am using C++11 and Code::Blocks 17.12 and compiling on a 32 bit system. NO Visual Studio. NO .net. I plan to compile this later on a 64 bit system. I have two options that currently work with this code. I am trying to find out which is better.
Which is better: to use HBITMAP outside or to use CreateCompatibleBitmap inside as I show in the following?
I call the function that these are in often as I am moving images around on a window.
Option 1 Using HBITMAP outside:
1 2 3 4 5 6
|
//HBITMAP is An object handle that manages bitmap data.
HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
SelectObject(hdcWorkingBackBuffer, hbmBuffer);
DeleteObject(hbmBuffer);
| |
Option 2 Using CreateCompatibleBitmap inside.
1 2 3 4
|
// without HBITMAP
SelectObject(hdcWorkingBackBuffer, CreateCompatibleBitmap(hdc, prc->right, prc->bottom));
| |
I think that with Option 1 of using HBITMAP uses up more cpu and memory resources, but maybe I might be able to use hbmBuffer as a global so as to not have to create it and destroy it each time that I run the function. But I do not know what HBITMAP holds; the color palate (which will not change) or dimensions (which will not change) or the actual pixel data (which WILL change).
I think that if the image changes and if the HBITMAP holds the actual pixel data , and if the pixel data changes, then is Option 2 better?
Thank you for your help.
I tested this and Option 2 locks up the program in a few seconds of running. Why? Is it because CreateCompatibleBitmap uses up memory and is not automatically deleted when the function ends, as I have read that C++11 does automatically? Does it do something outside of the function's clean-up scope? Does that mean that I should avoid creating inside other code as in Option 2 because it is harder for the compiler to clean up at the end of a function? I think maybe. Further question: Where can I find documentation on this?