Link to home
Start Free TrialLog in
Avatar of polgas
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.bmp");
      memdc.CreateCompatibleDC(pDC);
      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
Avatar of Bridge
Bridge

what does it do ? does it just print a black square??
You have to add:
Memdc.SelectObject(&bitmap);

before the BitBlt.


Dont you need a memdc.SelectObject( bitmap ) at one point ??
Avatar of polgas

ASKER

You're proposed code seems as follows:
void OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
      CBitmap (bitmap);
      CDC memdc;
      bitmap.LoadBitmap("barcd.bmp");
      memdc.CreateCompatibleDC(pDC);
      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
ASKER CERTIFIED SOLUTION
Avatar of pagladasu
pagladasu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial