// JP opened flex table

Click to See Complete Forum and Search --> : Unable to show bitmap in static


Y0rkieP
February 26th, 2007, 02:55 PM
Hi, Im string to open a window, display test in edit controll and place a bitmap in a static controll, with a close button under it.

ok so I'v created the window, added my edit controll, added the static controll and created the close button - all works so far.

now to adthe image to the static: reading the win32.hlp it shows-

STM_SETIMAGE
wParam = (WPARAM) fImageType; // image-type flag
lParam = (LPARAM) (HANDLE) hImage; // handle of the image

wparam is IMAGE_BITMAP and using resources my image is IDB_IMAGE. on compile all is well, with no errors, my window appears and works - just no image.

my code:

win.cpp - in wm_create


ImgWin = CreateWindow ("static", 0, WS_CHILD | WS_VISIBLE |
SS_BITMAP, 351, 0, 150, 150, hwnd, NULL,
GetModuleHandle(NULL), NULL);

SendMessage(ImgWin,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)(HBITMAP)IDB_IMAGE);


in win.h

#define IDB_CLOSE 200 // button identifier
#define IDB_IMAGE 201


in res.rc

IDB_IMAGE BITMAP "c:\\dev-cpp\\examples\\win32testapp\\bg.bmp"


can anyone give me any clues?? thanks :-)

ovidiucucu
February 26th, 2007, 08:24 PM
First, call LoadBitmap (http://msdn2.microsoft.com/en-us/library/ms532309.aspx) or LoadImage (http://msdn2.microsoft.com/en-us/library/ms648045.aspx) to get the bitmap handle.
Example:

HINSTANCE hInstance = GetModuleHandle(NULL);
HBITMAP hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_IMAGE));
if(NULL != hBitmap)
{
SendMessage(ImgWin, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);
}


NOTE: Not always any cast like '(HBITMAP)IDB_IMAGE' with no compile errors does the magic... ;)

Y0rkieP
February 27th, 2007, 11:58 AM
thanks once again Ovi...

To begin with I still had probs, so added an else statment opening a message box if the bitmap handle wasnt valid.

I checked I had the hInstance in the same way, but it was the bitmap that gave me pains. I had a resource problem there as well - seems I had forgot to add the #include "main.h". once fixed, I had 1 nice little image as I wanted. I really must remember my includes.

Thanks once again Ovi.

//JP added flex table