15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Switching between PORTRAIT and LANDSCAPE on the fly

Andreas Will -- a.will@T-Online.de
Friday, January 26, 1996

VC 1.52c, VC4.0
Win16, Win32 (NT, Win95)
MSDN available

Hi everyone,

I'd like to switch paper orientation while printing - 
i.e. 1st page 'landscape', 2nd page 'portrait' etc.

Here's what i _do_ know:
CWinApp contains the m_hDevMode member variable.
It is a global handle to a DEVMODE structure, which may be used
to set the orientation and create a printer DC. 

Inside OnPrepareDC() the already created printer/preview DC may be 
altered to fit your needs - however in order to change orientation
it looks like it has to be deleted and recreated with the modified
DEVMODE struct.

Deleting the DC requires a call to EndDoc() first, which of course 
terminates the current print job.

After creating the new DC i call StartDoc to continue printing.

This approach is stolen from OnFilePrint() in mfc\src\viewprnt.cpp
and works farely well with _real_ printing. 

However for print preview a second DC comes into play,
which further complicates the issue.

Here is what i would _like_ to know:
Do I have to override OnFilePrint and OnDraw in order to switch print
orientation on the fly or is there as less brutal - better portable -
way to do this ? 
How can i avoid calling EndDoc/StartDoc and still change the DC ?

My program - currently - is a 16Bit MFC application (doc-view type).
The code is already 32Bit aware/compliant and there is a
good chance that i have to port it to the MAC.
(I'm looking for a solution that is not limited to a single platform.)

TIA for any pointers, hints, ideas
  Andy



/////////////////
Andreas Will
Jever, Germany
a.will@t-online.de
/////////////////



LeRoy Baxter -- lbaxter@cinfo.com
Saturday, January 27, 1996

[Mini-digest: 2 responses]

Try a ResetDC() after the EndPage()

-----From: "Sanu M.P" 


	To change the paper orientation on the fly you need 
to override the OnPrepareDC virtual function associated 
with your view class.(Works for print and print preview
as well)
void CMyView::OnPrepareDC(CDC* pDC,CPrintInfo* pInfo)
{
    LPDEVMODE pDevMode;

    if (pDC->IsPrinting())
    {
        pDevMode = pInfo->m_pPD->GetDevMode();

        // See whether this page requires LANDSCAPE mode.
        if (IsLandscapeRequired(SomeParameter))
            pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
        else
            pDevMode->dmOrientation = DMORIENT_PORTRAIT;

        // Make sure that all objects other than the stock objects
        // that had been selected into the device context have been
        // selected out.
        pDC->ResetDC(pDevMode);
    }

    // Call the base class OnPrepareDC.
    CMyView::OnPrepareDC(pDC,pInfo);
}



Jim Lavin -- ooptech@Onramp.NET
Thursday, February 08, 1996

At 01:26 AM 1/26/96 MET, you wrote:
>Here is what i would _like_ to know:
>Do I have to override OnFilePrint and OnDraw in order to switch print
>orientation on the fly or is there as less brutal - better portable -
>way to do this ? 
>How can i avoid calling EndDoc/StartDoc and still change the DC ?
>

Have you tried using ResetDC()?  We use this constantly to switch from
portrait to landscape on the fly.  By doing this you don't have to worry
about creating multiple print jobs with StartDoc() EndDoc() calls.  You can
even use this to switch paper trays on the fly also.

Check out the documentation, it seems to be pretty useful with all of the
various things you can do with ResetDC().

Hope this helps


Jim Lavin
OOP Technologies
http://emporium.turnpike.net/~jlavin
http://rampages.onramp.net/~ooptech

I've seen programmers who couldn't be passed by reference or by value!





| Вернуться в корень Архива |