 |
|
|
 |
|
 |
Hi,
Iam developing an application/service for printers.The scenario is as follows
1. When a user selects a document and then he says the print command(no through my application...he selects normal print in file menu)then i have to catch some details like printername,no.of pages,document name..and so on...This action should be done before it get out from spooler.
2. As all of you that after printing data from spooler will be deleted..but in general for example for HP printer 3 files like lpr1234.tmp,shockwaveobject file ,.shd are generated. In this I have take take required files and keep them in my own spooler.
On my extensive search I came to know that by using WMI and WindowsAPI functions I can get to this goal...
But Iam unable to get into the right way....
If I have to use APIs then kindly tell what are the method I have to implement(if possible give me documentation link)
If through WMI....kindly guide me for the same
ALL these should be act as a service.....
thanks in Advance
|
|
|
|
 |
|
 |
I use this code in X64 OS.In debug mode printing is fine.
But In Release mode Startpage return -ve value. plz help me
|
|
|
|
 |
|
 |
Hi,
We are going to create a dialog based application. We want to print something from dialog. Can MFC standard print ability to support this printing? Anyone can help me for that?
Thanks,
Susan
|
|
|
|
 |
|
 |
please send your source project to me .^_^
Thank you !
Seu_why
|
|
|
|
 |
|
 |
I am drawing some lines while printing using page size A4.if I change the page size at runtime the lines are not printed correctly. how can I reflect the change of pagesize to print correctly.
gdfgdf
|
|
|
|
 |
|
 |
Hi , Thanks all.
I have developed an application in visual basic which prints on pre defined papers. My problem is when i print the content on EPSON InkJet/DeskJet its printing fine. But when i use another printer like HP Laser Printer its not printing on the paper( printing outside). My paper is very small (18cms x 10cms). In laser printer, when i keep the paper and move the lever to make paper not to move, its coming to the center of the tray. And when i print its printing in the left margin or right margin, where there is no paper and my paper in center! Could any one plz help me how to make it print in the center?
I have seen the code here By M.A Barnhart, but i couldnot understand the code except the GETDEVICECAPS. Could anyone plz help me doing the same in visual basic, if its the solution i am looking for.
Thanks in advance
Thanks in advance
Electronic Screw
|
|
|
|
 |
|
 |
Hi!
This code looks really great and might just be what I'm looking for. But I have a little problem.
When my function exits the program crashes, and i can't exactly understand why. It hink it crashes becuase when it destructs the CPrintInfo object, the destructor tries to delete CPrintInfo.m_pPD and this pointer is not valid.
I don't know if this problem is because of me, but I have copied your code right off so it should work shouldn't it.
Do you think you could help me, please?
Regards
Markus
|
|
|
|
 |
|
 |
