Solved

Printing bmp problem

Posted on 1998-10-26
6
438 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 65
ffmpeg - "rtsp://...... Operation not permitted" 4 73
sumHeights  challenge 17 65
Problem to event 3 74
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now