polgas
asked on
Printing bmp problem
I have a simple code used in printing bmp in my app.:
OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CBitmap bitmap;
CDC memdc;
bitmap.LoadBitmap("barcd.b mp");
memdc.CreateCompatibleDC(p DC);
pDC->BitBlt(0, 0, 100, 100, &memdc, 0, 0, SRCCOPY);
}
This code won't print the bmp "barcd.bmp". pls. help me work out this proble....or can you modify this simple code to work.... thanks
OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CBitmap bitmap;
CDC memdc;
bitmap.LoadBitmap("barcd.b
memdc.CreateCompatibleDC(p
pDC->BitBlt(0, 0, 100, 100, &memdc, 0, 0, SRCCOPY);
}
This code won't print the bmp "barcd.bmp". pls. help me work out this proble....or can you modify this simple code to work.... thanks
what does it do ? does it just print a black square??
You have to add:
Memdc.SelectObject(&bitmap );
before the BitBlt.
Memdc.SelectObject(&bitmap
before the BitBlt.
Dont you need a memdc.SelectObject( bitmap ) at one point ??
ASKER
You're proposed code seems as follows:
void OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CBitmap (bitmap);
CDC memdc;
bitmap.LoadBitmap("barcd.b mp");
memdc.CreateCompatibleDC(p DC);
memdc.SelectObject(&bitmap );
pDC->BitBlt(0, 0,100,100, &memdc, 0, 0, SRCCOPY);
}
but i'm afraid, the same problem occured......
the barcd.bmp exists in the proj directory to be sure...............
void OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
CBitmap (bitmap);
CDC memdc;
bitmap.LoadBitmap("barcd.b
memdc.CreateCompatibleDC(p
memdc.SelectObject(&bitmap
pDC->BitBlt(0, 0,100,100, &memdc, 0, 0, SRCCOPY);
}
but i'm afraid, the same problem occured......
the barcd.bmp exists in the proj directory to be sure...............
well I would atleast change
pDC->BitBlt( 0, 0, 100, 100, &memdc, 0, 0, SRCCOPY );
to
pDC->BitBlt( 0, 0, bitmap.Width(), bitmap.Height(), &memdc, 0, 0, SRCCOPY );
ALSO,
The "barcd.bmp" must be a RESOURCE withing the EXECUTABLE file, not a separate file within the (current) working directory! Thus, you will need to add the bitmap to the project as a RESOURCE, name it (you could keep 'barcd.bmp') and then call your code. If I am understanding your problem correctly, this should work!
Regards,
jdyer
pDC->BitBlt( 0, 0, 100, 100, &memdc, 0, 0, SRCCOPY );
to
pDC->BitBlt( 0, 0, bitmap.Width(), bitmap.Height(), &memdc, 0, 0, SRCCOPY );
ALSO,
The "barcd.bmp" must be a RESOURCE withing the EXECUTABLE file, not a separate file within the (current) working directory! Thus, you will need to add the bitmap to the project as a RESOURCE, name it (you could keep 'barcd.bmp') and then call your code. If I am understanding your problem correctly, this should work!
Regards,
jdyer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.