PDA

Click to See Complete Forum and Search --> : BitBlt


Bjwbell
Mar 17th, 2001, 10:08 PM
Why doesn't the image get BitBlted to the form I've made sure there is an image but it still doesn't work.

int LoadPicture(HWND hwnd,HDC winHDC,double Width,double Height){
HDC ImagehDC;
LPCTSTR File;
int checkError;
File=(LPCTSTR)GlobalAlloc(GMEM_FIXED,50);
File= "C:\\Bells\\Vb6Sbs\\Less09\\Bld-up.bmp";
ImagehDC=(HDC)LoadImage(appInstance,File,IMAGE_BITMAP,Width,Height,LR_LOADFROMFILE);
if(ImagehDC==NULL){
MessageBox(hwnd,"Darn no image","Msg",MB_OK);
}
checkError=BitBlt(winHDC,0,0,Width,Height,ImagehDC,0,0,SRCCOPY);
if(checkError==0){
MessageBox(hwnd,"Darn didn't paste too form","Msg",MB_OK);
}
return 1;
}

Cybrg641
Mar 17th, 2001, 10:41 PM
I think you have to put 2 backslashes when specifying a pathname. So change your "File" variable to "C:\\Bells\\Vb6Sbs\\Less09\\Bld-up.bmp"

Bjwbell
Mar 17th, 2001, 10:50 PM
The File variable does have two back slashes but the vb-world software takes out the second backslash

Cybrg641
Mar 17th, 2001, 11:02 PM
You are passing "Width" and "Height" as doubles when they are supposed to be integers. Does that help?

Bjwbell
Mar 17th, 2001, 11:13 PM
Nope.

Bjwbell
Mar 17th, 2001, 11:18 PM
Just too make sure you know everthing.
BitBlt comes back with the number 0.

Bjwbell
Mar 18th, 2001, 02:40 AM
Sigh Looking at the api's i have too get the HDC of the BitMap for BitBlt.
Which i can't do so i have to use the SelectObject api,
But i need some help on converting the BitMap from the LoadImage api to one that is Compatible with the SelectObject api.

parksie
Mar 18th, 2001, 03:17 AM
You have to create a DC that's compatible with the window you have, using CreateCompatibleDC.

Technocrat
Mar 19th, 2001, 10:05 AM
Try this:


int LoadPicture(HWND hwnd,HDC winHDC,double Width,double Height){
HDC ImagehDC;
LPCTSTR File;
int checkError;
ImagehDC = CreateCompatibleDC(NULL); //Setup The DC
File=(LPCTSTR)GlobalAlloc(GMEM_FIXED,50);
File= "C:\Bells\Vb6Sbs\Less09\Bld-up.bmp";
SelectObject(ImagehDC,LoadImage(appInstance,File,IMAGE_BITMAP,Width,Height,LR_LOADFROMFILE)); //Put The Bitmap In The DC
//ImagehDC=(HDC)LoadImage(appInstance,File,IMAGE_BITMAP,Width,Height,LR_LOADFROMFILE);
if(ImagehDC==NULL){
MessageBox(hwnd,"Darn no image","Msg",MB_OK);
}
checkError=BitBlt(winHDC,0,0,Width,Height,ImagehDC,0,0,SRCCOPY);
if(checkError==0){
MessageBox(hwnd,"Darn didn't paste too form","Msg",MB_OK);
}
return 1;
}


Remeber to destory your DCs when you are done with DeleteDC(yourHDC);
Also remember the BitBlt does not "really" put the image there, so when ever there is a redraw, WM_PAINT, etc. the image will disappear unless you fix it to be painted when those happen. So if your image is still not being BitBlt, make sure something is not redrawing your window after you have done it.

Bjwbell
Mar 19th, 2001, 01:53 PM
Thanks a million it worked.