Solved

How do you set the default printer programatically?

Posted on 1998-08-11
6
176 Views
Last Modified: 2013-11-20
I want to set the default printer from my Win32 program.
The program should primarily run under Windows NT, but
it would be nice if it'd work under Windows 95/98 too.

   /Dan
0
Comment
Question by:danandersson
  • 2
  • 2
  • 2
6 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1320537
How To Get and Set the Default Printer in Windows
http://support.microsoft.com/support/kb/articles/q135/3/87.asp

How to Set the Default Printer Programmatically in Windows 95
http://support.microsoft.com/support/kb/articles/q140/5/60.asp

0
 

Author Comment

by:danandersson
ID: 1320538
The primary platform I want to set the default printer is Windows NT. The given ansver from chensu did cover only 16-bit
Windows and Windows 95.
0
 
LVL 4

Expert Comment

by:agreen
ID: 1320539
In ALL versions of Windows, the appropriate way to get the default printer is to use GetProfileString, and the appropriate way to set the default printer is to use WriteProfileString.

The "HOWTO: Get and Set the Default Printer in Windows" applies to Win32 API which included with both NT and Win95.

So the chensu's answer is right.

I've already answered such question.
See http://www.experts-exchange.com\Q.10069298
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 4

Expert Comment

by:agreen
ID: 1320540
// To set the default printer for Windows NT use:
/* Note printer driver is usually WINSPOOL under Windows NT */

WriteProfileString("windows", "device", "My Printer, WINSPOOL,   "lpt1:");

SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0L, 0L,
   SMTO_NORMAL, 1000, NULL);
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1320541
The KB article does apply to Windows NT. Read it carefully please.

"This is the preferred method of changing the printer if the code is to be platform independent; this method will work on Windows 3.1, Windows 95 and Windows NT."

Thank you and also agreen.
0
 

Author Comment

by:danandersson
ID: 1320542
Thank you! Now I'm confident that this solves my problems :-)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Separate into files by filename 12 82
how to monitor remote shell execution on linux 9 100
Change to event 1 112
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question