Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to hook system API under win9x? Pin
jedyking1-Nov-04 5:32
jedyking1-Nov-04 5:32 
GeneralThe Focus of a modeless dialog2 Pin
si_691-Nov-04 5:26
si_691-Nov-04 5:26 
GeneralRe: The Focus of a modeless dialog2 Pin
Jim Crafton1-Nov-04 6:15
Jim Crafton1-Nov-04 6:15 
GeneralRe: The Focus of a modeless dialog2 Pin
valikac1-Nov-04 7:37
valikac1-Nov-04 7:37 
GeneralThe Focus of a modeless dialog Pin
si_691-Nov-04 5:25
si_691-Nov-04 5:25 
GeneralEdit control beeps on Esc or Tab keys Pin
Jim Crafton1-Nov-04 5:25
Jim Crafton1-Nov-04 5:25 
GeneralRe: Edit control beeps on Esc or Tab keys Pin
peterchen1-Nov-04 7:24
peterchen1-Nov-04 7:24 
GeneralOne more on print orientation and paper size specifications Pin
Member 12423731-Nov-04 4:06
Member 12423731-Nov-04 4:06 
Hello guys,
I used to print the content of a RichEditText control with following code.
But now I would like to print it in landscape and with paper specifications (12cm x8.5cm).
All articles I read are talking about the famous DEVMODE, but I have no clue how to insert this DEVMODE in my existing code.
Can you hep me ?
Thanks in advance
DD


void CTestRichEditText::OnPrint()
{
// lance l'interface pour l'imprimante
CPrintDialog printDialog(false);
bool bShowPrintDialog = TRUE; //FALSE lance directement l'impression

if (bShowPrintDialog)
{
int r = printDialog.DoModal();
if (r == IDCANCEL)
return;
}
else
{
printDialog.GetDefaults();
}

// recently added to try to print in landscape on special paper
DEVMODE *MyPrintMode;
MyPrintMode = printDialog.GetDevMode();
MyPrintMode->dmFields |= DM_ORIENTATION | DM_PAPERSIZE | DM_PAPERLENGTH | DM_PAPERWIDTH;
MyPrintMode->dmOrientation = DMORIENT_LANDSCAPE;
MyPrintMode->dmPaperSize = 0;
MyPrintMode->dmPaperLength = 120;
MyPrintMode->dmPaperWidth = 85;
// end of new added code

HDC hPrinterDC = printDialog.GetPrinterDC();

FORMATRANGE fr;
int nHorizRes = GetDeviceCaps(hPrinterDC, PHYSICALWIDTH),
nVertRes = GetDeviceCaps(hPrinterDC, PHYSICALHEIGHT),
nLogPixelsX = GetDeviceCaps(hPrinterDC, LOGPIXELSX),
nLogPixelsY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
LONG lTextLength; // Longueur total du document
LONG lTextPrinted; // Longueur du document edite

// Ensure the printer DC is in MM_TEXT mode.
SetMapMode ( hPrinterDC, MM_TEXT );
// Rendering to the same DC we are measuring.
ZeroMemory(&fr, sizeof(fr));
fr.hdc = fr.hdcTarget = hPrinterDC;

// Set up the page.
fr.rcPage.left = fr.rcPage.top = 0;
fr.rcPage.right = (nHorizRes/nLogPixelsX) * 1440;
fr.rcPage.bottom = (nVertRes/nLogPixelsY) * 1440;

// Set up 1" margins all around.
fr.rc.left = fr.rcPage.left + 570; // 1440; // 1440 TWIPS = 1 inch.
fr.rc.top = fr.rcPage.top + 570; 1440;
fr.rc.right = fr.rcPage.right - 570; // 1440
fr.rc.bottom = fr.rcPage.bottom - 570; // 1440

// Default the range of text to print as the entire document.
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
// Set up the print job (standard printing stuff here).
DOCINFO di;
ZeroMemory(&di, sizeof(di));
di.cbSize = sizeof(DOCINFO);

di.lpszDocName = "(Untitled)";

// Do not print to file.
di.lpszOutput = NULL;

// Start the document.
StartDoc(hPrinterDC, &di);

// Find out real size of document in characters.
lTextLength = m_RichTextCtrl.SendMessage ( /*hRTFWnd,*/ WM_GETTEXTLENGTH, 0, 0 );
// do {
// Start the page.
StartPage(hPrinterDC);

// Print as much text as can fit on a page. The return value is
// the index of the first character on the next page. Using TRUE
// for the wParam parameter causes the text to be printed.

#ifdef USE_BANDING

lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
FALSE,
(LPARAM)&fr);
SendMessage(hRTFWnd, EM_DISPLAYBAND, 0, (LPARAM)&fr.rc);

