Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Adding tabs to a CTabCrtl Pin
Ravi Bhavnani3-Oct-02 15:24
professionalRavi Bhavnani3-Oct-02 15:24 
GeneralRe: Adding tabs to a CTabCrtl Pin
monrobot135-Oct-02 8:38
monrobot135-Oct-02 8:38 
GeneralRe: Adding tabs to a CTabCrtl Pin
Ravi Bhavnani5-Oct-02 8:41
professionalRavi Bhavnani5-Oct-02 8:41 
GeneralRe: Adding tabs to a CTabCrtl Pin
Daniel Strigl2-Oct-02 10:40
Daniel Strigl2-Oct-02 10:40 
GeneralRe: Adding tabs to a CTabCrtl Pin
Ravi Bhavnani2-Oct-02 10:54
professionalRavi Bhavnani2-Oct-02 10:54 
GeneralRe: Adding tabs to a CTabCrtl Pin
Daniel Strigl2-Oct-02 19:17
Daniel Strigl2-Oct-02 19:17 
GeneralRe: Adding tabs to a CTabCrtl Pin
Ravi Bhavnani3-Oct-02 5:01
professionalRavi Bhavnani3-Oct-02 5:01 
Questionwhy i print out nothing? Pin
wangnanjing30-Sep-02 16:25
wangnanjing30-Sep-02 16:25 
Wink | ;) Hi,everyone:

I want to print a picture drawn in one of my windows.
The picture's base class is a CChart named m_chart.

The print programme is as following:

CWnd *pWnd = &m_chart;
CWindowDC dcWnd(pWnd);
CDC memDC;
CRect rect;


HBITMAP bmp;
CBitmap bitmap0;

memDC.CreateCompatibleDC(&dcWnd);

pWnd->GetWindowRect(rect);

bitmap0.CreateCompatibleBitmap(&dcWnd, rect.Width(),rect.Height() );
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap0);

CPrintDialog dlg(FALSE);
if (dlg.DoModal() ==IDOK)
{
// Create a CDC object for the device context we got
CDC dcPrinter;
dcPrinter.Attach(dlg.m_pd.hDC);

// Determine width, height and orientation

LPDEVMODE pDM = dlg.GetDevMode();

int dmOrientation = pDM->dmOrientation;
int Width = dcPrinter.GetDeviceCaps(HORZRES) - 100;
int Height = dcPrinter.GetDeviceCaps(VERTRES) - 100;

// Describe print job to print spooler
DOCINFO docInfo;
docInfo.cbSize = sizeof(docInfo);
docInfo.fwType = 0;
docInfo.lpszDocName = "Print Thermal Schedule!";
docInfo.lpszOutput = NULL;
docInfo.lpszDatatype = NULL;


// Start a document
if (0 < dcPrinter.StartDoc(&docInfo))
{
// Start a page; you might call StartPage/EndPage more than once;
// you'll have one call pair for each page you print.

if (0 < dcPrinter.StartPage())
{
// measure the printable page
int nOffsetX = dcPrinter.GetDeviceCaps(PHYSICALOFFSETX);
int nOffsetY = dcPrinter.GetDeviceCaps(PHYSICALOFFSETY);

int nHorzRes = dcPrinter.GetDeviceCaps(HORZRES);
int nVertRes = dcPrinter.GetDeviceCaps(VERTRES);

// load bitmap from file

bmp = NULL;
//bmp = (HBITMAP)bitmap0.GetSafeHandle();
//bmp = (HBITMAP) bitmap0;
HDC hdc;
bmp = (HBITMAP) dcWnd.GetCurrentBitmap()->m_hObject;
dcWnd.SelectGdiObject(hdc,bmp);

CBitmap bitmap;
bitmap.Attach (bmp);

// copy bitmap into memory DC

CDC dcMemory;
dcMemory.CreateCompatibleDC(&dcPrinter);

CBitmap* pOldBitmap = dcMemory.SelectObject(&bitmap);

BITMAP bm;
bitmap.GetBitmap(&bm);

// determine magnification

double Magnification;
double MagnificationW = (double)Width / (double)bm.bmWidth;
double MagnificationH = (double)Height / (double)bm.bmHeight;
Magnification = MagnificationW >= MagnificationH ? MagnificationH :
MagnificationW;

int iBitMap_X = (int)((double)bm.bmWidth * Magnification);
int iBitMap_Y = (int)((double)bm.bmHeight * Magnification);

int iOffset_X = (dcPrinter.GetDeviceCaps(HORZRES) - iBitMap_X - 50) / 2;
int iOffset_Y;

if (dmOrientation == 1) iOffset_Y = 50;
else iOffset_Y = (dcPrinter.GetDeviceCaps(VERTRES) - iBitMap_Y) / 2;

// stretch memory DC into printer DC
dcPrinter.StretchBlt(iOffset_X, iOffset_Y, iBitMap_X,
iBitMap_Y,&dcMemory,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);//dcMemory

dcMemory.SelectObject(pOldBitmap);

// close the page
dcPrinter.EndPage();
}
else
{
MessageBox("Couldn't start new page!");
}

// close the document. Printing actually starts now!
dcPrinter.EndDoc();
}
else
{
MessageBox("Couldn't start document.");
}
}
else
{
MessageBox("You have no default printer. You must set a default printer before priting.");
}


