I am trying to load a .bmp into an HBITMAP and then copy a portion of it into a new memory HBITMAP. I am pretty familiar with device contexts, memory bitmaps, and GDI - but I think I am missing something about HBITMAP creation. I've read and reread everything on the net but nothing has a complete code sample for this simple task so my efforts have been futile.

The following code (simplified) produces black squares on the screen - what am I missing?

//first load the source bitmap from a file - this works fine and will print to
// the screen with no problem
HBITMAP hbmsource = (HBITMAP)LoadImage(NULL,filepath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

//get the screen device context
CDC* pDC = GetDC();

//create two memory dcs compatible with the screen
HDC memDCsource = CreateCompatibleDC(pDC->m_hDC);
HDC memDCtarget= CreateCompatibleDC(pDC->m_hDC);

//select the source bitmap into the source DC
HBITMAP pOldBitmap1 = (HBITMAP)SelectObject(memDCsource,hbmsource);

//create a new bitmap compatible with the screen dc
HBITMAP hbmtarget = CreateCompatibleBitmap(pDC->m_hDC,w,h);

//.....I suspect that I am missing something here required to create the new
// bitmap... ie bitmap header, CreateDIB, etc. - I thought that CreateCompatibleBitmap
//covered all that.....

//select the new bitmap into the target dc
HBITMAP pOldBitmap2 = (HBITMAP)SelectObject(memDCtarget,hbmtarget);

//bitblt the source to the target
BitBlt(memDCtarget,0,0,w,h,memDCsource,0,0,SRCCOPY);

//cleanup
SelectObject(memDCsource,pOldBitmap1);
SelectObject(memDCtarget,pOldBitmap2);
DeleteDC(memDCsource);
DeleteDC(memDCtarget);

ReleaseDC(pDC);

.......Now when I try and display the new HBITMAP on the screen it is all black.

thanks for any help