[MFC] imprimer un dialogue au format DIB
Malheureusement pour moi le code fourni dans la FAQ ne fonctionne pas, je doit mal effectuer une tache de plus personne ne semble comprendre d'ou viens mon erreur.
Je me suis donc tourné vers le site codeProject et j'ai donc trouvé le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
void PrintBitmap(LPCTSTR filename) {
CPrintDialog printDlg(FALSE);
printDlg.GetDefaults();
// Or get from user:
// if (printDlg.DoModal() == IDCANCEL)
// return;
CDC dc;
if (!dc.Attach(printDlg.GetPrinterDC())) {
AfxMessageBox(_T("No printer found!")); return;
}
dc.m_bPrinting = TRUE;
DOCINFO di;
// Initialise print document details
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = filename;
BOOL bPrintingOK = dc.StartDoc(&di); // Begin a new print job
// Get the printing extents
// and store in the m_rectDraw field of a
// CPrintInfo object
CPrintInfo Info;
Info.SetMaxPage(1); // just one page
int maxw = dc.GetDeviceCaps(HORZRES);
int maxh = dc.GetDeviceCaps(VERTRES);
Info.m_rectDraw.SetRect(0, 0, maxw, maxh);
for (UINT page = Info.GetMinPage(); page <=
Info.GetMaxPage() && bPrintingOK; page++) {
dc.StartPage(); // begin new page
Info.m_nCurPage = page;
CBitmap bitmap;
// LoadImage does the trick here, it creates a DIB section
// You can also use a resource here
// by using MAKEINTRESOURCE() ... etc.
if(!bitmap.Attach(::LoadImage(
::GetModuleHandle(NULL), filename, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE))) {
AfxMessageBox(_T("Error loading bitmap!")); return;
}
BITMAP bm;
bitmap.GetBitmap(&bm);
int w = bm.bmWidth;
int h = bm.bmHeight;
// create memory device context
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap *pBmp = memDC.SelectObject(&bitmap);
memDC.SetMapMode(dc.GetMapMode());
dc.SetStretchBltMode(HALFTONE);
// now stretchblt to maximum width on page
dc.StretchBlt(0, 0, maxw, maxh, &memDC, 0, 0, w, h, SRCCOPY);
// clean up
memDC.SelectObject(pBmp);
bPrintingOK = (dc.EndPage() > 0); // end page
}
if (bPrintingOK)
dc.EndDoc(); // end a print job
else dc.AbortDoc(); // abort job.
} |
Cette fonction me permet d'imprimer un bitmap à partir d'un chemin je suppose "LPCTSTR filename" alors en faisant fonctionner ma cervelle
j'ai pensé à combiner le code de FARSCAPE et celui-ci afin de pouvoir reussir mon impression.
le code de la FAQ s'effectue directement à partir du dialogue courant.
il se compose des fonctions suivantes.
Code:
1 2 3 4 5
|
CBitmap *pBmp=CopyWindowToBitmap(this,true);
PrintBmp(pBmp);
pBmp->DeleteObject();
delete pBmp; |
or chez moi c'est la fonction PrintBmp(pBmp) qui plante donc à partir de mon dialogue je voudrais savoir si il etait possible de récuperer le chemin de mon dialogue courant et qu'il soit du type LPCTSTR
voila j'espere avoir été assez explicite et je vous remercie d'avance pour votre aides :P