#else

lTextPrinted = m_RichTextCtrl.SendMessage(/*hRTFWnd,*/
EM_FORMATRANGE,
TRUE,
(LPARAM)&fr);

#endif

// Print last page.
EndPage(hPrinterDC);

// If there is more text to print, adjust the range of characters
// to start printing at the first character of the next page.
if (lTextPrinted < lTextLength) {
fr.chrg.cpMin = lTextPrinted;
fr.chrg.cpMax = -1;
}
// Tell the control to release cached information.
SendMessage(/*hRTFWnd,*/ EM_FORMATRANGE, 0, (LPARAM)NULL);

EndDoc (hPrinterDC);
DeleteDC(hPrinterDC);
// recently added to try to print in landscape on special paper
GlobalUnlock(MyPrintMode);
// end of new added code
}
GeneralRe: One more on print orientation and paper size specifications Pin
Phil J Pearson1-Nov-04 6:10
Phil J Pearson1-Nov-04 6:10 
GeneralRe: One more on print orientation and paper size specifications Pin
Member 12423731-Nov-04 10:36
Member 12423731-Nov-04 10:36 
GeneralRe: One more on print orientation and paper size specifications Pin
Phil J Pearson2-Nov-04 1:25
Phil J Pearson2-Nov-04 1:25 
GeneralRe: One more on print orientation and paper size specifications Pin
Qadddd2-Nov-04 7:45
Qadddd2-Nov-04 7:45 
GeneralHook woes Pin
Roger Allen1-Nov-04 1:38
Roger Allen1-Nov-04 1:38 
GeneralRe: Hook woes Pin
vcplusplus1-Nov-04 2:38
vcplusplus1-Nov-04 2:38 
GeneralRe: Hook woes Pin
Roger Allen1-Nov-04 2:57
Roger Allen1-Nov-04 2:57 
GeneralRe: Hook woes Pin
PJ Arends1-Nov-04 7:47
professionalPJ Arends1-Nov-04 7:47 
GeneralRe: Hook woes Pin
Roger Allen1-Nov-04 22:55
Roger Allen1-Nov-04 22:55 
GeneralRe: Hook woes Pin
PJ Arends2-Nov-04 6:09
professionalPJ Arends2-Nov-04 6:09 
GeneralRe: Hook woes Pin
Roger Allen2-Nov-04 7:04
Roger Allen2-Nov-04 7:04 
GeneralRe: Hook woes Pin
PJ Arends2-Nov-04 16:17
professionalPJ Arends2-Nov-04 16:17 
GeneralRe: Hook woes Pin
Roger Allen2-Nov-04 22:46
Roger Allen2-Nov-04 22:46 
GeneralDiskQuota on remote machine Pin
std77021-Nov-04 1:24
std77021-Nov-04 1:24 
GeneralRe: DiskQuota on remote machine Pin
David Crow1-Nov-04 4:08
David Crow1-Nov-04 4:08 
GeneralRe: DiskQuota on remote machine Pin
std77021-Nov-04 5:01
std77021-Nov-04 5:01 
QuestionHow do I add chart using Visual C++ Pin
pubududilena1-Nov-04 0:52
pubududilena1-Nov-04 0:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.