Solved

How do you set the default printer programatically?

Posted on 1998-08-11
6
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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