Solved

Printing bmp problem

Posted on 1998-10-26
6
451 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:polgas
6 Comments
 
LVL 1

Expert Comment

by:Bridge
ID: 1323851
what does it do ? does it just print a black square??
0
 
LVL 1

Expert Comment

by:motigust
ID: 1323852
You have to add:
Memdc.SelectObject(&bitmap);

before the BitBlt.


0
 
LVL 1

Expert Comment

by:Bridge
ID: 1323853
Dont you need a memdc.SelectObject( bitmap ) at one point ??
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:polgas
ID: 1323854
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...............

0
 
LVL 1

Expert Comment

by:jdyer
ID: 1323855
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
0
 
LVL 4

Accepted Solution

by:
pagladasu earned 70 total points
ID: 1323856
Let us say you are going to load the bitmap file and not the resource.
Add this code
              HBITMAP m_hBitmap;
      m_hBitmap=(HBITMAP)::LoadImage(
            NULL,"barcd.bmp",IMAGE_BITMAP,
            0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
      CBitmap *mbmp=CBitmap::FromHandle(m_hBitmap);
              CDC *memDC=new CDC;
      memDC->CreateCompatibleDC(pDC);
      memDC->SelectObject(mbmp);
              pDC->BitBlt(10,10,500,500,memDC,0,0,SRCCOPY);
              delete memDC;

0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 92
Looking for a specific application/software 2 110
matchUp  challenge 6 64
MaxSpan challenge 9 96
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question