Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tellab5!kenk From: kenk@sunHd.tellabs.com (Ken Konecki) Newsgroups: comp.sys.mac.programmer Subject: Dialog problems in DA Message-ID: <4927@tellab5.tellabs.com> Date: 2 Jan 91 18:13:23 GMT Sender: news@Tellabs.COM Organization: Tellabs, Inc. Lisle, IL Lines: 139 Originator: kenk@sunHd I'm having trouble getting dialogs to work inside of a desk accessory. I keep the item list as an owned resource and do a GetResource() call to get a handle to it. When I create the dialog, I use NewDialog() and pass the handle of the item list obtained from GetResource() as the item list parameter. I do the dialogging and then call CloseDialog() at the end of the routine. Everything works as I expect it to but only on the first time I bring up the dialog. The second time I try, I get an address error and get dropped into Macsbug. Stepping through the routine with Macsbug, I've found that the call to NewDialog() returns a valid dialog record, but the control list is NIL. As you would expect, the first time through the routine, the control list of the dialog window is not NIL. This is of course why it the routine bombs the second time but not the first. The big question is: Why is the control list NIL the second time I call NewDialog()? I have enclosed the offending routine at the end of this post. The desk accessory I'm writing is a simple calendar display. The dialog is used to set the month and year that is being displayed. I'm using Think C 4.0 on a Mac SE. Thanks in advance for any help. Cheers, -Ken K #define ITEMS_ID 1 #define JAN_BTN 3 #define YEAR_ITEM JAN_BTN + 12 #define OFF 0 #define ON 1 static rsrcID(id) int id; { return (0xc000 + (~dce->dCtlRefNum << 5) + id); } static Handle dlogItems; int checkItems() { return ((dlogItems = GetResource('DITL', rsrcID(ITEMS_ID))) != NULL); } void setMonth(month, year) unsigned *month, *year; { int itemHit; register DialogPtr monthDlog; Str255 text; int oldMonth; Rect box; int itemType; Handle item, yearItem; long newYear; int dlogDone = FALSE; Debugger(); dlogItems = GetResource('DITL', rsrcID(ITEMS_ID)); SetRect(&box, 110, 68, 400, 200); monthDlog = NewDialog(NULL, &box, "\pSet Month", FALSE, 1, PUT_IN_FRONT, FALSE, 0L, dlogItems); /* * Unhilite the old button and hilite the new */ oldMonth = *month; GetDItem(monthDlog, oldMonth + JAN_BTN - 1, &itemType, &item, &box); SetCtlValue((ControlHandle) item, ON); /* * Set the current year as the default year */ NumToString((long) (*year), text); GetDItem(monthDlog, YEAR_ITEM, &itemType, &yearItem, &box); SetIText(yearItem, text); SelIText(monthDlog, YEAR_ITEM, 0, 32767); ShowWindow(monthDlog); /* DrawControls(monthDlog); */ /* * Do the dialogging */ while (!dlogDone) { ModalDialog(NULL, &itemHit); if (itemHit == 1) { /* * Ok button */ *month = oldMonth; GetIText(yearItem, text); StringToNum(text, &newYear); *year = (int) newYear; /* * Do some error checking */ dlogDone = TRUE; } else if (itemHit == 2) { /* * Cancel Button */ dlogDone = TRUE; } else if ((itemHit >= JAN_BTN) && (itemHit < YEAR_ITEM)) { /* * One of the radio buttons was hit */ GetDItem(monthDlog, oldMonth + JAN_BTN - 1, &itemType, &item, &box); SetCtlValue((ControlHandle) item, OFF); oldMonth = itemHit - JAN_BTN + 1; GetDItem(monthDlog, itemHit, &itemType, &item, &box); SetCtlValue((ControlHandle) item, ON); } } updateCalendar(); CloseDialog(monthDlog); } -- Ken Konecki "Eat well, stay fit, and die anyway" e-mail:kenk@tellabs.com -or- ...!uunet!tellab5!kenk