Hi !
First I want to thank everyone who answered my last post...
This time I have a (at last for me) completely new problem: how do I
configure a printer driver from the outside?
Or to be more specifically: I want to change the windows default
printer on-the-fly. That's not to hard, simply change the
device=... in the [windows] section of the win.ini and send the
appropiate WM_WININICHANGE-message (BTW: do I have to send the message
for "devices" *and* "windows" as control.exe does it ?). But how do I tell
a postscript-driver to write his output to a specific file? Easy (I
thought) simply change the "EpsFile=..." line in the right printer
section (e.g. [Apple LaserWriter Plus,FILE]), and send the
WM_WININICHANGE-message again... That sounds good, but is not
sufficient, control.exe sends a WM_DEVMODECHANGE-message with lParam
set to the driver's name (e.g. "Apple LaserWriter Plus"). OK, I wrote
this into my prog.
This is a small piece of it (VString is a string class of the toolkit
we use in out lab.):
class OSUtil {
static const char* win_section;
static const char* win_device;
static const char* prt_section;
static const char* dev_section;
static const char* ausgabe_datei;
void getPortAndDriver(const char* prtName,
VString& port, VString& driver);
public:
void setPrinter(const char* prtName);
void setPrintOutputFile(const char* printer, const char* name);
const char*Quote:};
OSUtil::win_section="Windows";
const char*
OSUtil::win_device="device";
const char*
OSUtil::prt_section="PrinterPorts";
const char*
OSUtil::dev_section="devices";
const char*
OSUtil::ausgabe_datei="EpsFile";
void
OSUtil::getPortAndDriver(const char* prtName, VString& port, VString& driver)
{
char buf1[200];
char* d;
char* p;
VString def("??");
GetProfileString(prt_section, prtName, def.gets(), buf1, sizeof(buf1));
d=strtok(buf1,",");
p=strtok(NULL,",");
p=strtok(p,":");
driver=d;
port=p;
port.toUpper();
#ifdef DEBUG
errout.message("OSUtil::getPortAndDriver:");
errout.message(" printer: \"%s\"", prtName);
errout.message(" driver \"%s\", port: \"%s\"", driver.gets(), port.gets());
#endif
#endifQuote:}
void
OSUtil::setPrinter(const char* prtName)
{
VString driver;
VString port;
VString towrite((char*)prtName);
getPortAndDriver(prtName,port,driver);
towrite+=",";
towrite+=driver;
towrite+=",";
towrite+=port;
towrite+=":";
#ifdef DEBUG
boolean ret;
errout.message("OSUtil::setPrinter(\"%s\")",prtName);
ret=
#endif
WriteProfileString(win_section,win_device,towrite);
#ifdef DEBUG
errout.message(" WriteProfileString(\"%s\", \"%s\", \"%s\")==%d",
win_section, win_device, towrite.gets(), ret);
#endif
SendMessage(0xFFFF,WM_WININICHANGE,0,(DWORD)dev_section);
SendMessage(0xFFFF,WM_WININICHANGE,0,(DWORD)win_section);
voidQuote:}
OSUtil::setPrintOutputFile(const char* printer, const char* name)
{
VString driver;
VString port;
VString towrite((char*)printer);
getPortAndDriver(printer,port,driver);
towrite+=",";
towrite+=port;
#ifdef DEBUG
boolean ret;
errout.message("OSUtil::setPrintOutputFile(\"%s\", \"%s\")",printer, name);
ret=
#endif
WriteProfileString(towrite.gets(),ausgabe_datei,name);
#ifdef DEBUG
errout.message(" WriteProfileString(\"%s\", \"%s\", \"%s\")==%d",
towrite.gets(), ausgabe_datei, name, ret);
#endif
SendMessage(0xFFFF,WM_DEVMODECHANGE,0,(DWORD)printer);
SendMessage(0xFFFF,WM_WININICHANGE,0,(DWORD)dev_section);
SendMessage(0xFFFF,WM_WININICHANGE,0,(DWORD)win_section);
SendMessage(0xFFFF,WM_WININICHANGE,0,(DWORD)towrite.gets());
But despite all hopes this does *not* work :(((Quote:}
Has anybody any suggestions to this? I'm getting frustrated because
control.exe is able to do things that I can't...
Any help is appreciated !
--
-- Jens --
____________________________________________
Real Programmers always confuse Christmas
and Halloween because
OCT 31 == DEC 25 !!
-- Andrew Rutherford
____________________________________________