richr@pogo.UUCP (06/13/86)
In article <419@batcomputer.TN.CORNELL.EDU> hsgj@batcomputer.TN.CORNELL.EDU (Dan Green) writes: >I would like to have the user enter a filename from my C program. >I have been looking at Requesters, but it appears that they are > So the only way I can think of requesting a filename is to >generate a window that is one text line high, and attach a console >Dan Green ARPA: hsgj@vax2.ccs.cornell.edu > UUCP: {decvax,ihnp4,allegra}!cornell!batcomputer!hsgj Dan, Here is a little program I have that I use in my programs to get a string as input. It is not well documented, relies on global variables (that should be obvious) and was written using buggy 1.0 s/w and RKM. It does however work. GetString will open a requester with a string gadget. String gadgets can be edited with the arrow keys, backspace, del, and right-A X (which erases the current string). I compile this module (last time in Lattice 3.02) and link it later. In your initialization code insert ... InitReq(); ... When you want a string from a user UBYTE *string_name; ... string_name = GetString("Enter File Name", "DefaultFile"); ... Open(string_name ... /* ---------------------------------------------------------------------- ----------------------------- GetStr.c ------------------------------- ---------------------------------------------------------------------- */ #include <exec/types.h> #include <intuition/intuition.h> extern struct Window *Window; SHORT GetFXY[] = {0, 0, 0, 9, 282, 9, 282, 0, 0, 0}; unsigned char get_buff[90]; struct Border GetFBorder = { -1, -1, /* Left, Top edges */ 3, NULL, JAM1, /* Front pen, draw mode */ 5, /* Corners */ GetFXY, /* XY Array */ NULL /* No links */ }; struct IntuiText FileString = { 1, 0, JAM1, 8, 22, NULL, NULL, NULL }; struct StringInfo MyString = { get_buff, /* Buffer for file name */ NULL, /* No undo buffer needed */ 0, 80, 0 /* Stuff */ }; struct Gadget GetF = { NULL, /* No next gadget */ 10, 40, 280, 10, /* Left, Top, Width, Height */ GADGHCOMP, /* Flag for string */ ENDGADGET, /* Needed for a requester */ STRGADGET | REQGADGET, /* This is a string gadget */ &GetFBorder, /* Border */ NULL, /* No alternate either */ NULL, /* No text */ NULL, /* No mutual exclusion */ &MyString, /* Special info data structure */ 1, /* First gadget */ NULL /* No special data */ }; SHORT FilesXY[] = {0, 0, 0, 69, 299, 69, 299, 0, 0, 0}; struct Border FilesBorder = { 0, 0, /* Left, Top edges */ 3, NULL, JAM1, /* Front pen, draw mode */ 5, /* Corners */ FilesXY, /* XY Array */ NULL /* No links */ }; struct IntuiText cancelText = { 2, 2, JAM1, 25, 11, NULL, "CANCEL", NULL }; SHORT cancelXY[] = { 0, 0, 101, 0, 101, 31, 0, 31, 0, 0 }; struct Border cancelBorder = { -1, -1, 1, 0, JAM1, 5, (APTR)&cancelXY, NULL }; struct Gadget cancel_gadget = { NULL, 270, 30, 100, 30, GADGHCOMP, RELVERIFY | ENDGADGET, BOOLGADGET | REQGADGET, (APTR)&cancelBorder, NULL, &cancelText, NULL, NULL, 2, NULL }; struct Requester Files; struct Requester cancelReq; InitReq() { InitRequester(&Files); Files.LeftEdge = 170; Files.TopEdge = 70; Files.Width = 300; Files.Height = 70; Files.ReqGadget = &GetF; Files.ReqBorder = &FilesBorder; Files.ReqText = &FileString; Files.BackFill = 2; InitRequester(&cancelReq); cancelReq.LeftEdge = 0; cancelReq.TopEdge = 8; cancelReq.Width = 640; cancelReq.Height = 192; cancelReq.ReqGadget = &cancel_gadget; cancelReq.BackFill = 0; } char *GetString(string, start) UBYTE *string; char *start; { ULONG class; struct IntuiMessage *message; FileString.IText = string; strcpy(get_buff, start); Request(&Files, Window); Wait(1 << Window->UserPort->mp_SigBit); while (message = (struct IntuiMessage *)GetMsg(Window->UserPort)) ReplyMsg(message); return(get_buff); } -- Rich Rodgers tektronix!pogo!richr