Programming Tips - How do I load a resource bitmap into a GDI+ bitmap?

Date: 2008jul12 Library: GDI+ Language: C/C++ OS: Windows Q. How do I load a resource bitmap into a GDI+ bitmap? A. Use this function:
Bitmap *ResourceToBitmap(const HINSTANCE hInstance, const int id) { HBITMAP hBmp = ::LoadBitmap(hInstance, MAKEINTRESOURCE(id)); if (bBmp == NULL) return NULL; return Bitmap::FromHBITMAP(hBmp, NULL); } void ExampleUse() { Bitmap *pBitmap; pBitmap = ResourceToBitmap(AfxGetInstanceHandle(), IDB_MY_BITMAP); printf("Size is %d x %d\n", pBitmap->GetWidth(), pBitmap->GetHeight()); }