|
Hello every one :
How can I dealing the date in Hijjry ?
thank you for your effort
Omar Halabiah
|
|
|
|
|
hi,
the tute was real cool,
thanks mate,
kreep.
|
|
|
|
|
I need help!!
I use the method, dc.StartDoc, dc.StartPage, dc.TextOut, dc.EndPage and dc.EndDoc for printing documents, but I need to print in a different page size (equivalent to third part of a letter page).
So, how can I do for changing the page size in customing way and printer print in that page size and not advance form-feed like a letter page?
thanks
|
|
|
|
|
I'm not sure what you are asking, but whenever printing I always start by getting the printer's page size. I use the method below to get the information. This will get the page size of the CDC passed as parameter one:
#define PRINTER_PAGE_HIMETRIC 1
#define PRINTER_PAGE_DEVICE_UINTS 2
void GetPrinterPageSizeByCDC(CDC &dc, int nUnits,
CSize &sizePage, CSize &sizePrintArea, CSize &sizePhysicalOffset,
int &nLogPixelsX, int &nLogPixelsY)
{
nLogPixelsX = dc.GetDeviceCaps(LOGPIXELSX);
nLogPixelsY = dc.GetDeviceCaps(LOGPIXELSY);
if(nUnits == PRINTER_PAGE_HIMETRIC)
{
double x_HIMETRICperDU = 25.4 * 100.0 / double(nLogPixelsX);
double y_HIMETRICperDU = 25.4 * 100.0 / double(nLogPixelsY);
sizePage.cx = int(double(dc.GetDeviceCaps(PHYSICALWIDTH)) * x_HIMETRICperDU);
sizePage.cy = int(double(dc.GetDeviceCaps(PHYSICALHEIGHT)) * y_HIMETRICperDU);
sizePhysicalOffset.cx = int(double(dc.GetDeviceCaps(PHYSICALOFFSETX)) * x_HIMETRICperDU);
sizePhysicalOffset.cy = int(double(dc.GetDeviceCaps(PHYSICALOFFSETY)) * y_HIMETRICperDU);
sizePrintArea.cx = int(double(dc.GetDeviceCaps(HORZRES)) * x_HIMETRICperDU);
sizePrintArea.cy = int(double(dc.GetDeviceCaps(VERTRES)) * y_HIMETRICperDU);
}
else
{
sizePage.cx = dc.GetDeviceCaps(PHYSICALWIDTH);
sizePage.cy = dc.GetDeviceCaps(PHYSICALHEIGHT);
sizePhysicalOffset.cx = dc.GetDeviceCaps(PHYSICALOFFSETX);
sizePhysicalOffset.cy = dc.GetDeviceCaps(PHYSICALOFFSETY);
sizePrintArea.cx = dc.GetDeviceCaps(HORZRES);
sizePrintArea.cy = dc.GetDeviceCaps(VERTRES);
}
} You can modify this function as needed. I have it setup to return the page size as either PRINTER_PAGE_HIMETRIC or PRINTER_PAGE_DEVICE_UINTS. Just set parameter 2 to one of the defines. It will return to you the following:
CSize sizePage - The size of the physical page.
CSize sizePrintArea - The size of the actual printable area.
CSize sizePhysicalOffset - The offset from the upper left corner of the physical page to the upper left corner of the printable area.
int nLogPixelsX - Units per inch on the X axis.
int nLogPixelsY - Units per inch on the Y axis.
With this information you can easily calculate 1/3 of the page.
Hope this helps...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
In order to print a Mschart from a dialog, I wanted to use this way of printing. I finally succeed to make it work or almost work ...
In fact everything works well (it prints !) on my development PC (win2k, quite recent, with all visual studio stuff) but nothing is printed on another PC (win98, much older, and just with the 2 files -.ocx and .dll- added for MSchart). It's not the same printer too but the one connected to the old PC is an epson stylus 760 supposed to be able to perform the StretchBlt.
Here my code launched when the Print button is clicked :
void CGraphDlg::OnEssai()
{
CDC dc;
BOOL ok;
// order chart to copy itself onto clipboard
m_Chart.EditCopy();
CloseClipboard();
// make sure the item in clipboard is a bitmap
if(IsClipboardFormatAvailable(CF_BITMAP))
{
if(OpenClipboard())
{
m_hbitmap = (HBITMAP)::GetClipboardData(CF_BITMAP);
CloseClipboard();
}
}
// lance l'interface pour l'imprimante
CPrintDialog printDialog(false);
bool bShowPrintDialog = TRUE; //FALSE lance directement l'impression
if (bShowPrintDialog)
{
int r = printDialog.DoModal();
if (r == IDCANCEL) // Get printer settings from user
return;
}
else
{
printDialog.GetDefaults();
}
dc.Attach(printDialog.GetPrinterDC()); // Attach a printer DC
dc.m_bPrinting = TRUE;
CString strTitle; // Get the application title
strTitle.LoadString(AFX_IDS_APP_TITLE);
DOCINFO di; // Initialise print document details
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;
int bPrintingOK = dc.StartDoc(&di); // Begin a new print job
// Get the printing extents and store in the m_rectDraw field of a
CPrintInfo Info;
CString toto;
Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES));
OnBeginPrinting(&dc, &Info); // empty funtion
dc.StartPage(); // begin new page
Info.m_nCurPage = 1;
OnPrint(&dc, &Info); // my "Print page" function
OnEndPrinting(&dc, &Info); // empty funtion
dc.EndPage(); // end new page
dc.EndDoc(); // end a print job
dc.Detach(); // detach the printer DC
}
and here in my OnPrint fctn (based on an example):
void CGraphDlg::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// Create a text for the title
CString sTitleHeader=_T("My First Chart");
CString toto;
// Get the page size and boundaries
CRect rectPage = pInfo->m_rectDraw;
TEXTMETRIC tm;
CFont font;
CSize textSize;
int cyChar;
// Create the font we will be using
font.CreatePointFont(240, "Arial", pDC);
CFont *pOldFont=pDC->SelectObject(&font);
//Set Margin
rectPage.top+=rectPage.bottom/48;
rectPage.bottom-=rectPage.bottom/48;
rectPage.left+=200;
rectPage.right-=200;
// Get Text size in order to center
pDC->GetTextMetrics(&tm);
textSize=pDC->GetTextExtent(sTitleHeader);
cyChar = tm.tmHeight;
// Draw Text (centered)
pDC->TextOut(((rectPage.right+rectPage.left)/2)-(textSize.cx/2), rectPage.top, sTitleHeader);
rectPage.top += cyChar + cyChar / 4;
// Draw header line divider
pDC->MoveTo(rectPage.left, rectPage.top);
pDC->LineTo(rectPage.right, rectPage.top);
// Go to next line
rectPage.top += cyChar / 4;
if(m_hbitmap)
{
BITMAP bm;
AfxMessageBox ("dans impression bitmap",MB_OK,MB_ICONSTOP);
::GetObject(m_hbitmap, sizeof(BITMAP), &bm);
CSize chartSize(bm.bmWidth, bm.bmHeight);
CDC dcMemory,dcScreen;
dcScreen.Attach(::GetDC(NULL));
// create "from" device context and select the loaded bitmap into it
dcMemory.CreateCompatibleDC(&dcScreen);
dcMemory.SelectObject(m_hbitmap);
// Print at 85% size within left/right margin
CSize printSize;
printSize.cx=(int)(rectPage.right*.85);
printSize.cy=printSize.cx/chartSize.cx*chartSize.cy;
toto.Format ( "cx = %d\ncy = %d\n",printSize.cx,printSize.cy);
AfxMessageBox (toto,MB_OK,MB_ICONSTOP);
// Print chart centered
pDC->StretchBlt( ((rectPage.right+rectPage.left)/2)-(printSize.cx/2),
rectPage.top, printSize.cx, printSize.cy, &dcMemory,
0, 0, chartSize.cx, chartSize.cy, SRCCOPY);
dcMemory.DeleteDC();
}
// Revert and Destroy
pDC->SelectObject(pOldFont);
font.DeleteObject();
}
Do you have an idea of what happens or how to progress in my investigations ?
Do you guess if problem comes from OnPrint routine itself or from the print without Doc/view framework ?
Note : I simplified my OnPrint routine to just print the title and drop the print of MsChart and get same problem, nothing is printed. At EndPage() call, I can see the printer spooler saying "print page 0 on 0 pages" that must not be a good sign ...
Thanks in advance for your help.
DD
|
|
|
|
|
hello chris,
I have a really Big problem.Iam using "HP LaserJet 2100" printer.
Iam attaching the sample code in this.PL help me by trying that code in your PC and get me a modified code which prints for landsacpe printing.The code is like this
This prints only potraiot...pl help me
/**********************************************************/
void CEditboxView::OnPrinting()
{
// TODO: Add your command handler code here
CString temp;
CPrintDialog dlg(FALSE);
if (IDOK == dlg.DoModal())
{
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
DWORD dwJob;
DWORD dwBytesWritten;
CString szPrinterName = dlg.GetDeviceName();
DEVMODE* devMode = dlg.GetDevMode();
PRINTER_DEFAULTS defaults;
defaults.pDatatype = NULL;
defaults.DesiredAccess = PRINTER_ACCESS_USE;
defaults.pDevMode =devMode;
// Need a handle to the printer.
BOOL bRtn = OpenPrinter( (char*)(const char *)szPrinterName, &hPrinter,&defaults );
if( bRtn == FALSE)
return ;
// Fill in the structure with info about this "document."
DocInfo.pDocName = "My Document";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";
// Inform the spooler the document is beginning.
if( (dwJob = StartDocPrinter( hPrinter, 1, (unsigned char *)&DocInfo )) == 0 )
{
ClosePrinter( hPrinter );
return ;
}
// Start a page.
if( ! StartPagePrinter( hPrinter ) )
{
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return ;
}
// Send the data to the printer.
if( !WritePrinter( hPrinter, "hello how are you", 20, &dwBytesWritten ) )
{
EndPagePrinter( hPrinter );
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return ;
}
// End the page.
if( ! EndPagePrinter( hPrinter ) )
{
EndDocPrinter( hPrinter );
ClosePrinter( hPrinter );
return ;
}
// Inform the spooler that the document is ending.
if( ! EndDocPrinter( hPrinter ) )
{
ClosePrinter( hPrinter );
return ;
}
// Tidy up the printer handle.
ClosePrinter( hPrinter );
}
}
/*********************************************************/
nbeed solution and advance thanx
|
|
|
|
|
I used that method for line-printing: OpenPrinter, StartDocPrinter, etc, but How can I do for change the font size and style?
|
|
|
|
|
set
defaults.pDevMode->dmFields = defaults.pDevMode->dmFields |DM_ORIENTATION;
defaults.pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
before opening printer
|
|
|
|
|
I have dialog and tree control in it. Now, i want to print only tree screen (not all dialog). How can i do it ? If somebody knows, help me, please
|
|
|
|
|
As told by Chris, derive ur dialog from public CDialog, TreeCtrlPrint. Add functions :
OnBeginPrinting
OnEndPrinting
For Printing, u have to refer to an article by Roger Allen
(search "print the content of a CTreeCtrl
")
U have to derive ur TreeCtrl from the tree control given by him which is printable.
When the event for printing is called, say on the Press of a button from the dialog, Prepare CDC and CPrintInfo and pass it to the Print() function in which u have to write the code as suggested by Roger. The tree control has APIs which will take care of the rest of the work.
Regards
Atul
|
|
|
|
|
print the content of screen as it is to the printer using MFC dialog based application
please give me full code
|
|
|
|
|
Please help me to print content of screen as it is to printer and also showing the print preview without doc/view for single frame window.
thanks
|
|
|
|
|
void CRamsDlg::OnPrint()
{
// TODO: Add your control notification handler code here
CPrintDialog cpd(FALSE);//,PD_ALLPAGES,this);
cpd.GetDefaults(); //Default printer
CDC printerDC;
printerDC.Attach(cpd.GetPrinterDC());
DOCINFO di;
di.cbSize=sizeof(DOCINFO);
di.lpszDocName="ACS Bill";
di.fwType=NULL;
di.lpszDatatype=NULL;
di.lpszOutput=NULL;
int PageWidth = 1500;
int PageLength =1500;
//Start new Document
printerDC.StartDoc(&di);
//Start new page
printerDC.StartPage();
printerDC.SetMapMode(MM_ANISOTROPIC); //MM_TEXT//1 to 1 pixel mapping
CDC *pDC=GetDC(); //DC of dialog
CRect cr;
GetClientRect(cr);
printerDC.BitBlt(0, 0, cr.Width()*3, cr.Height()*3, pDC, 0, 0, SRCCOPY);
printerDC.EndPage();
//Close printer document
printerDC.EndDoc();
//Finished
printerDC.DeleteDC();
ReleaseDC(pDC);
}
try this code .if there is any problem contact me
regards
meenachi
|
|
|
|
|
How can I make the image fill the whole page?
Thanks by the way.
|
|
|
|
|
CPrintDialog printDlg(FALSE);
printDlg.m_pd.nCopies = 1 ;
printDlg.m_pd.nMaxPage = m_CountPage ;
printDlg.m_pd.nMinPage = 1 ;
printDlg.m_pd.nFromPage = 1 ;
printDlg.m_pd.nToPage = m_CountPage ;
printDlg.m_pd.Flags =PD_ALLPAGES|PD_HIDEPRINTTOFILE|PD_PAGENUMS|PD_SELECTION|
PD_COLLATE|PD_RETURNDC|PD_ENABLEPRINTHOOK|PD_ENABLESETUPHOOK ;
printDlg.DoModal() ; // not show dialog
{CPrintDialog hWnd=0x00000000}
default printer Epson LQ-300 ESC/P 2 .
Thanks .
|
|
|
|
|
Start off by saying that the code works great in Release mode and is fine for what I'm trying to do.
However, when running the program in debug mode I get 1 assertation error, which is coming from a function: _free_dbg().
I have created a Print class, inserted the majority of your code into a function Print.PrintFile() but the debugger fails when I leave my OnPrint function in the dialog, e.g.
OnPrint()
{
set up DC and File Objects
Open File for reading
Call Print.PrintFile(File)
Close File
DeleteDC()
} <- DEBUGGER HAS PROBLEM WHEN GETTING HERE
However, in Debug mode the code still prints out the file before crashing.
Just wondering if anyone else had come across this problem, and/or is there a solution.
Cheers
Greg
|
|
|
|
|
Your best chance to get this problem sorted is to post all you code from your printing. It sounds like you have a dynamically allocated array which you are writing beyond the beginning/end off. So either post the whole OnPrint() procedure here, or mail it to me, and I will have a look.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
Roger,
Thanks for offer of help, but have now managed to solve the problem.
It was all my fault, unsuprisingly! I was making a call to the Printer Destructor in order to release a page if (for whatever reason) the print came into problems.
Have now changed it to just call EndPrinting()
Call me stupid
Greg
|
|
|
|
|
Chris,
I may be wrong but in the code you do a dc.Detach() right at the end of the procedure. Should this not be a dc.DeleteDC() as the docs say that the DC must be deleted. As it stands your not doing anything with it so it just leaks.....
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
At one point (ie 5 years ago) I could have sworn you didn't need to release a DC obtained via GetPrinterDC. Obviously I was totally wrong! Anyway, the article's been updated - thanks.
cheers,
Chris Maunder
|
|
|
|
|
Wow, that's what I call a prompt service. Less than 30 minutes between bug report and fixed version...
Regards
Thomas
Sonork id: 100.10453 Thömmi
Disclaimer: Because of heavy processing requirements, we are currently using some of your unused brain capacity for backup processing. Please ignore any hallucinations, voices or unusual dreams you may experience. Please avoid concentration-intensive tasks until further notice. Thank you.
|
|
|
|
|
Please....
provide me some hints on what code can i write in OnBeginPrinting() and OnEndPrinting().And I don't know how to use the CPrintInfo object...also
i understand it has to be used in OnBeginPrinting() function.I didn't use
your code since now, and my code works 50%...i mean i obtain the corect output
on the paper,but after the first page the printer "spits" back just an empty paper.I have to push the "Proceed" button of the printer's dialog in order to get the second page of my document(the third page in "history").The error that appears on the printer's dialog is "Size error"
|
|
|
|
|
And what the hell am I supposed to put into OnBeginPrint(), OnPrint(), and OnEndPrint()??????????
|
|
|
|
|
Hi, I too am wondering the same thing. Can you please help?
Thanks
VC++ Beginners
|
|
|
|
|
You guys need to dig through the MFC printing code and understand the mechanics. Chirs created code that looks like the MFC printing code but is not tied to a doc/view. The OnBeginPrint() and OnEndPrint() are for initializing and uninitializing stuff needed for printing. If you don't need them comment them out or just make empty functions for them. The OnPrint() is for drawing to the printer DC. The MFC version of OnPrint() calls OnDraw(). So, OnPrint() is where you draw to the printer.
This is nice code for printing stuff you are not drawing on the screen (reports, runtime stuff, etc.).
Good Luck...
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|