Solved

How o change chooser setting using program?

Posted on 2000-02-17
1
247 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

730 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