When I degugged,I can see the value of bmp and the length of iBitMap_X and so so.
I likes that I have got the handle to the bmp.
But I print nothing out.

Can you tell me why?

thanks a lot.


wang
AnswerRe: why i print out nothing? Pin
Chris Losinger30-Sep-02 16:27
professionalChris Losinger30-Sep-02 16:27 
GeneralPointer Elements & STL Containers :: STL Pin
valikac30-Sep-02 15:53
valikac30-Sep-02 15:53 
GeneralRe: Pointer Elements & STL Containers :: STL Pin
Chris Losinger30-Sep-02 16:24
professionalChris Losinger30-Sep-02 16:24 
GeneralRe: Pointer Elements & STL Containers :: STL Pin
RedZenBird30-Sep-02 17:46
RedZenBird30-Sep-02 17:46 
GeneralRe: Pointer Elements & STL Containers :: STL Pin
valikac30-Sep-02 18:00
valikac30-Sep-02 18:00 
GeneralString String! Pin
sherry_ca30-Sep-02 15:39
sherry_ca30-Sep-02 15:39 
GeneralRe: String String! Pin
Chris Losinger30-Sep-02 16:26
professionalChris Losinger30-Sep-02 16:26 
GeneralRe: String String! Pin
sherry_ca30-Sep-02 16:58
sherry_ca30-Sep-02 16:58 
GeneralRe: String String! Pin
Chris Losinger30-Sep-02 17:25
professionalChris Losinger30-Sep-02 17:25 
GeneralCList and flat DB Pin
G. White30-Sep-02 14:23
G. White30-Sep-02 14:23 
GeneralRe: CList and flat DB Pin
RedZenBird30-Sep-02 17:53
RedZenBird30-Sep-02 17:53 
GeneralRe: CList and flat DB Pin
G. White1-Oct-02 5:16
G. White1-Oct-02 5:16 
GeneralListview header column question Pin
alex.barylski30-Sep-02 13:45
alex.barylski30-Sep-02 13:45 
GeneralRe: Listview header column question Pin
Shog930-Sep-02 14:31
sitebuilderShog930-Sep-02 14:31 
GeneralRe: Listview header column question Pin
alex.barylski30-Sep-02 15:58
alex.barylski30-Sep-02 15:58 
Generalsaving data Pin
xai30-Sep-02 13:44
xai30-Sep-02 13:44 
GeneralRe: saving data Pin
valikac30-Sep-02 15:26
valikac30-Sep-02 15:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.