Jump to content

Print Dialog/Default Printer


Recommended Posts

I would like to send my reports to a printer selected through the Windows print setup dialog. In my search, I found "Set Default Printer.vi". The problem I have with this VI (besides the fact that it is locked) is that it does not return an error or any other notification if the "Cancel" button is selected on the dialog.

Anybody know who wrote this VI or have a better suggestion for how to do this?

Alan

Link to comment
I would like to send my reports to a printer selected through the Windows print setup dialog. In my search, I found "Set Default Printer.vi". The problem I have with this VI (besides the fact that it is locked) is that it does not return an error or any other notification if the "Cancel" button is selected on the dialog.

Anybody know who wrote this VI or have a better suggestion for how to do this?

This is my hacked together variant of the Set Default Printer.vi. I did some empirical research activity (in earlier days this was called reverse engineering and a hex editor and some disassembly can help wonders here) and this is to the best of my knowledge what the NI VI does, with some extra code to fix the behavior of that function with invalid inputs. BTW: There seems no way to get the cancel status at all.

(Basically calling this function with an empty string and FALSE for show dialog, sets the internal LabVIEW printer name apparently to an invalid setting and after that any print activity will abort with a printer dialog error (34) and the only way to get printing back to work is to restart LabVIEW or the applciation). You can produce the same error with the Application property in LabVIEW >= 7.x Printer.Default Printer).

I posted a bug report about this but never received anything besides the automatic acknowledgment until now.

Rolf Kalbermatter

Download File:post-349-1136843760.vi

Link to comment
This is my hacked together variant of the Set Default Printer.vi. I did some empirical research activity (in earlier days this was called reverse engineering and a hex editor and some disassembly can help wonders here) and this is to the best of my knowledge what the NI VI does, with some extra code to fix the behavior of that function with invalid inputs.

:nono: That's illeagal here in the land of freedom.

There seems no way to get the cancel status at all.

:( Unfortunately, that's the functionality I was looking for. Reports showing up at the printer after selecting cancel is hard to explain to users. I have a very crude and not 100% work around. I check the mouse position immediately after the call. If the user has not moved the window, I know if cancel has been pushed. Of course, if the window has been moved all bets are off. Because the Print Setup window is a Dialog, I don't know anyway of tracking its position.

Alan

Link to comment
i had a similar problem some time ago and my solution was, to programm the select printer dialog myself. You can get the list of installed printers like this:

post-885-1136969291.jpg?width=400

I was considering this approach as well. But the problem is that it does only allow to select the printer itself and not any of the print properties for the particular printer such as paper selection etc. I'll have to look into the possiblities.

Rolf Kalbermatter

:nono: That's illeagal here in the land of freedom.

Well, at least until now, not so here :P

Rolf Kalbermatter

Link to comment
I was considering this approach as well. But the problem is that it does only allow to select the printer itself and not any of the print properties for the particular printer such as paper selection etc. I'll have to look into the possiblities.

Rolf Kalbermatter

Well, at least until now, not so here :P

Rolf Kalbermatter

what abaut this example from ni site?

http://sine.ni.com/apps/we/niepd_web_displ...034080020E74861 :lightbulb:

Download File:post-2756-1137065441.vi

Link to comment

The problem with that VI is that it prints the panel as documentation, that is with a header. To create reports for instance it is usually not desirable to have any other information on the printout than what is on the actual panel that is to be printed.

This printout of panels without any additional information works very fine if you set the VI properties to "print when completed". But you have to create your own custom print dialog because the one discussed earlier will not indicate a user cancel.

Rolf Kalbermatter

Link to comment
I was considering this approach as well. But the problem is that it does only allow to select the printer itself and not any of the print properties for the particular printer such as paper selection etc. I'll have to look into the possiblities.

Rolf Kalbermatter

i have not checked this, yet, but i guess, you can open the properties via ActiveX, when you have the printer name. Ok, you need an extra button in your dialog, but i think this can work?!

Link to comment
The problem with that VI is that it prints the panel as documentation, that is with a header. To create reports for instance it is usually not desirable to have any other information on the printout than what is on the actual panel that is to be printed.

This printout of panels without any additional information works very fine if you set the VI properties to "print when completed". But you have to create your own custom print dialog because the one discussed earlier will not indicate a user cancel.

Rolf Kalbermatter

This brings up an interesting option. I'm not using VI panels to create reports. I'm using MS-Excel with the report generation toolkit. Could I call the print dialog through Excel? I've done some digging, but I haven't found anything yet.

The interesting thing about the VI that Yonatan suggested is that it returns an error on Cancel! I feel like I'm working with VB again (many solutions that almost work).

Alan

Link to comment
  • 2 months later...
...... But one drawback is that LabVIEW and only that is used as special keyword in the Call Library Node to mean the current LabVIEW instance which for build applications will be not labview.exe.

Rolf Kalbermatter

Didier and Rolf,

many thanx for your replies. :worship:

Setting the CLF path to ...\LabVIEW.exe and the function name to SetDefaultPrinter works in development environment of LV 5.1, but does not work in a built application as Rolf stated already. Behind the magic of SetDefaultPrinter CLF there should be a winapi call? As my coworker needs this functionalty in this really old LV version :wacko: he will solve it.

Never the less any more hints appreciated

Manfred

Download File:post-831-1144670212.vi

Link to comment
Didier and Rolf,

many thanx for your replies. :worship:

Setting the CLF path to ...\LabVIEW.exe and the function name to SetDefaultPrinter works in development environment of LV 5.1, but does not work in a built application as Rolf stated already. Behind the magic of SetDefaultPrinter CLF there should be a winapi call? As my coworker needs this functionalty in this really old LV version :wacko: he will solve it.

Never the less any more hints appreciated

Manfred

Download File:post-831-1144670212.vi

Just try "LabVIEW" as library name. It might work in the built application but there is no guarantee. The special LabVIEW library name was introduced in probably around 5.0. Not sure if LabVIEW was already using it as a place holder for the current instance or if that was only added later on.

There is probably quite a lot more than a single Windows API call behind SetDefaultPrinter. Printing in LabVIEW is somewhat involved and the original idea was to hide as much as possible of the printer setup and configuration from the user. This makes it now a little difficult to provide full print control.

And the reason this name was changed in later versions is probably because it had a name clash on one of the platforms LabVIEW is compiled for.

Rolf Kalbermatter

Link to comment
  • 6 months later...

I'm working with LabView 6.1 and have several vi's that display data I've taken. I need to be able to print to differnet printers. Using some of the above code I can change the defalt printer. Unfortunatly that doesn't change the printer under the File -> Page Setup -> Printer Setup .... No matter what printer I select it changes the default printer highlight in the windows printers and faxes window but the Labview print panel.vi always prints to the same printer unles I manually go in to the File -> Page Setup -> Printer Setup .... and change it there. What am I missing?

Thanx,

Norm

Link to comment
  • 1 year later...
  • 4 weeks later...

I'm having the same issue. I want to change the printer to a pdf driver (to save the front panel as a .pdf) then back to the default printer to print the results as a hard copy immediately after. This works only if I change the printer, close labview and restart my application then it will recognize the change? I think this may be a bug, because I see in 8.5 this is a bug fix.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.