?
Solved

How to get the IE Window to set Landscape Printing ?

Posted on 1999-12-09
6
Medium Priority
?
432 Views
Last Modified: 2013-12-03
Hi everybody,

I want to set the Landscape or portrait mode of the printer with printing
over IE4 or 5. It doesnt work as in MSDN descripted.
Or do I use the wrong window?
I tryed to use the GetHwnd() from the IE4, but I always get
an exception. So I used the wnd of the following class:

 <<webbrowser2.cpp>>  <<webbrowser2.h>>
see below ...

But again no luck. How I can get the right hwnd to set the paper orientation ?

Any help is appreciated ...

Thanks

Toni

......................


      SetLandscapeDevMode(wnd->m_hWnd, printermode);
      lpDispatch = ((CWebBrowser2 *)wnd)->GetDocument();
            
      if (lpDispatch != NULL)      {
            lpDispatch->QueryInterface(IID_IOleCommandTarget,
(void**)&lpOleCommandTarget);
            lpDispatch->Release();
            // print contents of web browser control
            lpOleCommandTarget->Exec(NULL, OLECMDID_PRINT,
OLECMDEXECOPT_DONTPROMPTUSER,´NULL,NULL);
            lpOleCommandTarget->Release();
      }


LPDEVMODE SetLandscapeDevMode(HWND hWnd, int mode)
{
   HANDLE      hPrinter;
   LPDEVMODE   pDevMode;
   DWORD       dwNeeded, dwRet;
   char pDevice[256];

   try
   {
            CPrintDialog *printDlg =
                  new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC,
NULL);
 
            // Dont Display Windows print dialog box.
            printDlg->GetDefaults();
            CString prnName = printDlg->GetDeviceName();
            strcpy(      pDevice, prnName );
            prnName.ReleaseBuffer();
            delete printDlg;

         /* Start by opening the printer */
         if (!OpenPrinter(pDevice, &hPrinter, NULL))
               return NULL;

         /*
            * Step 1:
            * Allocate a buffer of the correct size.
            */
         dwNeeded = DocumentProperties(hWnd,
               hPrinter,       /* handle to our printer */
               pDevice,        /* Name of the printer */
               NULL,           /* Asking for size so */
               NULL,           /* these are not used. */
               0);             /* Zero returns buffer size. */
         pDevMode = (LPDEVMODE)malloc(dwNeeded);

         /*
            * Step 2:
            * Get the default DevMode for the printer and
            * modify it for our needs.
            */
         dwRet = DocumentProperties(hWnd,
               hPrinter,
               pDevice,
               pDevMode,       /* The address of the buffer to fill. */
               NULL,           /* Not using the input buffer. */
               DM_OUT_BUFFER); /* Have the output buffer filled. */
         if (dwRet != IDOK)
         {
               /* if failure, cleanup and return failure */
               free(pDevMode);
               ClosePrinter(hPrinter);
               return NULL;
         }

         /*
            * Make changes to the DevMode which are supported.
            */
         if (pDevMode->dmFields & DM_ORIENTATION)
         {
                  /* if the printer supports paper orientation, set
it*/
                  if (mode == 1)
                        pDevMode->dmOrientation =
DMORIENT_LANDSCAPE;
                  else
                        pDevMode->dmOrientation = DMORIENT_PORTRAIT;
                  
         }

      //   if (pDevMode->dmFields & DM_DUPLEX)
      //   {
               /* if it supports duplex printing, use it */

      //       pDevMode->dmDuplex = DMDUP_HORIZONTAL;
      //   }

         /*
            * Step 3:
            * Merge the new settings with the old.
            * This gives the driver a chance to update any private
            * portions of the DevMode structure.
            */
         dwRet = DocumentProperties(hWnd,
               hPrinter,
               pDevice,
               pDevMode,       /* Reuse our buffer for output. */
               pDevMode,       /* Pass the driver our changes. */
               DM_IN_BUFFER |  /* Commands to Merge our changes and */
               DM_OUT_BUFFER); /* write the result. */

         /* Done with the printer */
         ClosePrinter(hPrinter);

         if (dwRet != IDOK)
         {
               /* if failure, cleanup and return failure */
               free(pDevMode);
               return NULL;
         }
   }
   catch(...)
   {
   }

   /* return the modified DevMode structure */
   return pDevMode;

}
0
Comment
Question by:moosach
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:wylliker
ID: 2272191
Changing the Page Setup is difficult in IE 4 and 5.  Under 3 you could change it with client side script.

I have come across an ActiveX component that does what you want and there is a corresponding article on MSDN.

This Activex control will launch the Page Setup dialog in a hidden window and manipulate the various values - WITHOUT - changing the end users current settings.  This means that you can set up landscape/portrait on a per page basis with just a few lines of client-side script and this control.

I am not affiliated with this company but found their product (free for simple print settings you pay for advanced) would solve our need to turn off and/or change the header and footer settings on a per page basis.

The control is here - there is a working DEMO on their site:

http://www.meadroid.com/scriptx/

The related MSDN article is here:

http://msdn.microsoft.com/workshop/author/script/dhtmlprint.asp



0
 
LVL 1

Author Comment

by:moosach
ID: 2279633
Hi,

pretty good answer ! That will help !
How to give you the points now :-) ?

CU

Toni
0
 
LVL 4

Expert Comment

by:wylliker
ID: 2284496
I will re-submit my comment above as an answer.  You need only accept and grade it.

With a Rich Edit Control you need to use the EM_EXSETSEL message.

Set up a CHARRANGE structure

CHARRANGE SelRange;
SelRange.cpMin = 0;
SelRange.cpMax = 0;

SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &SelRange);


Give it a try and let me know
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 4

Expert Comment

by:wylliker
ID: 2284504
Sorry about that - posted a comment to a different question as an answer.

Please reject this and I will re-submit my answer properly.

Again, sorry.
0
 
LVL 1

Author Comment

by:moosach
ID: 2285851
No Problem :-) !!
0
 
LVL 4

Accepted Solution

by:
wylliker earned 800 total points
ID: 2287277
Changing the Page Setup is difficult in IE 4 and 5.  Under 3 you could change it with client side script.

I have come across an ActiveX component that does what you want and there is a corresponding article on MSDN.

This Activex control will launch the Page Setup dialog in a hidden window and manipulate the various values - WITHOUT - changing the end users current settings.  This means that you can set up landscape/portrait on a per page basis with just a few lines of client-side script and this control.

I am not affiliated with this company but found their product (free for simple print settings you pay for advanced) would solve our need to turn off and/or change the header and footer settings on a per page basis.

The control is here - there is a working DEMO on their site:

http://www.meadroid.com/scriptx/ 

The related MSDN article is here:

http://msdn.microsoft.com/workshop/author/script/dhtmlprint.asp 

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question