Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embed printer prompt on form or centre the printer prompt 2

Status
Not open for further replies.

Steve-vfp9user

Programmer
Feb 5, 2013
334
GB
Hi

The below is my standard use of selecting a printer before printing:

Code:
cPrinter = GETPRINTER()
IF EMPTY(cPrinter)
  RETURN
ENDIF

SET PRINTER TO NAME(cPrinter)
* CODE ETC
SET PRINTER TO

Is it possible to embed the printer prompt on a form as I would like to show other information on that form or can the printer prompt be centered on the screen?

This is purely for cosmetic purposes.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
I don't think so.
But you could get the names of printers from APRINTERS() and use that list of printer name in your own form.

Chriss
 
Steve, just to be clear: when you refer to the "printer prompt", do you mean the dialogue that is invoked by GETPRINTER()? If so, I don't know any way of centring it on the screen.

Bit if you want to display the various items from that dialogue in your own form ... Yes, you do that. You can display a control (probably a listbox or combo box) containing a list of installed printers to choose from. Use APRINTERS()to get the list of printers, and then populate the combo box or list box in the usual way.

To display the supplementary info, such as the driver name, the printer location, the comment and the status, call APRINTERS() with 1 as the second parameter. That will give you the relevant information in columns 2 - 5 of the resulting array. You can also get the status by calling PRINTSTATUS(), but I think that only works in DOS . You can also call PRTINFO() to get things like the paper size, orientation, default paper source, and so on.

Does that help at all?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Chriss - Thank you

Mike - Your post

"Does that help at all?"

Yes and that sounds like a good idea. I'll try it out and post back.

Much appreciated both.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
Well, the only other thing the GETPRINTER() dialog has and Mike didn't mention yet is the Network Printer button.

There's ANETRESOURCES() which is more than determining printers, but look at the help. I'd always prefer to also have network printers in the APRINTERS() list, which can be done by, well, doing a printer installation, picking a network printer and give it a name to address it by locally, and then also have it in APRiNTERS().

That's a bit like mapping a network share with a drive letter and being able to address it by that letter. Installing a network printer just like a normal printer does more than providing a name, you also have the printer settings under that name and can do the same as with any printer, if you install it multiple times you can address it by different names, for which different settings are associated.

But I have the impression you're interested in the list of printer names only and not the other information in the GETPRINTER() dialog. Since you only need the name of a printer for SET PRINTER TO NAME ... you can simply integrate this name list. The only other thing GETPRINTER does aside from giving the name list to pick from, is display the currently picked name as the initial selection.

Chriss
 
The only other thing GETPRINTER does aside from giving the name list to pick from, is display the currently picked name as the initial selection.

Which you can get by calling [tt]SET("PRINTER", 3)[/tt].

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike said:
I don't know any way of centring it on the screen.
I second the solution of creating your own Select printer form with a ListBox of printers but it is possible to manipulate the Printer Dialog of getprinter().
You can reposition it on your screen and make the form smaller or larger. And you will be surprised that the form contains actually more objects then you see in the current view. Ever tried TAB + ENTER on that Printer screen?

The trick is to use a second exe (second thread) to reposition the Printer window in your application (in fact any window can be manipulated).
That second exe can be in VB or in VFP or any other language.
It uses the FindWindow and MoveWindow api.

A quick and dirty example of that exe and yes, there are better ways to split the command into parameters:

The Movewf.exe
Code:
parameter cmd

*cmd like "0400=0100=0600=0400=0200=Printer"  form left, form top, form width, form height, max seconds trying, window name

xs=val(substr(cmd,1,4))
ys=val(substr(cmd,6,4))
wf=val(substr(cmd,11,4))
hf=val(substr(cmd,16,4))
wt=val(substr(cmd,21,4))
fname=substr(cmd,26)

declare integer FindWindow IN user32 integer, string
declare integer MoveWindow in user32 integer,integer,integer,integer,integer, integer

st=seconds()

do while seconds() < st+wt
	fHwnd=findwindow(0,fname) 
	if fHwnd>0
		MoveWindow(fHwnd,xs,ys,wf,hf,1)
		exit
	endif
