Solved

Printing bmp problem

Posted on 1998-10-26
6
459 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 95
maven archtype selection in eclipse 1 57
Smart Camera scanning and reading information 3 113
Capture logon name 13 87
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 …
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.

861 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