Solved

How o change chooser setting using program?

Posted on 2000-02-17
1
239 Views
Last Modified: 2013-12-26
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
Comment
Question by:TeLieh
1 Comment
 
LVL 4

Accepted Solution

by:
Alex Curylo earned 200 total points
ID: 2536141
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 97
maven archtype selection in eclipse 1 53
matchUp  challenge 6 52
Sed question 2 68
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now