enddo



And the calling program with getprinter()
For centering you need to calculate the correct x and y values first using sysmetric(1) and (2) and form width and height.

Code:
oScript = CREATEOBJECT("wscript.shell")

cmd='movewf "0400=0100=0600=0400=0002=Printer"'
oScript.run(cmd,1,.f.)
?getprinter()
 
You could make the parameterization simpler, but I see. Since GetPrinter() is showing a window that's gone when you pick one, you have to use a second EXE (or a second IDE) to use MoveWinows to resize it and see the other elements of the dialog.

Well, some of them are in Sys(1037) - Page Layout.

Chriss
 
An ingenious solution, Jack.

I can see that you need to launch the second EXE before you do the GETPRINTER(), because the printer dialogue is modal. Hence the need to delay the actual move, to give the dialogue time to open. But I'm not sure why you have set the parameters up in that way, rather than simply passing each one individually.

But it's certainly a good technique to keep in mind.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
As I said the passing of parameters can be simpler especially to a "VFP.exe". But not all programming languages can accept multiple parameters. AFAIK a "VB6.EXE" can accept only one command line argument and you have to split that one into individual parameters using VB's split function. You could say the way I passed the parameters in the example can be used by any language. I rather use VB6 for auxiliary exes like movewf.exe. But as the example shows it's also possible programming in VFP only.
 
I would use the 'windows' based printer selection instead, which offers a wide array of settings, at least a lot more than sys(1037)

Screenshot_-_3_25_2023_8_41_36_AM_cudkki.png




If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike Lewis,

would that be necessary? By now, Steve could use MoveWindow to move the GetPrinter dialog or use some other dialogs on top of creating his own. I think it would now be a good move of Steve to wrap this up or change the question based on all the additional alternatives given.

Personally, I prefer to [tt]SET PRINTER TO NAME (nameexpression)[/tt] because it doesn't change the default windows printer. If you'd like to provide options for a printer for each print job like Word and other application allow, then SYS(1037) is of limited support only, it once could do more. It was new to me that GetPrinter has a hidden printer properties button. I think the only unmentioned things now regarding printers is that there are further API functions to also control print jobs and other things, too. Plenty of possibilities to pick from.

You inintally also showed how you can get the further informations also displayed by GetPrinter. Such as the driver name. I always thought of that as a dispensable information of this dialog, as it's nothing an end user wold normally know or need to know, but even that's all available.

Chriss
 
Me said:
I see that DockWin is an Autohotkey script. Do you know if it can ba automated from within VFP?

To answer my own question: Yes.

From the Autohotkey documentation:

With AutoHotkey installed, there are several ways to run a script:
[ul][li] Double-click a script file (or shortcut to a script file in Explorer.[/li]
[li] [highlight #FCE94F]Call AutoHotkey.exe on the command line and pass the script's filename as a command-line parameter.[/highlight][/li]
[li] After creating the default script, launch AutoHotkey via the shortcut in the Start menu to run it.[/li]
[li] If AutoHotkey is pinned to the taskbar or Start menu on Windows 7 or later, recent or pinned scripts can be launched via the program's Jump List.[/li]
[/ul]

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Chris, I was asking about automating Autohotkey more out of curiosity than anything else. As you say, it would be good to hear from Steve whether this question of centralising the dialogue is really important, or whether creating his own dialogue would be his preferred solution.

Personally, I wouldn't bother with any of these solutions. I would stick to the built-in GETPRINTER() dialogue, which is not only much less work, but it is also what users are accustomed to. Then again, I don't know Steve's users; there might well be a good reason for this request.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you for all the posts.

Having evalutated all of them, it's back to the cPrinter = GETPRINTER() prompt as we felt for it's worth cosmetically, it wasn't worth.

Hope that doesn't sound defeatist but perhaps it's the old if it 'aint broke, don't fix it syndrome.

Much obliged.

Thank you

Steve Williams
VFP9, SP2, Windows 10
 
If you're mainly after the list of printer names to pick from, I'd replace the dialog by embedding a combobox using the array of names APRINTERS() fills. Of course, it's all well, if GETPRINTER() does the job.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top