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; } }




Reply With Quote