PDA

Click to See Complete Forum and Search --> : Putting a bitmap on a dialog


Bad5887
Jul 16th, 2000, 11:18 PM
HOw can i do this? this is what i tryed:

extern void LoadBack(HWND hBack)
{
HANDLE bDC;
HANDLE hBit;
HANDLE BitDC;
bDC=GetDC(hBack);
hBit=LoadResource(hInst,600);
BitDC=GetDC(hBit);
BitBlt(bDC,(long)30,(long)30,(long)50,(long)50,BitDC,(long)0,(long)0,SRCCOPY); //(int)"&HCC0020");




}

in C, and i pass the dialog's handle to this function, the resource #600 is a bitmap i wanna use for the dialog. how can i load a bitmap from a resource and Bitblt it onto the dialog?

Wulf
Jul 25th, 2000, 10:15 AM
This should work. The code was designed for a CView, but it should be compatible. You will have to specify a string resource ID though instead of a number.

extern void LoadBack(HWND hBack)
{
CDC* cdc=NULL;
HDC hDC=NULL;
CBitmap* bmp=NULL;
HBITMAP hbmp=NULL;

hbmp=(HBITMAP)LoadImage(NULL,"BMP_ID",IMAGE_BITMAP,100,100, NULL);
bmp=bmp->FromHandle(hbmp);
cdc=cdc->FromHandle(hDC);
cdc->CreateCompatibleDC(pDC);
CBitmap* oldbmp=(CBitmap*)hDC.SelectObject(bmp);

pDC->BitBlt(0,0,100,100,cdc,0,0,SRCCOPY);

cdc->SelectObject(oldbmp);
delete cdc;
}

Bad5887
Jul 25th, 2000, 11:22 AM
Thanks, but it is incompatable, first it says undeclared identifier for 'CDC' and there is like 50 other errors, i'm trying to do this with the LCC 32bit C compiler and api, I can't get it to work:( Also, in VC++, when making a bitmap in the resource, it only allows number values for the resource. So how would i do this. I'm stuck:(

Wulf
Jul 25th, 2000, 08:01 PM
As usual, I forgot about couple things :) I'm more confidant about this code though.

extern void LoadBack(HWND hBack)
{
CDC* cdc=NULL,pDC=new CDC;
HDC hDC=NULL;
CBitmap* bmp=new CBitmap;

if(!bmp->LoadBitmap(BMP_ID))
return;

hDC=GetDC(hBack);
cdc=cdc->FromHandle(hDC);
cdc->CreateCompatibleDC(pDC);
CBitmap* oldbmp=(CBitmap*)cdc->SelectObject(bmp);

pDC->BitBlt(0,0 ,100 ,100 ,cdc,0,0,SRCCOPY);

ReleaseDC(hBack,hDC);
cdc->SelectObject(oldbmp);
delete cdc;
}

If one of your errors was similar to
"error C2065: 'CDC' : undeclared identifier"
then use this. Note: you will have to supply an application instance. AfxGetInstanceHandle() can be used, but if you have access to the Afx... commands you should be able to declare CDC, CBitmap, etc. The other source is a HINSTANCE passed to WinMain()

extern void LoadBack(HWND hBack)
{
HDC hDC=NULL;
HBITMAP bmp=NULL;
LPCSTR strBmpID;

strBmpID=MAKEINTRESOURCE(BMP_ID);
bmp=LoadBitmap(programInstance,strBmpID)
if(bmp==(HBITMAP)NULL)
return;

hDC=GetDC(hBack);

BitBlt(hDC,0,0 ,100 ,100 ,cdc,0,0,SRCCOPY);

ReleaseDC(hBack,hDC);
}