|
-
Feb 5th, 2003, 02:49 PM
#1
Thread Starter
Frenzied Member
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;
}
}
-
Feb 8th, 2003, 06:39 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|