Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing Registry (Printer)
Message
From
15/09/1999 13:27:53
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Title:
Changing Registry (Printer)
Miscellaneous
Thread ID:
00265090
Message ID:
00265090
Views:
63
Greetings,

I have an application in VFP 6.0 that gets a list of all the printers from the registry. This uses the Registry.Vcx that ships with VFP 6.0. I then present all the printers in a list box for the user to select. After the user selects the desired printer, I then write the selection back to the registry and also write the selection to the device key in the win.ini file (About the 4th line down).

When I do this, MS Mail encounters a problem. It says there is a printer problem. When I check the registry and the win.ini files, everything has been changed as the user selected. If I go into "Start", "Settings", "Printers" and select any printer and set it to default, then the MS Mail works OK.

I was able to trace the MS Mail error back to the changing of the Win.ini file. If I don't do this, MS Mail works fine, but it wants to send the printout to the old default printer, not the printer changed via the application.

Below is the code for the Click event of the command button to write to the registry and win.ini files
I have also included the information in my Bigy.h file which contains all the registry integer settings.

I really need to be able to let the user change the default printer through the application. Am I missing something?

Thanks in advance,

Scott

********Click Event of Command Button After List Selection
**--Now we need to get the Printer Driver and the Port so we can set the win.ini file accordingly
#include bigy.h

cValue = thisform.list1.value

cPrintDirectory = "System\CurrentControlSet\Control\Print\Printers\" + cValue

cDrvValue = ""

**--Get the Printer Driver for the Selected Printer
if os() <> "Windows NT"
nVal = oReg.GetRegKey("Printer Driver",@cDrvValue, cPrintDirectory, HKEY_LOCAL_MACHINE)
if nVal <> 0
=messagebox("Failed To Read The Registry To Retrieve Printer Driver", 48, "Error")
endif
endif

cPort = ""
**--Get the Printer Port for the Selected Printer
if os() <> "Windows NT"
nVal = oReg.GetRegKey("Port",@cPort, cPrintDirectory, HKEY_LOCAL_MACHINE)
else
nVal = oReg.GetRegKey(cValue,@cPort, "Software\Microsoft\Windows NT\CurrentVersion\Devices", HKEY_CURRENT_USER)
endif
if nVal <> 0
=messagebox("Failed To Read The Registry To Retrieve Printer Port", 48, "Error")
endif

**--Set the New Dafault Printer
if os() = "Windows NT"
cNewValue = cValue + "," + cPort
nVal = oReg.SetRegKey("Device",cNewValue, "Software\Microsoft\Windows NT\CurrentVersion\Windows", HKEY_CURRENT_USER)
else
nVal = oReg.SetRegKey("DEFAULT",cValue, "System\CurrentControlSet\Control\Print\Printers", HKEY_CURRENT_CONFIG)
endif

if nVal <> 0
=messagebox("Failed To Set The Registry To The Selected Printer", 48, "Error")
endif


if os() <> "Windows NT"
cNewDefaultPrinter = cValue + "," + cDrvValue + "," + cPort

DECLARE SHORT WriteProfileString IN Win32API STRING cSection, STRING cEntry, STRING cString
DECLARE INTEGER SendMessageTimeout IN Win32API integer, integer, integer, integer, integer, integer, integer

**--Write the new default printer to the win.ini file.
nWrite = WriteProfileString("Windows", "device", cNewDefaultPrinter)

if nWrite <> 1
=messagebox("Error Changing Default Printer.", 48, "Error")
endif
**--Set the printer to the selected printer in all open applications
lb_success = SendMessageTimeout(HWND_BROADCAST,WM_WININICHANGE,0,0,SMTO_NORMAL,1000,0)
endif

thisform.release


**************BIGY.H

*-- (c) Big Y Foods, Inc. 1998
*-- Scott Kramer

*-- BIGY.H
*-- Include this file where needed for localization
*-- purposes

*-- Application Information

#DEFINE COPY_RIGHT_INFO "Copyright @ 1998 Big Y Foods, Inc."
#DEFINE LIC_USER "PC RESOURCE COORDINATOR"
#DEFINE LIC_COMPANY "Big Y Foods, Inc."

* This works in Win95

* Operating System codes
#DEFINE OS_W32S 1
#DEFINE OS_NT 2
#DEFINE OS_WIN95 3
#DEFINE OS_MAC 4
#DEFINE OS_DOS 5
#DEFINE OS_UNIX 6

