Solved

How o change chooser setting using program?

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 84
How to know only "File created" with EventLog 3 29
format the code in java 6 73
unix example issues 18 49
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

12 Experts available now in Live!

Get 1:1 Help Now