The code as shonw was for 98 and NT4. What enviroment do you have?
For W2K conflicts did occur. It has been too long and I do not remember any details.
If it helps here is a newer example (but I have not run this in a few years either.)
void CChildView::PrintSetup(int item)
{
CDC dc;
CPrintDialog printDlg(FALSE);
if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user
return;
dc.Attach(printDlg.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;
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.m_rectDraw.SetRect(0,0,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
CRect MyArea;
MyArea = UserPage(&dc, 0.9f); // fixed margin in inches (you can change this)
dc.StartPage(); // begin new page
switch(item)
{
case(1):
PrintLoose(&dc,MyArea);
break;
case(2):
PrintRecord(&dc,MyArea);
break;
}
if (bPrintingOK)
{
dc.EndPage();
dc.EndDoc(); // end a print job
}
else
{
dc.AbortDoc(); // abort job.
}
dc.Detach(); // detach the printer DC
return;
}
I do not mind getting old. It beats all the other options that I can think of.
|
|
|
|
 |
|
 |
Ok, I'm coding for 2000/XP.
It appears that if I don't use the CPrintInfo pointer it works just fine.
I can't really see where you use that variable, what is it good for? Because I've never used that one when I do printing code.
|
|
|
|
 |
|
 |
Hello all
Say I have a program - for which I have no source code, and it prints a "report" in this case it is actually a Point-Of-Sale RECEIPT going to either a SERIAL or PARALLEL printer port
I want tyo TRAP, the print Job, before it gets to the port, re-package it (add some Logo, and header / footer lines) and then let go of it to the intended printer..
Can this be done? Any suggestions please (using MFC / C++)
Thanks
Alex
|
|
|
|
 |
|
 |
AlexEvans wrote:
Can this be done?
Yes it can. I have no background in intercepting serial connections. Have you posted this question in the C++ forum?
I do not mind getting old. It beats all the other options that I can think of.
|
|
|
|
 |
|
 |
In the UserPage function the line:
int OriginalMapMode = pDC->SetMapMode(MM_TWIPS);
was good to save the original, but you forgot to restore it.
You should do this at the end of UserPage also.
pDC->SetMapMode(OriginalMapMode);
Thanks for the good work!
David Leikis
|
|
|
|
 |
|
 |
David_Leikis wrote:
but you forgot to restore it.
YEP , Thanks for the note.
I do not mind getting old. It beats all the other options that can think of.
|
|
|
|
 |
|
 |
I used the codes below to change a print page size, but it can only be used succeed in Win98, cannot in WinXP. Can you help me to fix it? Thank you.
CView::OnPreparePrinting(CPrintInfo* pInfo)
{
CPrintDialog dlgPrint(FALSE);
if( !dlgPrint.GetDefaults() )return FALSE;
LPDEVMODE pDM=dlgPrint.GetDevMode();
if (pDM==NULL)return FALSE;
pDM->dmPaperSize = DMPAPER_USER;
pDM->dmFields |= DM_PAPERSIZE;
pDM->dmPaperLength = 920;
pDM->dmPaperWidth = 2410;
::GlobalUnlock(pDM);
pInfo->m_pPD->m_pd.hDC = dlgPrint.CreatePrinterDC();
pInfo->SetMaxPage( 1 );
return DoPreparePrinting(pInfo);
}
|
|
|
|
 |
|
 |
I have not had very much interaction with WinXP. From a few minutes review, I do not see anything out of place with your code. Question though. Is this with the same printer on each system?
I do not mind getting old. It beats all the other options that can think of.
|
|
|
|
 |
|
 |
I want to print the image keeping it's original size without considering the size of page,how can i do?
|
|
|
|
 |
|
 |
hi,
how about adding a function for line thickness. if you draw a line with thickness 1 on a DMP it is a lot thicker that the line with the same width drawn on laser (or any hi-res) printer.
milind
|
|
|
|
 |
|
 |
In MSDN, it says that you can retrieve a color attribute of a printer job by deviceMode->dmColor,
But I found that it doesn't work fine on all printer driver, could some body help me how to get
a printer job is colot or not, exactly?
|
|
|
|
 |
|
 |
Hi,
First of all great piece of code that's really helping me sort a particular project, thanks!
My problem/query is that I get inconsistent paper area results depending on which printer I select (which seems to be a theme looking at the other threads but I can't seem to get myself pointed in the right direction to solve the issue satisfactorily). Like the others it seems to be Inkjets which are the problem?
Firstly, If I set the margins too low on certain printers the top/left print areas come back as -ve figures which I assume should be simply set to zero?
Secondly, amongst other things, I'm trying to get some text wedged in the very bottom right hand of the page - with the non-inkjet printers this comes out just fine but with inkjets(and with the margins >=0) the bottom is far too great a figure?
Whilst I'm not a newbie, I wouldn't say I'm an expert so perhaps I'm missing something quite simple?
I'm using NT4/MSVC++ 6.0,
Printers OK, HP Laserjet, WinFax
Printers NOK, Canon BJC 4000, HP Deskjet
Thanks Very Much
ASH
|
|
|
|
 |
|
 |
First a suggestion.
Start with a simple problem and make it work first.
Say a 2 inch margin (or what ever scale you wish) that is well inside all printable bounds of the printers you need to deal with. Draw a box around this area and some text in the middle. Is that consistent?
Next work this same problem out to the edges of the sheet to be printed. Where do failures begin?
On the I have dealt with HP 500,550, 660 and some wide carriage with out problems, other than yes the lower printable area is not accessable. Same with a Canon 2000. If that is the problem there is not to much you can do. It is out of the boundary the printer supports. But you should be able to prove that is the case with the trial above.
"I will find a new sig someday."
|
|
|
|
 |
|
 |
First off I want to thank you Michael for your excellent and highly useful source!
I have implemented this code and it workes perfectly. At least when the active
configuration is Debug. I made no other changes than setting it to Release and
then StartDoc() began returning -1. Why is that?! I changed it back to Debug
and it worked fine once again.
I don't imagine that StartDoc() only works for Debug builds. Do you have any idea
as to why this is happening to me?
Please help. I appreciate your assistance.
Thanks.
|
|
|
|
 |
|
 |
There should not be any issue with debug vs release. One issue could be is everything being initialized. You could do a quick test by printing out the prameters (say a message box) and verifying all the data exists.
What printer and os are you trying to use? Some differences do exist depending on how you are trying to initialize the printer, but that should not be in the start doc but in the scaling calculations.
"I will find a new sig someday."
|
|
|
|
 |
|
 |
I would like to retrieve the height and the width of the paper selected in
the CPrintDialog by the user.
When I display the CPrintDialog then if the user change the paper,
dmPaperLength and dmPaperWidth are not updated but dmFormName is updated.
dmPaperLength and dmPaperWidth are updated only if I reload the CPrintDialog and
press ok button again.
I remarq that dmpapersize is updated but how can I retrieve the height and the width
from dmpapersize??
Thank you,
Christophe from Belgium
This is my code :
//-------------------------------------------
int ret;
PRINTDLG PRT_DLG;
LPDEVMODE lpDevMode;
CPrintDialog pd( true,PD_ALLPAGES|PD_RETURNDC|PD_HIDEPRINTTOFILE,NULL);
ret = AfxGetApp()->DoPrintDialog(&pd);
if(ret == IDOK)
{
AfxGetApp()->GetPrinterDeviceDefaults(&PRT_DLG);
lpDevMode = (LPDEVMODE)::GlobalLock(PRT_DLG.hDevMode);
if(lpDevMode != NULL)
{
CString str2;
m_paperHeight.cm = (float)(lpDevMode->dmPaperLength/100) ;
m_paperHeight.inches = (lpDevMode->dmPaperLength/100) * (float)0.39;
m_paperWidth.cm =(float) (lpDevMode->dmPaperWidth/100) ;
m_paperWidth.inches = (lpDevMode->dmPaperWidth/100) * (float)0.39;
CEdit * ptre=(CEdit *) GetDlgItem(IDC_EDIT14);
ptre->SetWindowText(( char*) lpDevMode->dmFormName);
initWidthHeightofPaper();
::GlobalUnlock(PRT_DLG.hDevMode);
}
}
//--------------------------------------------
|
|
|
|
 |
|
 |
lavocat wrote:
AfxGetApp()->GetPrinterDeviceDefaults(&PRT_DLG);
This line gets the defaults for the printer not what you have selected.
To get the current selection try something like:
int ret;
CPrintDialog pd( true,PD_ALLPAGES|PD_RETURNDC|PD_HIDEPRINTTOFILE,NULL);
ret = AfxGetApp()->DoPrintDialog(&pd);
if(ret == IDOK)
{
CDC dc;
dc.Attach(pd.GetPrinterDC()); // attach a printer DC
// Set Map Mode
int OriginalMapMode = dc.SetMapMode(MM_LOMETRIC);
CSize Physical;
// This gets the Physical size of the page in Device Units
Physical.cx = dc.GetDeviceCaps(PHYSICALWIDTH);
Physical.cy = dc.GetDeviceCaps(PHYSICALHEIGHT);
dc.DPtoLP(&Physical);
double m_paperHeight_cm = ((double)Physical.cy/100.) ;
double m_paperHeight_inches = ((double)Physical.cy/254.);
double m_paperWidth_cm = ((double)Physical.cx/100.) ;
double m_paperWidth_inches = ((double)Physical.cx/254.);
}
"I will find a new sig someday."
|
|
|
|
 |