Printer left margin
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Printer left margin

  1. #1
    Join Date
    Mar 2013
    Posts
    13

    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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,012

    Re: Printer left margin

    And how does your code look like?
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2013
    Posts
    13

    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 12:41 PM.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,012

    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

  5. #5
    Join Date
    Jan 2012
    Location
    India
    Posts
    193

    Re: Printer left margin

    U can use BeginPrint and in that GetDeviceCaps .. U can set page layout in that

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    19,012

    Re: Printer left margin

    Quote Originally Posted by ROCKYCAT View Post
    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

  7. #7
    Join Date
    Mar 2013
    Posts
    13

    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;

  8. #8
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,875

    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++17 Compiler: Microsoft VS2017 (15.5.0)

  9. #9
    Join Date
    Mar 2013
    Posts
    13

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)