HOWTO: Change the Default Printer with FoxPro 2.x and Windows 95ID: Q186392
|
Microsoft Knowledge Base article
Q103645 "How to Change the Default Windows Printer from FoxPro,"describes how to programmatically change the default windows printer. However, the article correctly states that the procedures will not work for FoxPro 2.6a in Windows 95. This article demonstrates a method to use the sample code in article Q103645.
Save the sample code in Q103645 to a program file named Pchg.prg. You use the Pchg.prg file as a procedure file in the code example that follows. The following sample code demonstrates how to change the default printer and print test print jobs after each printer change:
* #DEFINES used to match WinSDK message definitions
#DEFINE HWND_BROADCAST 65535
#DEFINE WM_WININICHANGE 26
SET LIBRARY TO HOME()+"FoxTools.fll" ADDITIVE
*-- Init the PostMessage function so we can force Fox to
*-- reread the WIN.INI
PostMsg = regfn('POSTMESSAGE', "IICC", "I")
SET PROCEDURE TO pchg
DIMENSION laPrinters(1,1) && Array that holds the printer information.
liNumber = 0 && The number of printers available.
lcCurrentPrint = "" && The current default printer.
*-- Fill the variables with the printer info
DO GETPRINT WITH laPrinters, liNumber, lcCurrentPrint
*-- First, print to one printer...
liNewPrinter = 1 && Select the first printer in the list
DO putprint WITH laPrinters, liNumber, liNewPrinter
*-- Now make the PostMessage call to ensure that the
*-- [Windows] section of WIN.INI is re-read by all running apps.
=callfn(PostMsg, HWND_BROADCAST, WM_WININICHANGE, 0, "Windows")
*-- CLEAR PROGRAM has to be here or it won't work.
CLEAR PROGRAM
*-- Print something to test
DISPLAY STATUS TO PRINTER
*-- Now print to a different printer...
liNewPrinter = 2 && Select the second printer in the list
DO putprint WITH laPrinters, liNumber, liNewPrinter
*-- Now make the PostMessage call to ensure that the
*-- [Windows] section of WIN.INI is re-read by all running apps.
=callfn(PostMsg, HWND_BROADCAST, WM_WININICHANGE, 0, "Windows")
SET TALK OFF
*-- Do this again so it works.
CLEAR PROGRAM
*-- Print something to test
DISPLAY STATUS TO PRINTER
For additional information, please see the following article in the Microsoft Knowledge Base:
Q103645 How to Change the Default Windows Printer from FoxPro(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Mike A. Stewart, Microsoft Corporation
Additional query words: kbDSupport kbDSE kbVFp vfoxwin
Keywords :
Version : WINDOWS:2.5,2.5a,2.5b,2.6,2.6a
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: August 3, 1999