I am trying to load a Bitmap, resize the bitmap to a certain size(that size will be determined at run time) & then show the bitmap on a static control
Right now my problem is in the resizing part:
I use the function StretchBlt(); to resize the bitmap but the function is returning zero which means the function failed. Can you suggest what I am doing wrong & if my code after that will copy the picture to the static control?
Some extra information that may be needed, I call this code in the message WM_CREATE & NOT in the WM_PAINT message.
void PopUpDialog :: SetStaticPicture(){ bkgdImage = (HBITMAP) LoadImage( NULL, "popupbk.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE ); // Resize Bitmap to classes private vars width & height HDC hdc = GetDC( hwnd ); HDC hdcMem = CreateCompatibleDC( hdc ); HDC hdcTar = CreateCompatibleDC( hdc ); BITMAP bm; BITMAP newBm = CreateCompatibleBitmap( hdcTar, width, height ); // I want to place the resized bitmap in this variable GetObject( bkgdImage, sizeof(bm), &bm ); SelectObject( hdcMem, bkgdImage ); // Copy the bkgdImage from the hdcMem to the newBm in hdcTar & resize it int success = StretchBlt( hdcTar, 0, 0, newBm.bmWidth, newBm.bmHeight, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY ); // the above function always fails if ( success == 0 ) { return false; } DeleteObject( &bkgdImage ); SelectObject( hdcTar, &newBm ); // Copy the contents of hdcTar(the resized bitmap) to bkgdImage bkgdImage = CreateCompatibleBitmap( hdcTar, newBm.bmWidth, newBm.bmHeight ); // Rubbish collection ReleaseDC( hwnd, hdc ); DeleteDC( hdcMem ); DeleteDC( hdcTar ); DeleteObject( &bm ); DeleteObject( &newBm ); // Set Statics background to bitmap SendMessage( hwnd, STM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) bkgdImage ); }