Solved

Printing bmp problem

Posted on 1998-10-26
6
431 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 66
iSeries FTP Exit Program 8 114
dog bark java program 15 82
Annoying "thing" blocks my view 4 54
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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

12 Experts available now in Live!

Get 1:1 Help Now