|
Post by heindevrein on Oct 4, 2014 20:47:10 GMT 1
(1) The command "prindc_d% = Printer.hDC" should give a positive number, indicating the
default printer. It is used by me preceding the command "Output = Printer", and also starting
manupilation of printer fonts or starting a printing job. The number prindc_d% is also
used in the command "Dlg Print Me, PD_PRINTSETUP, prindc_d%".
This works fine, except, as far as I know, for the printer HP Photosmart 5520 under
Windows 7.
(2) The command "SetPrinterByName p$" should set p$ as the default printer, to be used in
a printing job. The names of the available printers can be obtained using the commands
App.PrinterCount and App.PrinterName().
However, even if p$ is the name of an available printer (as it should be), the outcome of
the command is the Error Message "Printer Name invalid". So the command never seems to
work.
Advice as to how to mend or circumvent these two failures in GFABASIC32 will be
appreciated. HdV.
|
|
|
Post by dragonjim on Oct 16, 2014 16:54:52 GMT 1
Hi,
Sorry for the delay in replying...there is so little traffic on this site these days that I sometimes forget to check it!
To try and answer your queries:
1. I not sure if I fully understand what you are trying to do here: Dlg Print Me, PD_PRINTSETUP, hDC creates a Print Dialog box tied to Me (or any active or inactive form if you prefer) in which you can select which Printer you wish to print through and the hDC of that printer is returned in hDC (or printd_c% as you refer to it). Hence, to call Dlg Print, you would use code similar to that below:
OpenW 1 Local h As Handle Dlg Print Win_1, 4, h
In the above code, the Print Dialog window is called and the hDC of the selected printer is returned in h. Using h, the next two lines then set up the printer:
SetPrinterHDC h Output = Printer
Hence, preloading h (or printd_c%) with Printer.hDC will have no effect as it is used as a return value rather than an outgoing parameter.
As for the hDC of the default printer this is already pre-loaded into the Printer object and can be returned with Print Printer.hDC; if this returns a non-positive number (or zero) it is usually because there is no default printer registered on your system.
2. You are absolutely correct in assuming that SetPrinterByName p$ uses the printer name to set the current printer and I can't see why you are getting this error message UNLESS you are sending App.PrinterName(n) where n is greater than the value of App.PrinterCount (and therefore a null string) which would cause this error.
Try the following example to see if you can reproduce the error and, if you can, post your results here:
Local Int32 n For n = 0 To App.PrinterCount Print App.PrinterName(n) & Iif(n = 0, " (Default)", "") SetPrinterByName App.PrinterName(n) Next n
I hope some of this has proved helpful.
|
|
|
Post by heindevrein on Oct 17, 2014 20:43:32 GMT 1
Hello, As to problem (1), the single command "prindc_d% = Printer.hDC" should work. As a matter of fact, it seems to work now. Nevertheless, your suggestion Local h As Handle
Dlg Print Win_1, 4, h might be useful in case the problem arises again.
As to problem (2), it is still there. Even the simple command SetPrinterByName App.PrinterName(1) yields the error message "Printer Name invalid". The value of "App.PrinterCount" was 2.
|
|
|
Post by dragonjim on Oct 17, 2014 22:30:29 GMT 1
Hi again,
I agree that prindc_d% = Printer.hDC should work to get the hDC of the default printer - the fact it doesn't could well be linked to the fact that you don't seem to be able to get SetPrinterByName p$ to work either.
Is there any chance you could run the program below, copy the output in the debug window and paste it into a reply?
Local Int32 n Debug.Show For n = 1 To App.PrinterCount Debug App.PrinterName(n) Next n
This may give me a better idea of what is happening.
|
|
|
Post by heindevrein on Oct 18, 2014 20:28:39 GMT 1
I did run the suggested procedure. It gave the right answers: HP Deskjet F4200 series
Brother HL-1430 series But adding for instance SetPrinterByName App.PrinterName(2) or, after having defined the string variable p$, p$ = App.PrinterName(2) SetPrinterByName p$ the usual error message appeared.
|
|
|
Post by dragonjim on Oct 18, 2014 23:55:00 GMT 1
Interesting. What version of Windows are you using? It's only that I would have expected to see the Microsoft XPS Document Writer in the list somewhere on anything Windows Vista onwards. To the best of my knowledge, the Printer object is obtained through Windows APIs from the Printer information stored in Windows itself; hence, if the printer drivers and settings in Windows are OK, they should be OK in GFA. Therefore, the most probable explanation for it not working in your case could be: - That the drivers and/or settings for one or both of your printers are either corrupted, didn't install properly or are not up to date.
- That one or both of your printers is wireless and there is an error in the connection.
- Similarly, that one or both of your printers is connected by USB or Parallel and there is a fault in the cable (I've seen that a few times!).
- That there is a conflict between the drivers of your printers.
- That another application or some software that is taking control of printer management and not allowing the Windows APIs access to the printers.
I'm not saying that it is definitely one of the above, but they are more likely explanations than a failure within GFA (although that is not unknown).
If you're interested in my advice, I would disconnect your printers and then plug them in one at a time and see if they work properly independently; try swapping cables around (dodgy cables are not always immediately obvious); but first, I would ensure that you have the most up to date drivers installed for both printers - if you are using Windows 8 or 8.1, this is a particular problem, with some manufacturers originally producing generic drivers which didn't work after 8.1 or 8.1 SP1 was installed.
On my end, I'll ask around and see if I can find anyone with any other helpful solutions.
I hope one of the above solutions solves the problem. If so - or if not - let me know.
|
|