[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

How o change chooser setting using program?

Usually I set current printer, modem,apple talk in the chooser. Can I change these setting in my program using the toolsbox or other technical.
thanks.

Best regards
Te-Lieh
0
TeLieh
Asked:
TeLieh
1 Solution
 
Alex CuryloCommented:
Heh. I just posted the answer to the printer part in that OTHER question of yours -- I was away the last couple of days, sorry.

Current modem and AppleTalk settings are best handled in a compatible fashion using the "MoreNetworkSetup" sample code
from Apple, which you can get at

http://developer.apple.com/samplecode/Sample_Code/Networking/MoreNetworkSetup.htm

As for current printer, there is no official way to do that, here I'm pasting in my suggestions from the other thread again :)


Now, as for setting the printer driver, I haven't done it myself, but here is how I GET the name of the currently-selected printer. I suppose a daring person could try to modify it to SET the name, as well. Here's how it works:

1) Get the name of the currently-selected printer driver by calling GetString on resource ID -8192. This string resource resides in the System and tracks, well, the current printer driver. I should warn you that Apple has specifically told me that this is undocumented and not guaranteed to be forever cool.

2) Get a dirID to the current Extensions folder using FindFolder and the following contants: kOnSystemDisk,  kExtensionFolderType, kDontCreateFolder.

3) Using the file name (same as driver name) from step 1 and the dirID from step 2, open the printer driver using FSpOpenResFile.

4) Get resource type 'PAPA', ID -8192, from the newly-opened resource file. The first pascal string in the PAPA resource appears to always contain the currently-selected printer's name.

Here is code posted on c.s.m.p which purports to do that, but which I disclaim all responsibility for if it doesn't work:

***************

Here's an snippet from the extension I wrote a while ago.It used to work
with LW 8.0 and sys 7.1 I took out err checking for brevity.  Use it at your
own risk :-)

void DoChangeCurPrinter()
{
    StringHandle curDriver;
    Handle curPrinter;
    short resRef;
    
    curDriver =   GetString(-8192);
  // get the  currently active printer driver - LaserWriter ,
ImageWriter,etc.
    HLock(curDriver);
    // Open LaserWriter res file. This call moves memory, so lock the handle
    resRef = OpenResFile(*curDriver);
    HUnlock(curDriver);
// get the name of current  printer selection in Chooser
// It' s stored in this resource of the LW
   curPrinter= GetResource('PAPA',-8192);
  // Assuming you got new printer name,zone and addr block
 //from the NBP lookup
  
   ChangePrinter(curPrinter,newPrinterName, newPrinterZone,     
                                           &newPrinterAddrBlock);
   CloseResFile( resRef)
}


void ChangePrinter(Handle curPrinter ,Str32 printerName,
                   Str32 newPrinterZone,AddrBlock* newPrinterAddr)   
{
  Ptr p;
  Str32 objType="\pLaserWriter";
  /*manually stick new name, type, zone & addr block*/
  
   HLock(curPrinter);
   p = *curPrinter;
   BlockMove(printerName,p,printerName[0]+1);
   p+=*p+1;
   
   BlockMove(objType,p,objType[0]+1);
   p+=*p+1;
   
   BlockMove(newPrinterZone,p,newPrinterZone[0]+1);
//if there's only 1 zone stick '*' in the zone field
     p+=*p+1;
   
   BlockMove(newPrinterAddrBlock,p,sizeof(long));//ptr to the addr block
   HUnlock(curPrinter);
   ChangedResource(curPrinter);
   WriteResource( curPrinter );
   ReleaseResource(curPrinter);
  
 
}

HTH, Andy


***********************
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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