How: Print in landscape from code in VB 
Author Message
 How: Print in landscape from code in VB

I need to print some stuff in VB, but I can not
find out how to print anything in Landscape
without using the Print Dialog box.  I do not
want to use the dialog box nor to I want to
set the printer to print in landscape by default.

It looks like I can do this with the ExtDeviceMode
API call and setting dmOrientation to landscape in
the DEVMODE structure, but I have very little documentation
on this and no examples.

Is there an easier way?

Please cc a reply to my e-mail.

Thanks,
Steven

--

+ Texas Department of Health,                      home (512) 453-2317 +
+ WIC Automation                              work (512) 458-7111x3476 +
+ Just say no to Win95; Linux Yes      Pager 800-624-7243 PIN#145-9112 +
+ My opinions are my own and by no means represent the state of Texas. +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Copyright (C) 1996 by Steven Drinovsky.  Free distribution to everyone
except Microsoft, who can purchase for US$1,000 per distributed copy.



Sun, 19 Jul 1998 03:00:00 GMT  
 How: Print in landscape from code in VB

says...

Quote:

>I need to print some stuff in VB, but I can not
>find out how to print anything in Landscape
>without using the Print Dialog box.  I do not
>want to use the dialog box nor to I want to
>set the printer to print in landscape by default.

>It looks like I can do this with the ExtDeviceMode
>API call and setting dmOrientation to landscape in
>the DEVMODE structure, but I have very little documentation
>on this and no examples.

>Is there an easier way?

Get a copy of VSVIEW off of CICA or SIMTEL.

John



Mon, 20 Jul 1998 03:00:00 GMT  
 How: Print in landscape from code in VB

PSS ID Number: Q80185
Article last modified on 06-21-1995

1.00 2.00 3.00

WINDOWS

---------------------------------------------------------------------
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for
  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0
---------------------------------------------------------------------

SUMMARY
=======

Some printers support changing the orientation of the paper output to
landscape. With the Windows API Escape() function, you can change
the settings of the printer to either landscape or portrait. In addition,
if you have one of the following products, you can use the Common Dialog
box to allow users to set the mode inside a Visual Basic Application:

 - Visual Basic version 1.0 Professional Toolkit
 - Professional Edition of Visual Basic version 2.0
 - Standard or Professional Edition of Visual Basic version 3.0

Below is an example showing how to invoke the Windows API Escape()
function from Microsoft Visual Basic.

NOTE: The Windows API Escape() function is provided in Windows versions
3.0 and 3.1 for backward compatibility with earlier versions of Microsoft
Windows. Applications are supposed to use the GDI DeviceCapabilities()
and
ExtDeviceMode() functions instead of the Escape() function, but neither
DeviceCapabilities() nor ExtDeviceMode() can be called directly from
Visual
Basic. This is because they are exported by the printer driver, not by
the
Windows GDI. The only way to use ExtDeviceMode() or DeviceCapabilities()
in Visual Basic is to create a DLL and call them from there.

MORE INFORMATION
================

Normally, output for the printer is in portrait mode, where output is
printed horizontally across the narrower dimension of a paper. In
landscape mode, the output is printed horizontally across the longer
dimension of the paper.

You can use the Escape() function to change the orientation of the
printer by passing GETSETPAPERORIENT as an argument. When you
initially print text to the printer, Visual Basic will use the
currently selected orientation. Sending the Escape() function will not
take effect until you perform a Printer.EndDoc. After you perform a
Printer.EndDoc, output will print in the orientation that you have
selected.

To determine if your printer supports landscape mode, do the
following:

1. From the Windows Program Manager, run Control Panel.

2. From the Control Panel, select the Printers icon.

3. From the Printers dialog box, choose the Configure button.

4. The Configure dialog box will contain an option for landscape
   orientation if landscape is supported on your printer.

How to Check the Current Orientation of the Printer
---------------------------------------------------

To check the current orientation of the printer, use the following code:

' Enter the following Declare statement as one, single line:
Declare Function Escape% Lib "GDI" (ByVal hDC%, ByVal nEsc%, ByVal nLen%,
   lpData As Any, lpOut As Any)

