// JP opened flex table

Click to See Complete Forum and Search --> : Bitmap background -- classic problem


asalways
September 21st, 2007, 12:00 AM
I'd like to load a bitmap as a background

In WinMain, I do

HWND hWnd=CreateWindow(
__FILE__,"Lovely Dragon",
(WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME ^ WS_MAXIMIZEBOX) | WS_VISIBLE,
CW_USEDEFAULT,CW_USEDEFAULT,
rc.right-rc.left,rc.bottom-rc.top,
NULL,NULL,hInstance,NULL);
if(hWnd==NULL) return 0;

but in WM_CREATE message processing, i do
HDC hdc;
PAINTSTRUCT ps;
HBITMAP hBitmap;
HINSTANCE hInst;
static BITMAP bitmap;
static HDC hBackDC,hMemDC;

sweet(msg){
case WM_CREATE:
// hBitmap=(HBITMAP)LoadImage((HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),"Winter.bmp",IDB_BITMAP1,0,0,LR_LOADFROMFILE); OR
hInst=(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE);
hBitmap=LoadBitmap(hInst,"IDB_BITMAP1");
if(hBitmap==NULL){
MessageBox(hWnd,"Program fini","Background image fails to bloaded",MB_OK);
SendMessage(hWnd,WM_DESTROY,0,0);
return 0;
}

GetObject(hBitmap,sizeof(BITMAP),&bitmap);
hdc=GetDC(hWnd);
hBackDC=CreateCompatibleDC(hdc);
SelectObject(hBackDC,hBitmap);
DeleteObject(hBitmap);

hBitmap=CreateCompatibleBitmap(hdc,(int)bitmap.bmWidth,(int)bitmap.bmHeight);
hMemDC=CreateCompatibleDC(hdc);
ReleaseDC(hWnd,hdc);
SelectObject(hMemDC,hBitmap);
DeleteObject(hBitmap);

//Someother messages
}




its compiled with no error or warning, but its executed with hBitmap==NULL, after I press the OK button in MessageBox Program finish, the window is show without drawing anything on client
LoadImage or LoadBitmap fail in the same way

Thanks a lot

Ali Imran
September 22nd, 2007, 10:28 PM
Is ok if you load bitmap in WM_CREATE event, but drawing is usualy put under WM_PAINT event.

And make sure IDB_BITMAP1 really is the right ID of the bitmap object.
Secondly is just a thought (am not sure about it), try this:

hBitmap=LoadBitmap(GetModuleHandle(NULL),"IDB_BITMAP1");


maybe becuase hInst is NULL.

regards

//JP added flex table