dave@utzoo.uucp (Dave Sherman) (02/13/90)
How does an application or INIT find out what name the user has entered as User Name in the Chooser? This doesn't appear to be documented anywhere. Thanks. David Sherman Toronto dave@lsuc.on.ca (lsuc is down for a few days) 416-889-7658
dorourke@polyslo.CalPoly.EDU (David M. O'Rourke) (02/13/90)
dave@utzoo.uucp (Dave Sherman) writes: >How does an application or INIT find out what name the user >has entered as User Name in the Chooser? This doesn't appear >to be documented anywhere. Here's some code that I use to do it: procedure GetChooserName(var theString : Str255); const ChooserNameID = -16096; var TempString : StringHandle; begin TempString := GetString(ChooserNameID); theString := TempString^^; end; {GetChooserName} >Thanks. Hope this helps. -- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|///////////////////////////////////////// David M. O'Rourke____________________|_____________dorourke@polyslo.calpoly.edu | Graduating in March of 1990, with a BS in Computer Science | |_That should make several people at Poly happy.______________________________|
minow@mountn.dec.com (Martin Minow) (02/14/90)
In article <1990Feb12.220022.19862@utzoo.uucp> dave@utzoo.uucp (Dave Sherman)
(Hi Dave) asks how to find the Chooser's username.
It's a system-defined string resource, try GetString(-16096) to get a handle.
Martin Minow
minow@thundr.enet.dec.com
alexis@panix.UUCP (Alexis Rosen) (02/16/90)
Ouch. David's example will work. Most of the time. Problem is, a file in the resource search path might have the same string. It shouldn't but it might. (This is particularly a problem if you're writing an XCMD, as I was.) And more to the point, what about deallocating that handle? The following is the code to an XCMD that does the trick, which I wrote about a million years ago... Implementation Procedure main (p: XCmdBlockPtr); Var saveResFile, nameLength: Integer; nameH: Handle; Procedure ShowErr (err: String); Var junk: integer; Begin ParamText(err, '', '', ''); junk := Alert(264, Nil) End; Begin If p^.paramCount <> 0 Then ShowErr('Error: The GetNodeName XFCN takes no arguments and returns the chooser node name.'); saveResFile := CurResFile; UseResFile(0); nameH := GetResource('STR ', -16096); If nameH <> Nil Then DetachResource(nameH); UseResFile(saveResFile); nameLength := SignedByte(nameH^^); Handle(p^.returnValue) := NewHandle(1 + nameLength); BlockMove(Pointer(Longint(nameH^) + 1), Pointer(p^.returnValue^), nameLength); p^.returnValue^^[nameLength + 1] := 0; DisposHandle(nameH) End; { Main } End. ShowErr does the obvious thing (and exits back to the caller). Now that I look at this, I can see that it's not perfect either- if the string's not there, it's nice enough not to Detach the resource, but then it derefs to get the string length. Stupid... On the other hand, it hasn't crashed yet. (Not surprising...) BTW, p is an XCMD parameter block, and p^.returnValue is the choosername. Nothing else in p^ matters. If you like C and don't like Pascal, I thing DTS released an equivalent routine in C a year ago or so. Check tech notes (?) --While we're talking about chooser stuff-- Why isn't there a programmatic interface to the chooser??? I can mess with imagwriter resources by hand (in a way that's guaranteed to break at some pont in the future), but there's absolutely NO WAY to do things with a third-party driver (how many look like Apple's internally?). It gets even worse with network things, like LaserWriters, netmodems, whatever. This is a deplorable situation and needs fixing ASAP. Sadly, it doesn't look like System 7 will address this... Too late to type straight, Alexis Rosen (too late for .sig, too)