* DLL Paths for various operating systems
#DEFINE DLLPATH_32S "\SYSTEM\" &&used for ODBC only
#DEFINE DLLPATH_NT "\SYSTEM32\"
#DEFINE DLLPATH_WIN95 "\SYSTEM\"

* DLL files used to read INI files
#DEFINE DLL_KERNEL_W32S "W32SCOMB.DLL"
#DEFINE DLL_KERNEL_NT "KERNEL32.DLL"
#DEFINE DLL_KERNEL_WIN95 "KERNEL32.DLL"

* DLL files used to read registry
#DEFINE DLL_ADVAPI_W32S "W32SCOMB.DLL"
#DEFINE DLL_ADVAPI_NT "ADVAPI32.DLL"
#DEFINE DLL_ADVAPI_WIN95 "ADVAPI32.DLL"

* DLL files used to read ODBC info
#DEFINE DLL_ODBC_W32S "ODBC32.DLL"
#DEFINE DLL_ODBC_NT "ODBC32.DLL"
#DEFINE DLL_ODBC_WIN95 "ODBC32.DLL"

* Registry roots
#DEFINE HKEY_CLASSES_ROOT -2147483648 && BITSET(0,31)
#DEFINE HKEY_CURRENT_USER -2147483647 && BITSET(0,31)+1
#DEFINE HKEY_LOCAL_MACHINE -2147483646 && BITSET(0,31)+2
#DEFINE HKEY_USERS -2147483645 && BITSET(0,31)+3
#DEFINE HKEY_CURRENT_CONFIG -2147483643 && BITSET(0,31)+5

* Misc
#DEFINE APP_PATH_KEY "\Shell\Open\Command"
#DEFINE OLE_PATH_KEY "\Protocol\StdFileEditing\Server"
#DEFINE VFP_OPTIONS_KEY "Software\Microsoft\VisualFoxPro\6.0\Options"
#DEFINE VFP_OPT32S_KEY "VisualFoxPro\6.0\Options"
#DEFINE CURVER_KEY "\CurVer"
#DEFINE ODBC_DATA_KEY "Software\ODBC\ODBC.INI\"
#DEFINE ODBC_DRVRS_KEY "Software\ODBC\ODBCINST.INI\"
#DEFINE SQL_FETCH_NEXT 1
#DEFINE SQL_NO_DATA 100
#DEFINE HWND_BROADCAST 65535
#DEFINE WM_WININICHANGE 26
#DEFINE SMTO_NORMAL 0


* Error Codes
#DEFINE ERROR_SUCCESS 0 && OK
#DEFINE ERROR_EOF 259 && no more entries in key

* Note these next error codes are specific to this Class, not DLL
#DEFINE ERROR_NOAPIFILE -101 && DLL file to check registry not found
#DEFINE ERROR_KEYNOREG -102 && key not registered
#DEFINE ERROR_BADPARM -103 && bad parameter passed
#DEFINE ERROR_NOENTRY -104 && entry not found
#DEFINE ERROR_BADKEY -105 && bad key passed
#DEFINE ERROR_NONSTR_DATA -106 && data type for value is not a data string
#DEFINE ERROR_BADPLAT -107 && platform not supported
#DEFINE ERROR_NOINIFILE -108 && DLL file to check INI not found
#DEFINE ERROR_NOINIENTRY -109 && No entry in INI file
#DEFINE ERROR_FAILINI -110 && failed to get INI entry
#DEFINE ERROR_NOPLAT -111 && call not supported on this platform
#DEFINE ERROR_NOODBCFILE -112 && DLL file to check ODBC not found
#DEFINE ERROR_ODBCFAIL -113 && failed to get ODBC environment

* Data types for keys
#DEFINE REG_SZ 1 && Data string
#DEFINE REG_BINARY 3 && Binary data in any form.
#DEFINE REG_DWORD 4 && A 32-bit number.

* Data types labels
#DEFINE REG_BINARY_LOC "*Binary*" && Binary data in any form.
#DEFINE REG_DWORD_LOC "*Dword*" && A 32-bit number.
#DEFINE REG_UNKNOWN_LOC "*Unknown type*" && unknown type

* FoxPro ODBC drivers
#DEFINE FOXODBC_25 "FoxPro Files (*.dbf)"
#DEFINE FOXODBC_26 "Microsoft FoxPro Driver (*.dbf)"
#DEFINE FOXODBC_30 "Microsoft Visual FoxPro Driver"
Next
Reply
Map
View

Click here to load this message in the networking platform