Sub Command1_Click ()
   Const PORTRAIT = 1
   Const LANDSCAPE = 2
   Const GETSETPAPERORIENT = 30

   Dim Orient As OrientStructure
   Printer.Print ""
   Orient.Orientation = LANDSCAPE
   x% = Escape(Printer.hDC, GETSETPAPERORIENT, Len(Orient), "", Null)
   Print x%
End Sub

How to Change the Printer Orientation to Landscape
--------------------------------------------------

The following example below demonstrates how to change the printer
orientation to landscape. Please note that your printer must support
landscape mode for these commands to have any effect.

1. Start a new project in Visual Basic (ALT, F, N). Form1 is created by
   default.

2. Add a command button (Command1) to Form1.

3. Add the following code to the global module:

   Type OrientStructure
      Orientation As Long
      Pad As String * 16
   End Type
   ' Enter the following Declare statement on one, single line:
   Declare Function Escape% Lib "GDI" (ByVal hDc%, ByVal nEsc%,
               ByVal nLen%, lpData As OrientStructure, lpOut As Any)

4. Add the following code to the Command1_Click event procedure of the
   Command1 button:

   Sub Command1_Click ()
      Const PORTRAIT = 1
      Const LANDSCAPE = 2
      Const GETSETPAPERORIENT = 30

      Dim Orient As OrientStructure

      '* Start the printer
      Printer.Print ""

      '* Specify the orientation
      Orient.Orientation = LANDSCAPE

      '* Send escape sequence to change orientation
      x% = Escape(Printer.hDC, GETSETPAPERORIENT,
                Len(Orient), Orient, NULL)
      '* The EndDoc will now re-initialize the printer
      Printer.EndDoc

      Printer.Print "Should print in landscape mode"
      Printer.EndDoc
   End Sub

Additional reference words: 1.00 2.00 3.00
KBCategory: kbprint kbprg kbcode
KBSubcategory: APrgPrint

=========================================================================
====

Copyright Microsoft Corporation 1995.



Sat, 25 Jul 1998 03:00:00 GMT  
 How: Print in landscape from code in VB

Quote:

>I need to print some stuff in VB, but I can not
>find out how to print anything in Landscape
>without using the Print Dialog box.  I do not
>want to use the dialog box nor to I want to
>set the printer to print in landscape by default.

>It looks like I can do this with the ExtDeviceMode
>API call and setting dmOrientation to landscape in
>the DEVMODE structure, but I have very little documentation
>on this and no examples.

check out pprtr47.zip in cica, garbo or simtel mirrors
(pprtr4.zip on CIS or AOL), e.g. in /simtel/win3/dll
on oak.oakland.edu (or ftp.coast.net, their latest, fastest
mirror) ...

  16-bit Windows DLL providing higher-level language access
  via functions to retrieve and change all printer
attributes
  (orientation, pagesize, bin, copies, etc).  Also list
  available printers, get/change default printer, get port,
  get printer capabilities. V4.7 adds W95 & NT
  compatibility + functions for printable area/margins,
print
  to supplied file names, use printer's setup dialog; more
  samples. Shareware $10. SWREG #1462. Upl by author.
Mentioned
  in the April 95 VBPJ Q&A section.

---------------------
"Programming is the art of debugging a blank sheet of
paper"
Paul F Poellinger    2019 Round Lake Drive
Silent O Software    Houston, TX  77077


        http://rampages.onramp.net/~pelican



Sat, 25 Jul 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Code to print off in landscape?

2. Landscape printing in VB 5.0

3. Landscape Printing in VB

4. changing print setup from porttrait to landscape using VB

5. Landscape Printing in VB 5.0

6. VB landscape print

7. VB Printing in Landscape Mode

8. Crystal Reports Printing to the not-default printer sq Landscape printing

9. Vb code to print 2D bar-code

10. Q. Can we print color-coded VB codes?

11. Retrieving code from a print file of vb project code (vb6)

12. AC97?:Print table contents in landscape for all tables in DB

 

 
Powered by phpBB® Forum Software