Results 1 to 2 of 2

Thread: Printing Text

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Question Printing Text

    I'm trying to print the text in a multiline edit box.

    The text prints, but only on one line without line breaks and
    the font is not correct.

    SelectObject(...) seems to set the font, but then the text prints
    really small.

    Code:
    void PrintWindowText(HWND hWnd)
    {
    	DOCINFO di;
    	PRINTDLG pd;
    	
    	ZeroMemory(&pd, sizeof(PRINTDLG));
    	pd.lStructSize = sizeof(PRINTDLG);
    	pd.hwndOwner   = hWnd;
    	pd.hDevMode    = NULL;
    	pd.hDevNames   = NULL;
    	pd.Flags       = PD_RETURNDC | PD_NOPAGENUMS;
    	
    	if (PrintDlg(&pd)) 
    	{
    		memset( &di, 0, sizeof(DOCINFO)); 
    		di.cbSize = sizeof(DOCINFO); 
    		di.lpszOutput = (LPTSTR) NULL; 
    		di.lpszDatatype = (LPTSTR) NULL; 
    		di.fwType = 0; 
    		
    		
    		StartDoc(pd.hDC, &di);
    		StartPage(pd.hDC); 
    		
    		GetWindowRect(hWnd, &rPrint);
    		
    		DWORD dwBufferSize = GetWindowTextLength(hWnd)+1;
    		
    		CHAR* szBuffer = new CHAR[dwBufferSize];
    		
    		GetWindowText(hWnd, szBuffer, dwBufferSize);
    		
    		//SelectObject(pd.hDC, (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0));
    		
    		TextOut(pd.hDC, 20, 20, szBuffer, dwBufferSize);
    		
    		EndPage(pd.hDC);
    		EndDoc(pd.hDC);
    		DeleteDC(pd.hDC);
    		delete[] szBuffer;
    	}
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Fonts sizes are given in device units. This means that a 40 pixel font (quite large on a screen) will end up very tiny on a 300dpi printer.

    MSDN contains the code to calculate a point size font for a given device.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width