#include #include #include pascal Boolean OurFilter(DialogPtr dlg, EventRecord *event, short *itemhit); void doDialog (void); void doCopyString(Str255, Str255); #define dName 128 // The DLOG resource ID, 128 #define iText 1 // Item # for the text box #define iOK 2 // Item # for the OK button #define iCancel 3 // Item # for the cancel button void doDialog (void) { DialogPtr TheDialog; // A pointer to the DLOG resource Str255 theText, theItem; // A string to copy, and retrieve, text short iKind; Handle iHandle; Rect iRect; OSErr theErr; short itemHit; TheDialog=GetNewDialog(dName, nil, (WindowPtr)-1); //This command retrieves the dialog, and displays it in the // foreground GetDialogItem(TheDialog, iText, &iKind, &iHandle, &iRect); // Creates a handle for the editable text area, to allow // us to update/retrieve it doCopyString("\pName", theText); // Custom function that copies the text into the string SetDialogItemText(iHandle, theText); // Sets the text of the edit text to theText (Name) do { // Create a loop so that they can't exit the dialog ModalDialog(NewModalFilterProc(OurFilter), &itemHit); // A filter to watch for custom commands (enter, tab) // As soon as any action occurs, it returns the item // number it occurred in theErr = SetDialogDefaultItem(TheDialog, iOk); // This is the default item to watch, if we had the // custom filter looking for enter. // At this point you can put in any if or other statements // you want, to check for any buttons being pressed, // such as: /* if (itemHit == iInputOk) SysBeep(1); */ } while ((itemHit != iOk) || (itemHit != iCancel)); // Keep the loop going until either Ok or Cancel is selected DisposeDialog(TheDialog); // Take the dialog off the screen, and free up the memory } /* The following is a custom string copy command, which I find easier to use */ void doCopyString(Str255 source, Str255 dest) { SInt16 strLen; strLen = source[0]; BlockMove(source + 1, dest + 1, strLen); dest[0] = strLen; } /* This can be a custom filter, to check for any commands or mouse actions made while your dialog box is displayed. It's currently empty, as a filter must be defined for dialogs. */ pascal Boolean OurFilter(DialogPtr dlg, EventRecord *event, short *itemHit) { return false;