Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   problem selecting a bitmap into printer DC (http://www.go4expert.com/forums/selecting-bitmap-printer-dc-t2935/)

hlin_do 9Feb2007 22:17

problem selecting a bitmap into printer DC
 
I have a problem to SelectObject of Bitmap into memery DC. My code is like,
Code:

HINSTANCE hinstOriginal;
hinstOriginal = ::AfxGetResourceHandle();
::AfxSetResourceHandle(g_hResInstance);

CDC mem;
CBitmap *oldBmp;
CBitmap temp;
BOOL B = temp.LoadBitmap(id);  //id is resource id
BITMAP BitMap;
temp.GetBitmap(&BitMap);

mem.CreateCompatibleDC( pPrintDC );            // a printer DC
mem.SetMapMode (pPrintDC->GetMapMode ());

oldBmp = mem.SelectObject(&temp);      // this call returns 0 on some PCs!

CPoint size;
size.x = BitMap.bmWidth;
size.y = BitMap.bmHeight;
mem.DPtoLP(&size);

BOOL bret = pGDoc->m_pDC->StretchBlt(m_iX,
                m_iY*-1,
                m_iWidth,
                m_iHeight*-1,
                &mem,
                0,
                0,
                size.x,
                size.y,
                SRCCOPY);

This code works on same PC, but not on others, SelectObject returns 0;
Please help.

Thank you very much.

hlin_do

henryzlin@hotmail.com

shabbir 10Feb2007 09:40

Re: problem selecting a bitmap into printer DC
 
Check out the error code with the GetLastError.

hlin_do 13Feb2007 00:54

Re: problem selecting a bitmap into printer DC
 
GetLastError returns 0 befaore and after SelectObject call

hlin_do

shabbir 13Feb2007 09:24

Re: problem selecting a bitmap into printer DC
 
I see a definite problem here

BITMAP BitMap;

Variable is declared but not initialized

temp.GetBitmap(&BitMap);

GetBitmap should not work to the variable which is not initilaized

oldBmp = mem.SelectObject(&temp);

Obvious reason is it should fail

On some systems the garbage for BitMap may not be NULL.

hlin_do 21Feb2007 04:11

Re: problem selecting a bitmap into printer DC
 
I think I know how to make it work now. Basicly, I need to load as DIB instead bitmap.

Thanks anyway!

hlin_do


All times are GMT +5.5. The time now is 18:54.