Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Get Windows Default Printer

Author
Message
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 28th Aug 2012 17:00
I am using DarkInk for my printing commands, and I want to be able to let the user choose a printer. Using the get printer count() command, I can list the printers and allow the user to change it using my own interface, which is great.

However, DarkInk has one command missing, which is to determine which printer is the current windows default. So I thought I would just write a DLL call that goes and finds out. Now, I am horrible with DLL calls to windows, escpecially if they need to return a string, but here is what I have so far. Unfortunately, I got to the point where I need to specify which DLL to load and use, and now I am stuck. The MSDN page lists a ".lib"....

http://msdn.microsoft.com/en-us/library/windows/desktop/dd144876(v=vs.85).aspx

Any suggestions?

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Aug 2012 03:18 Edited at: 29th Aug 2012 03:24
the Default Printer works for me using lprint from the sample code... so I can not see what your predicament is here...

EDIT

Get Printer Name()

Does this not work for you?

GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 29th Aug 2012 03:23
It is hard to explain why I need it...

In my program, I have two options: Print, and Print to PDF. The second option will loop through the printers until it finds one with PDF in the name, and print to that printer. The first option will just send to the default printer.

When you select the PDF route, I use "set printer index()" to set it to the PDF printer and print. But then when they select "Print", I want it to go to the default printer. Since I just changed it to the PDF printer, I need to know which printer is the windows default so I can change DarkInk to go back to that one.

Essentially, once you print to a printer other than the default, you have know way of knowing which printers was the default to begin with, and therefore cannot change it back.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Aug 2012 03:27
oh I see... but not all pcs have PDF printing by standard... so I guess you remedied this by disabling the option...

I suppose I should await your updates then

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 29th Aug 2012 03:33
The MSDN forums will give you the best start searching for the Printer classes. I've found these: (I've never used a printing device before though, not needed it)

http://support.microsoft.com/kb/246772
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx

I'm also aware that using a Device Context or something similar to send data to a printer too.

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 30th Aug 2012 00:24
I don't have DarkInk but had a quick gander at the help files which still exist on the author's website.

When you start up program can you not use Get Printer Name() as suggested by MrValentine to store name of default printer.

Then use Get Printer Count(), Set Printer Index and Get Printer Name() to loop through all the printers and retrieve name of each printer, then just test each name against the saved name and that gives you the index number you need to use to reset back to default printer.

Boo!
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 30th Aug 2012 00:28 Edited at: 30th Aug 2012 00:29
You and I think alike. But, unfortunately, I have already tried that and it did not work. If you use get printer name() or get printer index() at the start of the program, they always return the information for the first printer listed, i.e. index 0. On my machine, the default printer is actually the 4th listed since it lists them alphabetically. Running get printer name() as the first line of the project returns the name of the printer down the hall that we use for dot matrix reports. I can assure you, it is not my default, but since its name is "\\server\inv001", it comes up first alphabetically.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 30th Aug 2012 00:30
make that three of us then, I stayed quiet about that because I found I got the same result...

spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 30th Aug 2012 11:47
Just knocked this up but will only work on 2000, XP, Vista and 7. Win 98 needs a more complicated bit of code but hopefully you're not bothered about that.



Boo!
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 30th Aug 2012 16:31
Quote: "Win 98 needs a more complicated bit of code but hopefully you're not bothered about that."


I am not worried at all about Windows 98. Also, the code seems to work perfectly.

Thanks!
sladeiw
17
Years of Service
User Offline
Joined: 16th May 2009
Location: UK
Posted: 6th Sep 2012 17:48 Edited at: 6th Sep 2012 18:33
I stopped using DarkInk a year or so ago because it gave me various problems when printing large images, or when used continuously for a long period of time. You get nice purple error boxes that your program cannot trap or handle. I wrote a set of printer functions from scratch, the function I use to get the default printer is below if it's any use.



Requires Matrix1utils.

Edit: Speeling
GIDustin
18
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 27th Nov 2012 18:41
Sorry to revive a dead thread.

@sladeiw: If you stopped using DarkInk, what do you use now?

Login to post a reply

Server time is: 2026-07-08 14:11:38
Your offset time is: 2026-07-08 14:11:38