Solved

setting default printer form VC++

Posted on 1998-12-01
1
223 Views
Last Modified: 2013-12-03
Does anyone know how i can set a printer to be the default windows printer from within a visual C++ program.

thanx in advance,

peter@icpc.ie
0
Comment
Question by:pbranagan
1 Comment
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
ID: 1416556
Check  http://support.microsoft.com/support/kb/articles/q135/3/87.asp

Quoting:

// This code uses a sample profile string of "My Printer,HPPCL5MS,lpt1:"

// To get the default printer for Windows 3.1, Windows 3.11, Windows 95, and Windows NT use:
GetProfileString("windows", "device", ",,,", buffer, sizeof(buffer));
 
// To set the default printer for Windows 3.1 and Windows 3.11 use:
WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:");
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0L);
 
// To set the default printer for Windows 95 use:
WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:");
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0L,
(LPARAM)(LPCTSTR)"windows");
 
// 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:");
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0L, 0L);

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now