?
Solved

setting default printer form VC++

Posted on 1998-12-01
1
Medium Priority
?
258 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
[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
1 Comment
 
LVL 11

Accepted Solution

by:
alexo earned 400 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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 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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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