Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

setting default printer form VC++

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
pbranagan
Asked:
pbranagan
1 Solution
 
alexoCommented:
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now