|
Dieter,
Interesting idea. I´m heavily occupied with a project atm, but will look into this as soon as possible. Maybe this can resolve the problem, some of the people are getting with the class.
Thanks
Albert
|
|
|
|
|
Yeah, now it works. No more blank sheets!!!!!!!!
|
|
|
|
|
Thanks for the input.
I had exactly the problem you described. I could print on a couple of local printers, but not on the network printers. After implementing your change everything works as described. I can even print on a large plotter.
Thanks again.
|
|
|
|
|
Hello,
I am sorry that it took so long to react. I have checked and tested Dieter Hammer's code now and it works perfectly on all my available printers. So i am preparing a new, updated version and i will upload it as soon as possible. Huge thanks to Dieter!!!!
This new version will include:
- the code suggested by Dieter Hammer, which should eliminate
that nasty blank page problem
- correct printing dialogs, which were partially pushed out of desktop area
- proportional correct printout, independent of paper orientation
- checking, if printer is actually capable for printing image
Albert
|
|
|
|
|
Hello Albert!
I need realy your help! Send me please (if it is possible) a demo project.
mailto: kaiser@nm.ru
|
|
|
|
|
Demo is on the way, check your mail
Albert
|
|
|
|
|
Just returned on Sunday from my vacancy from Europe and just now (was away
for 6 weeks) i had a chance to see the mess i've created with my last
version. I had uploaded an update/bugfix before i started my trip, but
for some reason, Codeproject doesn´t seem to have received it (maybe mail
probs, who knows). Just sent it yesterday again.
The main problem at the last version was, that the memdc doesn´t
combine with the stretch coordinates. This works on some printers, but not
on all. In the new version (uploaded) i calculate the stretching relation at the printer cap side. That version worked on all printers i had access
(laser and deskjets).
If htere is still a problem i will look into Noels suggestion.
Again, big sorry, hope it works now.
|
|
|
|
|
Maybe the printer isn't capable of performing a StretchBlt(...)
Just test this with:
<code>int iRasterCaps=GetDeviceCaps(pDC,RASTERCAPS)
</code>
|
|
|
|
|
Hi everybody !
I implemented your code to make a hardcopy and it worked - for a moment. At homeOffice (HP Deskjet 930C) it worked 10 time very good.
Now beeing in the Office (HP LaserJet 1200) it works only rarely. Most attemps ends with a blank page.
Is there any Problem with device-depindig bmps ? I would like to print an existing memDC (Mirror-Image to make all drawings, when all is finished it will be displayed to the screen to prevent flickering).
But using this DC and calculationg the size etc. causes a blank sheet too. Are there Problems with sizes etc ? It drives me crazy - I have no idea what to do now
Any help ?
Thanks
Martin L
|
|
|
|
|
I have a Lexmark Optra S 1650, plus a couple of other Lexmark printers I've tried printing on, all I can get so far is just the printers to wind up but I don't even get a blank page, I've also tried every possible print option combination. Any ideas?
I have added the changes you mentioned 2 sizeprn lines and changed the stretchBlt line.
Thanks,
Oscar
|
|
|
|
|
Hi, I'm still a beginner in MFC. I was wandering, where to put the command? Do I have to make another button specially for printing or I can use the default?
I'm trying to understand how to print using MFC.
Thx
|
|
|
|
|
Hi there,
I think it's easy. Below you find that part of my source, that will do what you need.
void OPP::OnRButtonDblClk(UINT nFlags, CPoint point)
{
CPrntScreen * ScrCap;
ScrCap = new CPrntScreen();
ScrCap->DoPrntScreen(2,2,FALSE);
delete ScrCap;
ScrCap = NULL;
COlePropertyPage::OnRButtonDblClk(nFlags, point);
}
As you can see, at my programm I i added an Window-Message for
WM_RBUTTONDBLCK which will call the function above.
Hope that helps,
regrads, Rudolf
|
|
|
|
|
First, I like the simplicity of this. Very good.
I created an MFC Dialog application with a command button to execute the print screen. I used the example code given. Actually I tried both. Everything seems to work, but the page printed is blank. Got any ideas what I am doing wrong?
Jeff Brady
CTO Visual Systems, Inc.
|
|
|
|
|
Sorry, my mail doesn´t work atm, so didn´t see this. No, atm i don´t have an idea, will cross check this tomorrow with the src code from the page, just to be sure. I use this code in two commercial projects without prob, but will see.
til later,
Albert
|
|
|
|
|
Jeff,
you are right, there is a bug in the stretching routine
I didn´t see it, because it does not happen on all printers. I had to go through 7 printers for finding 2 which show the same problem you described.
And it only happens, if dialogs are captured, full screen capture (type 0" work perfectly.
Thanks god, that my application are still in developement and the client didn´t see it either
I think, i found the solution and will upload a revised version.
If you need a quickfix, here is how to:
In the printing section, you will find the following 2 lines:
sizePrn.cx = pDC->GetDeviceCaps(HORZRES);
sizePrn.cy = pDC->GetDeviceCaps(VERTRES);
add there, just before the
pDC->LPtoDP(&sizePrn);
this two lines:
sizePrn.cx = (sizePrn.cx*sizeClient.cx)/sizeScreen.cx;
sizePrn.cy = (sizePrn.cy*sizeClient.cy)/sizeScreen.cy;
so that you get a:
sizePrn.cx = pDC->GetDeviceCaps(HORZRES);
sizePrn.cy = pDC->GetDeviceCaps(VERTRES);
sizePrn.cx = (sizePrn.cx*sizeClient.cx)/sizeScreen.cx;
sizePrn.cy = (sizePrn.cy*sizeClient.cy)/sizeScreen.cy;
pDC->LPtoDP(&sizePrn);
Change the line:
pDC->StretchBlt(0,0,sizePrn.cx,sizePrn.cy,&memDC,0,0,sizeScreen.cx,sizeScreen.cy,SRCCOPY);
to:
pDC->StretchBlt(0,0,sizePrn.cx,sizePrn.cy,&memDC,0,0,sizeClient.cx,sizeClient.cy,SRCCOPY);
That should do it!
|
|
|
|
|
Thanks so much!!!
I will test it out later today.
This is my first experience with anyone at CodeProject -- what a breath of fresh air
Jeff
|
|
|
|
|
Albert,
Well I tried the quickfix. Same results.
Old Code:
sizePrn.cx = pDC->GetDeviceCaps(HORZRES);
sizePrn.cy = pDC->GetDeviceCaps(VERTRES);
pDC->LPtoDP(&sizePrn);
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "CapScreen Printer...";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
New Code:
sizePrn.cx = pDC->GetDeviceCaps(HORZRES);
sizePrn.cy = pDC->GetDeviceCaps(VERTRES);
sizePrn.cx = (sizePrn.cx*sizeClient.cx)/sizeScreen.cx;
sizePrn.cy = (sizePrn.cy*sizeClient.cy)/sizeScreen.cy;
pDC->LPtoDP(&sizePrn);
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "CapScreen Printer...";
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = (LPTSTR) NULL;
di.fwType = 0;
My printer is an HP LaserJet 2100 Series PCL6.
Jeff
|
|
|
|
|
Jeff,
if you read the section with the quickfix again, you will see, that there is one more change to make. Maybe you didn´t see it, so here once more:
Change the line:
pDC->StretchBlt(0,0,sizePrn.cx,sizePrn.cy,&memDC,0,0,sizeScreen.cx,sizeScreen.cy,SRCCOPY);
to:
pDC->StretchBlt(0,0,sizePrn.cx,sizePrn.cy,&memDC,0,0,sizeClient.cx,sizeClient.cy,SRCCOPY);
This change is actually the most important one, because this line caused the problem. Explanation:
sizeScreen holds the screen resulution (full screen)
sizeClient holds the coordinates of the captured area.
I thought, that i can adjust the stretching relation simply there in the StretchBlt function, passing the full screen coordinates as source coordinates. Wrong! This works strangly on some printers, but not on all.
The fix is to adjust the magnification at the destination coordinates (the 2 lines you included) and to use the correct source coordinates (the second change, listed above).
I´ve already uploaded the new code, should be there in a few days.
Sorry again for this inconvenience,
Albert
|
|
|
|
|
Albert,
Tried your code & it works great.
Noticed the emails re: blank pages. I had the same problem until I noticed that my PCL printer (same type as Jeffs) was set to Vector mode instead of Raster mode. After changing to Raster - everything worked fine.
David.
|
|
|
|
|
Albert,
Well I finally got to try the latest code. But.... it still does blank pages.
It is a simple MFC application running under Win2K. The printer is an HP LasetJet 2100 Series PCL 6. The only code I have added is the following triggered by a command button:
void CScreenPrintTestDlg::OnPrintWindow()
{
CPrntScreen * ScrCap;
ScrCap = new CPrntScreen("Impossible to print!","Error!");
ScrCap->DoPrntScreen(1,1,false);
delete ScrCap;
ScrCap = NULL;
}
I am solving my problem with a different solution, but I thought you might want to look at this.
Thanks for your efforts,
Jeff
|
|
|
|
|
Am I missing something. I copied your function into my program as stated. But I get a lot of error about functions taking only one parameter not 2.
Is there a header file I need, the only extra one is "stdafx.h" ?
|
|
|
|
|
If you use the function version (copied/pasted from the file "PrintScreen_as_function.cpp"), then you will need to add a function prototype for this function to the header file of your class (the class, where you added the function). The prototype should look like this:
void DoPrntScreen(int fArea, int fOrientation);
Do NOT use the included header file for this version!!!!
Don´t forget to fix the class name of the copied function (which is "MyClass") according to name of YOUR class!
And most important, the usage is diferent! To use this version, just call the function like:
DoPrntScreen(1, 2);
nothing else to be done (as you don't have to create an object)! If you want to modify the Error text, just do it in the source code, see the definition of "sErrortext" and "sMsgCaption" in the code of this version.
If you use the class version ("PrntScreen.cpp" and "PrntScreen.h"), then you have to:
- copy the two files to your project's source folder
- add the two files to your project:
(solution explorer->add existing->[PrntScreen.cpp] to [SOURCE FILES]
(solution explorer->add existing->[PrntScreen.h] to [HEADER FILES]
- In the class/source (.CPP), where you pretend to use the PrintScreen function, add at the top, just AFTER the other includes (like "stdafx.h"), the line:
#include "PrntScreen.h"
- add the code (like posted above) for capturing/printing to the event handler, which you have foreseen (button etc).
It should compile without error, just checked that. No other header file is needed. Check, if the header file is included AFTER "stdafx.h".
Albert
|
|
|
|
|
is it Posible to Print richtext with in a given rectangle area
don't worry with the size of file..
is a simple thing i expliend in lot..
Trying: Edit,RichEdit control printing,
with in a rectangle as per they are drawn
in scroll view..
----
//****************************************************************************
// I want to draw the RichTextControl content in a specified rectangle on my printing page
// (as i done with editbox control) using FormatRange function with the different
// Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this function ?..
//***********************************************************************
//RTCtrlPrint1View.h
public:
CRTCtrlPrint1Doc* GetDocument();
//My*************************************
void RTCtrlCreate();
void DrawRichText(CDC *pDC);
void DrawEditText(CDC *pDC);
CRichEditCtrl m_redit;
CRect m_redRect;
CEdit m_edit;
CRect m_edRect;
UINT r;
CFont font;
//***************************************
//RTCtrlPrint1View.cpp
//=======================
void CRTCtrlPrint1View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
//edith box displaytext font
font.CreateFont(14,0,0,0,FW_NORMAL,FALSE,FALSE,
0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH|FF_MODERN,"Arial");
r=14;
m_edRect = CRect(50*r,-100*r,240*r,-700*r);
m_redRect = CRect(250*r,-100*r,750*r,-700*r);
CSize sizeTotal;
sizeTotal.cx = 850*r;
sizeTotal.cy = 1100*r;
SetScrollSizes(MM_TWIPS, sizeTotal); //MM_TWIPS
RTCtrlCreate();
}
void CRTCtrlPrint1View::OnDraw(CDC* pDC)
{
CRTCtrlPrint1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->Rectangle(1*r,1*r,800*r,-1100*r);//Print Area Rect
if(pDC->IsPrinting())
{
DrawEditText(pDC);//Simple Edit box text
DrawRichText(pDC);//My RichEdit box text
}
}
#define IDC_REDIT 4001 //defining a resource ID
#define IDC_EDIT 4002 //defining a resource ID
void CRTCtrlPrint1View::RTCtrlCreate() //creates both Rich edit & Edit Controls
{
CRect m_temp;
CClientDC dc(this);
OnPrepareDC(&dc);
//creating edit box in scroll view
m_temp = m_edRect;
dc.LPtoDP(m_temp);
m_edit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_EDIT);
m_edit.SetFont(&font,FALSE);
m_edit.SetWindowText("Help Me! Thank u");
//creating rich edit box in scroll view
m_temp = m_redRect;
dc.LPtoDP(m_temp);
m_redit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,m_temp,this,IDC_REDIT);
//writing some text in richtext control
CString str;
str="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\froman\\fprq2\\fcharset0 Times New Roman;}{\\f1\\fswiss\\fprq2\\fcharset0 System;}}{\\colortbl ;\\red255\\green0\\blue0;\\red51\\green153\\blue102;\\red0\\green0\\blue255;}\\viewkind4\\uc1\\pard\\cf1\\i\\f0\\fs24 ThankYou\
\\cf0\\i0 \\cf2\\b for\
\\cf0\\b0 \\cf3 Trying\
\\cf0 !\\b\\f1\\fs20 \\par }";
EDITSTREAM es;
es.dwCookie = (DWORD)&str;
es.pfnCallback = RichEditStreamInCallback;
m_redit.StreamIn(SF_RTF,es);
}
void CRTCtrlPrint1View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
// pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetMapMode(MM_TWIPS);
}
void CRTCtrlPrint1View::DrawEditText(CDC *pDC)
{
CRect m_temp;
m_temp = m_edRect;
CString str;
m_edit.GetWindowText(str);
pDC->SetBkMode(TRANSPARENT);
pDC->Rectangle(m_temp);
//Draws with Fonts as we wish
pDC->DrawText(str,m_temp,DT_WORDBREAK|DT_EXPANDTABS|DT_NOPREFIX);
}
//****************************************************************************// I want to draw the RichTextControl content in a specified rectangle on my
// printing page (as i done with editbox control) using FormatRange function
// with the different Font styles as in RichEditControl - HelpMe please!.
// DrawRichText(CDC *pDC) -> could u solve the problem that i have in this
// function ?..
//****************************************************************************void CRTCtrlPrint1View::DrawRichText(CDC *pDC)
{
CRect m_temp;
FORMATRANGE fmtRange;
long lLineWidth;
m_temp = m_redRect;
// pDC->LPtoDP(m_temp);
pDC->Rectangle(m_temp);
lLineWidth = ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH), 1440,
pDC->GetDeviceCaps(LOGPIXELSX));
fmtRange.hdc = pDC->m_hDC;
fmtRange.hdcTarget = pDC->m_hDC;
fmtRange.rc = m_temp;
fmtRange.rcPage = m_temp;
fmtRange.chrg.cpMin = 0;
fmtRange.chrg.cpMax = -1;
m_redit.SetTargetDevice(pDC->m_hDC, lLineWidth);
m_redit.FormatRange(&fmtRange, TRUE);
}
my Mail: cpbalaji2000@yahoo.com
Balaji
|
|
|
|
|