How to select printer by using lotus script in R6.5

Hi all,i have a question about select printer in Notes, and it is very urgent!!!.

i want to create a new button (action) in the memo form, when i click this new button, it will print the memo by using a dedicated printer (eg: a postscript printer) and create a file “temp.ps” in c:\temp.

but i found that i cannot select printer through lotusscript.

did any kind man can teach me how to do?

thank a lot

Subject: How to select printer by using lotus script in R6.5

No way to do that.

All you can have is to display the print dialog with uidoc.Print() or uiview.Print().

Subject: RE: How to select printer by using lotus script in R6.5

Actually there is a wayHere is code that I found some time ago and worked well for me

Declarations:

Const HWND_BROADCAST = &HFFFF&

Const WM_WININICHANGE = &H1A

Declare Function GetProfileString Lib “kernel32” Alias “GetProfileStringA” _

(Byval lpAppName As String, _

Byval lpKeyName As String, _

Byval lpDefault As String, _

Byval lpReturnedString As String, _

Byval nSize As Long) As Long

Declare Function WriteProfileString Lib “kernel32” Alias “WriteProfileStringA” _

(Byval lpszSection As String, _

Byval lpszKeyName As String, _

Byval lpszString As String) As Long

Declare Function SendNotifyMessage Lib “user32” Alias “SendNotifyMessageA” _

(Byval hwnd As Long, _

Byval msg As Long, _

Byval wParam As Long, _

lParam As Any) As Long

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument



Set uidoc = ws.CurrentDocument

Call SetDefPrinter("HP4200_Prod", "", "IP_10.0.4.59")

Call uidoc.Print( 1 )

End Sub

Sub SetDefPrinter(Byval PrinterName As String, Byval DriverName As String, Byval PrinterPort As String)

Dim DeviceLine As String

'rebuild a valid device line string

DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort

'Store the new printer information in the

'[WINDOWS] section of the WIN.INI file for

'the DEVICE= item

Call WriteProfileString("windows", "Device", DeviceLine)	

'Cause all applications to reload the INI file

Call SendNotifyMessage(HWND_BROADCAST, WM_WININICHANGE, 0, Byval "windows")	

End Sub

Sub GetDriverAndPort(Byval Buffer As String, DriverName As String, PrinterPort As String)

Dim posDriver As Long

Dim posPort As Long

DriverName = ""

PrinterPort = ""

'The driver name is first in the string

'terminated by a comma

posDriver = Instr(Buffer, ",")



If posDriver > 0 Then

	

 'Strip out the driver name

	DriverName = Left(Buffer, posDriver - 1)

	

 'The port name is the second entry after

 'the driver name separated by commas.

	posPort = Instr(posDriver + 1, Buffer, ",")

	

	If posPort > 0 Then

		

    'Strip out the port name

		PrinterPort = Mid(Buffer, posDriver + 1, posPort - posDriver - 1)

		

	End If

End If

End Sub

Function StripNulls(startstr As String) As String

'Take a string separated by chr$(0)

'and split off 1 item, shortening the

'string so next item is ready for removal.

Dim pos As Long



pos = Instr(startstr$, Chr$(0))



If pos Then

	

	StripNulls = Mid$(startstr, 1, pos - 1)

	startstr = Mid$(startstr, pos + 1, Len(startstr))

	

End If

End Function

Sub SetDefaultPrinterWinNT()

Dim Buffer As String

Dim DeviceName As String

Dim DriverName As String

Dim PrinterPort As String

Dim PrinterName As String

Dim r As Long



If List1.ListIndex > -1 Then

	

 'Get the printer information for the currently selected

 'printer in the list. The information is taken from the

 'WIN.INI file.

	Buffer = Space(1024)

	PrinterName = List1.list(list1.ListIndex)

	

	Call GetProfileString("PrinterPorts", PrinterName, "", Buffer, Len(Buffer))

	

 'Parse the driver name and port name out of the buffer

	GetDriverAndPort Buffer, DriverName, PrinterPort

	

	If (Len(DriverName) > 0) And (Len(PrinterPort) > 0) Then

		SetDefPrinter PrinterName, DriverName, PrinterPort

	End If

	

End If

End Sub

Subject: RE: How to select printer by using lotus script in R6.5

thank for your code.i have tried to create new button (action) and insert the code for testing, i found that the default printer has been changed. (by checking the printer list in windows xp), but R6.5 still launch the original printer.

i found that this code is work for R5.

um… anyone who know the reason why the above code cannot apply to R6.5? and any workaround for this issue?

thanks

Subject: RE: How to select printer by using lotus script in R6.5

wierd, I used this code in an R7 environment, and it worked very well

Subject: RE: How to select printer by using lotus script in R6.5

As of 7.0.3, the uidoc.Print method takes a printer name as parameter (which might not help prodigy on 6.5 at all …).

Subject: RE: How to select printer by using lotus script in R6.5

… without calling native Windows functions, I should have added.

Anyway, thanks for sharing this fully fledged code sample.

And just in case somebody is going to ask for this: There’s also no native LotusScript support for opening the print preview dialog. The only way I know of is to simulate key strokes.