×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Embed printer prompt on form or centre the printer prompt
2

Embed printer prompt on form or centre the printer prompt

Embed printer prompt on form or centre the printer prompt

(OP)
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

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

(OP)
Chriss - Thank you

Mike - Your post

Quote:

"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

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

Quote:

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 SET("PRINTER", 3).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Embed printer prompt on form or centre the printer prompt

Quote (Mike)

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 --> VFP

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 --> VFP

oScript = CREATEOBJECT("wscript.shell")

cmd='movewf "0400=0100=0600=0400=0002=Printer"'
oScript.run(cmd,1,.f.)
?getprinter() 

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

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.

RE: Embed printer prompt on form or centre the printer prompt

I would use the 'windows' based printer selection instead, which offers a wide array of settings, at least a lot more than sys(1037)



If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.

RE: Embed printer prompt on form or centre the printer prompt

Mike Gagnon,

I wonder about the page range selection in those Windows standard printer properties dialogs.
But I know you can get there with the help of Windows API, as shown here, for example:
https://github.com/VFPX/Win32API/blob/master/sampl...

Chriss

RE: Embed printer prompt on form or centre the printer prompt

Tom,

I see that DockWin is an Autohotkey script. Do you know if it can ba automated from within VFP (which I htink is what Steve required)?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Embed printer prompt on form or centre the printer prompt

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 SET PRINTER TO NAME (nameexpression) 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

RE: Embed printer prompt on form or centre the printer prompt

Quote (Me)

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:

Quote:

With AutoHotkey installed, there are several ways to run a script:
  • Double-click a script file (or shortcut to a script file in Explorer.
  • Call AutoHotkey.exe on the command line and pass the script's filename as a command-line parameter.
  • After creating the default script, launch AutoHotkey via the shortcut in the Start menu to run it.
  • 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.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Embed printer prompt on form or centre the printer prompt

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

RE: Embed printer prompt on form or centre the printer prompt

(OP)
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

RE: Embed printer prompt on form or centre the printer prompt

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close