Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2003, 01:58 PM
Demigorgon Demigorgon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 Demigorgon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 16 sec
Reputation Power: 0
Printing in landscape with Shellexecute

Greets,

I'm using the ShellExecute to open a file and print it. I was wondering if there is a way to set this so it will print landscape..

All I'm doing is this :

ShellExecute 1, "print", "C:\ log.txt", vbNullString, vbNullString, 0

Much thanks

Reply With Quote
  #2  
Old October 18th, 2003, 03:05 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Using the ShellExecute Function to Print Files

This article explains how to print a file specified by the user of your Microsoft Visual Basic® application.

Printing a File from Within an Application
The Microsoft® Windows® application programming interface (API) ShellExecute function can be used from within a Microsoft Visual Basic® application to print a file. In addition, this function can be used to load an executable (.EXE) file.

To use the ShellExecute function, you must include the following Declare statement in your project:

Private Declare Function ShellExecuteAny Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String,
ByVal lpParameters As Any, ByVal lpDirectory As Any, ByVal nShowCmd As Long)
As Long

The ShellExecute function requires six arguments, as follows:

hWnd A long value that contains the window's handle.
LpOperation A string that specifies the operation that the ShellExecute function is to perform. This string can be one of three values, as follows:
open Specifies that the file lpFile is to be opened. In Microsoft Windows 95 this file may be a Windows 95 folder.
print Specifies that the file lpFile is to be printed.
explore Explores the folder for lpFile in Windows 95.
LpFile A string containing the name of the file to open, print, or explore.
LpParameters Set to NULL if lpFile specifies a document file. If lpFile specifies an executable file, then lpParameters is a pointer to a string specifying the parameters that should be passed to the application.
LpDirectory A string specifying the default directory's name.
NShowCmd If a document file is specified in lpFile, this should be set to zero. If an executable file is specified in lpFile, this determines how the ShellExecute function displays the application after it is loaded. The following values may be used:
SW_HIDE Hides the window and activates the executable file.
SW_MAXIMIZE Maximizes the window.
SW_MINIMIZE Minimizes the window. The next top-level window in the z-order is activated.
SW_RESTORE Activates the window even if it is hidden or minimized.
SW_SHOW Activates the window and displays it in its original size and at its original position.
SW_SHOWMAXIMIZED Activates the window. The window is displayed as maximized.
SW_SHOWMINIMIZED Activates the window. The window is displayed as minimized.
SW_SHOWMINNOACTIVE Activates the window as minimized. The active window retains the focus.
SW_SHOWNA Activates the window in its current state but the active window retains the focus.
SW_SHOWNOACTIVATE Displays the window in its most recent size and in its most recent position. The active window retains the focus.
SW_SHOWNORMAL Displays the window in its original size and at its original position.

In the example program below, you retrieve the name of the file you want to print from the Text Box control. Then you call the ShellExecute function with the lpFile argument set to "print". Notice that for demonstration purposes, you set the nShowCmd argument to SW_SHOWMINNOACTIVE. This argument lets you print the file to the printer without actually having to make the program receive the focus. The actual application that prints the document appears in a minimized window.

Example Program
This program shows how to use the ShellExecute function to print a Microsoft Word document. The function can also print regular text files, such as those created by the Windows 95 Notepad application.

Create a new project in Visual Basic. Form1 is created by default.
Add the following Constant and Declare statements to the General Declarations section of Form1 (note that the Declare statement must be typed as a single line of code):
Private Declare Function ShellExecuteAny Lib "shell32.dll" Alias "ShellExecuteA"
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String,
ByVal lpParameters As Any, ByVal lpDirectory As Any, ByVal nShowCmd As Long)
As Long
Const SW_SHOWMINNOACTIVE = 7

Add the following code to the Form_Load event for Form1:
Private Sub Form_Load()
Text1.Text = ""
End Sub

Add a Text Box control to Form1. Text1 is created by default.
Add a Command Button control to Form1. Command1 is created by default. Set its Caption property to "Print".
Add the following code to the Click event for Command1 (note that the "Ret =" statement must be typed as a single line of code):
Private Sub Command1_Click()
Dim Ret As Long
Dim FileToPrint As String

FileToPrint = Text1.Text
Ret = ShellExecuteAny(Me.hwnd, "print", FileToPrint, ByVal 0&, ByVal 0&,
SW_SHOWMINNOACTIVE)
End Sub

Run the example program by pressing F5. Type the name of a Microsoft Word document or text file you want to print in the Text Box control. Click the Print command button to run the application that originally created the document or text file. Notice that this application remains loaded in the background, minimized, while it sends the file to the printer.


http://msdn.microsoft.com/archive/d...sdn_msdn168.asp

Reply With Quote
  #3  
Old October 18th, 2003, 07:55 AM
Demigorgon Demigorgon is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 Demigorgon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 16 sec
Reputation Power: 0
Thanks cleverpig, but I've read that before, and I'm not seeing where it says anything about page setup parameters such as landscape.

Reply With Quote
  #4  
Old October 19th, 2003, 09:09 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
what's your landscape???..Landscape printer or landscape print control??

Last edited by cleverpig : October 19th, 2003 at 09:14 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Printing in landscape with Shellexecute


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT