Introduction

Here, I am introducing a function SBitdraw(CDC *pDC, UINT nIDResource, int i) to load any bitmap to a dialog. There are so many ways by which we can load a bitmap. Here, I am giving a function which you can just add to your project and get the result. No need to add any other header files or .cpp files.

Comments and Discussions

All the m_bitmap objects created in the redraw handler will not be freed. However, the tricky thing is that you code may not work if you delete m_bitmap, becuase the SelectObject() may need it even outside the function. As indicated by YoSilver, you should load the bitmap only once. You normally place it to a memory DC and copy the memory to the screen each time you redraw. BTW, this technique is called "double buffering", which also helps to avoid flickering.