How to Set Landscape or Portrait for Printer in Windows 3.0

ID Number: Q80185

1.00

WINDOWS

Summary:

Some printers support changing the orientation of the paper output to

landscape. With the Windows 3.0 API Escape function, you can change

the settings of the printer to either landscape or portrait.

Below is an example of invoking the Windows 3.0 API Escape function

from Microsoft Visual Basic programming system version 1.0 for

Windows.

Important Note: The Windows API Escape function used below is provided

in Windows 3.0 only for backward compatibility with earlier Microsoft

Windows releases. New applications should use the GDI

DeviceCapabilities and ExtDeviceMode functions instead of the Escape

function shown below.

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 3.0 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.

The 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.

Code Example

------------

1. Run Visual Basic, or from the File menu, choose New Project (ALT,

F, N) if Visual Basic is already running. Form1 is created by

default.

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

3. Add the following code to the global module:

GLOBAL.BAS

----------

Type OrientStructure

Orientation As Long

Pad As String * 16

End Type

' The following Declare statement must be on a 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:

FORM1

-----

Sub Command1_Click ()

Const PORTRAIT = 1

Const LANDSCAPE = 2

Const GETSETPAPERORIENT = 30

Const NULL = 0&

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 3.00