-
June 28th, 2013, 09:27 AM
#1
Printer left margin
I have code that prints.
PrintDlg.
StartDoc
StartPage
TextOut
EndPage
EndDoc
I am trying to calculate left margin from (inchis * 100) to pixels.
So the left input for TextOut will be correct.
How do I do this?
-
June 28th, 2013, 10:14 AM
#2
Re: Printer left margin
And how does your code look like?
Victor Nijegorodov
-
June 28th, 2013, 11:28 AM
#3
Re: Printer left margin
Does this help?
360,1020 is the bottom middle of the page in pixels.
850,-1100 from other peoples code.
Is what I think is the page size in inchis * 100?
PRINTDLG pdlg;
PRINTDLG* ppd = NULL;
DOCINFO di;
DOCINFO* pdi = NULL;
DWORD dw1 = 0;
DWORD dw2 = 0;
DWORD dwLines = 0;
DWORD dwTm = 0;
DWORD dw1 = 0;
DWORD dw2 = 0;
UINT uiTm = 0;
int xPPI = 0;
int yPPI = 0;
long xExt = 0;
long yExt = 0;
WORD wo1 = 0;
WORD wo2 = 0;
char* pch1 = NULL;
char* pch2 = NULL;
char chP[180];
ppd = (PRINTDLG*)&pdlg;
pdi = (DOCINFO*)&di;
pch1 = s_pchBuf1;
pch2 = (char*)&chP;
// hdp = HDC of printer
// s_hwEdi = HWND of Edit Control
// s_woMarL = Left Margin (inchis*100)
// s_woLPX = GetDeviceCaps(HDC of Edit Control,LOGPIXELSX);
// s_pchBuf1 = new char[97000]
// s_pchExeName = Path of this .exe file
uiTm = ::GetWindowTextA(s_hwEdit,s_pchBuf1,96968);
if ((uiTm == 0) || (*s_pchBuf1 == 0))
return 0;
dwLines = (DWORD)::SendMessageA(s_hwEdit,EM_GETLINECOUNT,0,0L);
dw2 = ((s_woMarL*s_woLPX)/100);
pdi->cbSize = 20;
pdi->lpszDocName = PathFindFileName(s_pchExeName);
pdi->fwType = 0;
pdi->lpszDatatype = NULL;
pdi->lpszOutput = NULL;
xPPI = GetDeviceCaps(hdP,LOGPIXELSX);
yPPI = GetDeviceCaps(hdP,LOGPIXELSY);
xExt = ((850*xPPI)/100);
yExt = ((1100*yPPI)/100);
xPPI = 0;
yPPI = 0;
yPPI = (ppd->nFromPage*51);
StartDoc(hdP,pdi);
for (xPPI = ppd->nFromPage; xPPI < ppd->nToPage; xPPI++)
{
SetMapMode(hdP,MM_ANISOTROPIC);
SetWindowExt(hdP,850,-1100,NULL);
SetViewportExt(hdP,xExt,-yExt,NULL);
StartPage(hdP);
for (wo2 = 0; wo2 < 51; wo2++)
{
if (dwLines < (DWORD)yPPI)
break;
dwTm = (DWORD)::SendMessageA(s_hwEdit,EM_LINEINDEX,yPPI,0L);
if (dwTm < uiTm)
{
*pch2 = (BYTE)180;
::SendMessageA(s_hwEdit,EM_GETLINE,yPPI,(LPARAM)pch2);
wo1 = (BYTE)*pch2;
if (wo1 == 180)
*pch2 = 0;
dw1 = lstrlenA(pch2);
TextOut(hdP,(dw2+4),(wo2*20),pch2,dw1);
}
yPPI++;
}
wsprintfA(pch2,TEXT("PAGE %u"),(xPPI+1);
dwTm = lstrlen(pch2);
TextOut(hdP,360,1020,pch2,dwTm);
EndPage(hdP);
}
EndDoc(hdP);
DeleteDC(hdP);
return 0;
Last edited by ROCKYCAT; June 29th, 2013 at 11:41 AM.
-
June 29th, 2013, 04:58 AM
#4
Re: Printer left margin
Originally Posted by ROCKYCAT
Code:
s_woLPX = GD_GetDeviceCaps(hdcedit,LOGPIXELSX);
HDC of EDIT CONTROL.
DWORD PrintJBTDoc()
{
HDC hdP = NULL;
PDA* ppd = NULL;
DOCINFOA diIn;
DOCINFOA* pdi = NULL;
HFONT hfOld = NULL;
DWORD dwLines = 0;
DWORD dwTm = 0;
DWORD dw1 = 0;
DWORD dw2 = 0;
UINT uiTm = 0;
int xPPI = 0;
int yPPI = 0;
long xExt = 0;
long yExt = 0;
WORD wo1 = 0;
WORD wo2 = 0;
char* pch1 = NULL;
char* pch2 = NULL;
pdi = (DOCINFO*)&diIn;
ClearMem4(s_pchBuf1,MEM_BUF1);
uiTm = ::GetWindowTextA(s_hwEdi,s_pchBuf1,(MEM_BUF1-32));
if ((uiTm == 0) || (*s_pchBuf1 == 0))
return 0;
pch1 = s_pchBuf1;
pch2 = s_pchBuf2;
dwLines = SND_NoPar(s_hwEdi,EM_GETLINECOUNT);
if (dwLines == 0)
return 307;
...
for (xPPI = ppd->nFromPage; xPPI < ppd->nToPage; xPPI++)
{
GD_SetMapMode(hdP,MM_ANISOTROPIC);
GD_SetWindowExt(hdP,850,-1100,NULL);
GD_SetViewportExt(hdP,xExt,-yExt,NULL);
GD_StartPage(hdP);
for (wo2 = 0; wo2 < 51; wo2++)
{
if (dwLines < (DWORD)yPPI)
break;
ClearMem4(pch2,MEM_BUF2);
dwTm = (DWORD)::SendMessageA(s_hwEdi,EM_LINEINDEX,yPPI,0L);
if (dwTm < uiTm)
{
*pch2 = (BYTE)180;
::SendMessageA(s_hwEdi,EM_GETLINE,yPPI,(LPARAM)pch2);
wo1 = (BYTE)*pch2;
if (wo1 == 180)
*pch2 = 0;
dw1 = lstrlenA(pch2);
xTextOut4(hdP,(dw2+4),(wo2*20),pch2,dw1);
}
yPPI++;
}
ClearMem4(pch2,MEM_BUF2);
NumToDecStr4(pch2,(xPPI+1),2);
xTextOut4(hdP,360,1020,IDS_PAGE,4);
xTextOut4(hdP,430,1020,pch2,2);
GD_EndPage(hdP);
}
GD_EndDoc(hdP);
GD_SelectObject(hdP,(HFONT)hfOld);
GD_DeleteDC(hdP);
return 0;
}
What are all these GD_...() functions?
What is ClearMem4()? Other ...4() functions?
What are these magic numbers: 360,1020, 850, ...?
Victor Nijegorodov
-
June 28th, 2013, 11:31 AM
#5
Re: Printer left margin
ohhh, please, edit your post adding Code tags around code snippet!
Otherwise it is verz hard to read/understand what you wrote...
Victor Nijegorodov
-
June 29th, 2013, 03:08 AM
#6
Re: Printer left margin
U can use BeginPrint and in that GetDeviceCaps .. U can set page layout in that
-
June 29th, 2013, 11:45 AM
#7
Re: Printer left margin
Does this help?
360,1020 is the bottom middle of the page in pixels.
850,-1100 from other peoples code.
Is what I think is the page size in inchis * 100?
PRINTDLG pdlg;
PRINTDLG* ppd = NULL;
DOCINFO di;
DOCINFO* pdi = NULL;
DWORD dw1 = 0;
DWORD dw2 = 0;
DWORD dwLines = 0;
DWORD dwTm = 0;
DWORD dw1 = 0;
DWORD dw2 = 0;
UINT uiTm = 0;
int xPPI = 0;
int yPPI = 0;
long xExt = 0;
long yExt = 0;
WORD wo1 = 0;
WORD wo2 = 0;
char* pch1 = NULL;
char* pch2 = NULL;
char chP[180];
ppd = (PRINTDLG*)&pdlg;
pdi = (DOCINFO*)&di;
pch1 = s_pchBuf1;
pch2 = (char*)&chP;
// hdp = HDC of printer
// s_hwEdi = HWND of Edit Control
// s_woMarL = Left Margin (inchis*100)
// s_woLPX = GetDeviceCaps(HDC of Edit Control,LOGPIXELSX);
// s_pchBuf1 = new char[97000]
// s_pchExeName = Path of this .exe file
uiTm = ::GetWindowTextA(s_hwEdit,s_pchBuf1,96968);
if ((uiTm == 0) || (*s_pchBuf1 == 0))
return 0;
dwLines = (DWORD)::SendMessageA(s_hwEdit,EM_GETLINECOUNT,0,0L);
dw2 = ((s_woMarL*s_woLPX)/100);
pdi->cbSize = 20;
pdi->lpszDocName = PathFindFileName(s_pchExeName);
pdi->fwType = 0;
pdi->lpszDatatype = NULL;
pdi->lpszOutput = NULL;
xPPI = GetDeviceCaps(hdP,LOGPIXELSX);
yPPI = GetDeviceCaps(hdP,LOGPIXELSY);
xExt = ((850*xPPI)/100);
yExt = ((1100*yPPI)/100);
xPPI = 0;
yPPI = 0;
yPPI = (ppd->nFromPage*51);
StartDoc(hdP,pdi);
for (xPPI = ppd->nFromPage; xPPI < ppd->nToPage; xPPI++)
{
SetMapMode(hdP,MM_ANISOTROPIC);
SetWindowExt(hdP,850,-1100,NULL);
SetViewportExt(hdP,xExt,-yExt,NULL);
StartPage(hdP);
for (wo2 = 0; wo2 < 51; wo2++)
{
if (dwLines < (DWORD)yPPI)
break;
dwTm = (DWORD)::SendMessageA(s_hwEdit,EM_LINEINDEX,yPPI,0L);
if (dwTm < uiTm)
{
*pch2 = (BYTE)180;
::SendMessageA(s_hwEdit,EM_GETLINE,yPPI,(LPARAM)pch2);
wo1 = (BYTE)*pch2;
if (wo1 == 180)
*pch2 = 0;
dw1 = lstrlenA(pch2);
TextOut(hdP,(dw2+4),(wo2*20),pch2,dw1);
}
yPPI++;
}
wsprintfA(pch2,TEXT("PAGE %u"),(xPPI+1);
dwTm = lstrlen(pch2);
TextOut(hdP,360,1020,pch2,dwTm);
EndPage(hdP);
}
EndDoc(hdP);
DeleteDC(hdP);
return 0;
-
June 29th, 2013, 12:12 PM
#8
Re: Printer left margin
Please, when you post code use code tags as asked by Victor in post #4. Go Advanced, select code then click '#'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 29th, 2013, 03:00 PM
#9
Re: Printer left margin
Does this help?
360,1020 is the bottom middle of the page in pixels.
850,-1100 from other peoples code.
Is what I think is the page size in inchis * 100?
Code:
PRINTDLG pdlg;
PRINTDLG* ppd = NULL;
DOCINFO di;
DOCINFO* pdi = NULL;
DWORD dw1 = 0;
DWORD dw2 = 0;
DWORD dwLines = 0;
DWORD dwTm = 0;
DWORD dw1 = 0;
DWORD dw2 = 0;
UINT uiTm = 0;
int xPPI = 0;
int yPPI = 0;
long xExt = 0;
long yExt = 0;
WORD wo1 = 0;
WORD wo2 = 0;
char* pch1 = NULL;
char* pch2 = NULL;
char chP[180];
ppd = (PRINTDLG*)&pdlg;
pdi = (DOCINFO*)&di;
pch1 = s_pchBuf1;
pch2 = (char*)&chP;
// hdp = HDC of printer
// s_hwEdi = HWND of Edit Control
// s_woMarL = Left Margin (inchis*100)
// s_woLPX = GetDeviceCaps(HDC of Edit Control,LOGPIXELSX);
// s_pchBuf1 = new char[97000]
// s_pchExeName = Path of this .exe file
uiTm = ::GetWindowTextA(s_hwEdit,s_pchBuf1,96968);
if ((uiTm == 0) || (*s_pchBuf1 == 0))
return 0;
dwLines = (DWORD)::SendMessageA(s_hwEdit,EM_GETLINECOUNT,0,0L);
dw2 = ((s_woMarL*s_woLPX)/100);
pdi->cbSize = 20;
pdi->lpszDocName = PathFindFileName(s_pchExeName);
pdi->fwType = 0;
pdi->lpszDatatype = NULL;
pdi->lpszOutput = NULL;
xPPI = GetDeviceCaps(hdP,LOGPIXELSX);
yPPI = GetDeviceCaps(hdP,LOGPIXELSY);
xExt = ((850*xPPI)/100);
yExt = ((1100*yPPI)/100);
xPPI = 0;
yPPI = 0;
yPPI = (ppd->nFromPage*51);
StartDoc(hdP,pdi);
for (xPPI = ppd->nFromPage; xPPI < ppd->nToPage; xPPI++)
{
SetMapMode(hdP,MM_ANISOTROPIC);
SetWindowExt(hdP,850,-1100,NULL);
SetViewportExt(hdP,xExt,-yExt,NULL);
StartPage(hdP);
for (wo2 = 0; wo2 < 51; wo2++)
{
if (dwLines < (DWORD)yPPI)
break;
dwTm = (DWORD)::SendMessageA(s_hwEdit,EM_LINEINDEX,yPPI,0L);
if (dwTm < uiTm)
{
*pch2 = (BYTE)180;
::SendMessageA(s_hwEdit,EM_GETLINE,yPPI,(LPARAM)pch2);
wo1 = (BYTE)*pch2;
if (wo1 == 180)
*pch2 = 0;
dw1 = lstrlenA(pch2);
TextOut(hdP,(dw2+4),(wo2*20),pch2,dw1);
}
yPPI++;
}
wsprintfA(pch2,TEXT("PAGE %u"),(xPPI+1);
dwTm = lstrlen(pch2);
TextOut(hdP,360,1020,pch2,dwTm);
EndPage(hdP);
}
EndDoc(hdP);
DeleteDC(hdP);
return 0;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|