[comp.sys.mac.programmer] cdev question: Why does GetDItem return bad value on closeDev?

mahboud@kinetics.UUCP (Mahboud Zabetian) (07/21/89)

Does anyone know what state the Control Panel is in at the time of a closeDev
call?  I do a GetDItem and SetIText when I get a closeDev call, but it never
works, and sometimes it even crashes.

In macsbug I notice that my DITL list is still pointed to by the Control Panel
window and that my cdev file is still open.  So why am I not getting a valid
Handle back from GetDItem?

On a related note- what happens when you get an updateDev call?  I do some
drawing in the cdev window, which will get erased as soon as I get another
message(other than a nulDev), but this drawing almost never is seen.  I know
that the code for it gets executed, but the drawing seems to be wiped out with
something.

Thank you...

mahboud

Standard Disclaimer:  Don't mind me, I'm just babbling.
------------------------------------------------------------------------------
     Mahboud Zabetian	 (415) 975-4511		mahboud@kinetics.com
  Kinetics/Excelan/Novell
 1340 Treat Blvd, Suite 500		...!ucbvax!mtxinu!kinetics!mahboud
   Walnut Creek, CA 94596
------------------------------------------------------------------------------
Woke up in my clothes again this morning, I don't know exactly where I am....
					--- Sting
------------------------------------------------------------------------------

kazim@Apple.COM (Alex Kazim) (07/22/89)

In article <783@kinetics.UUCP> mahboud@kinetics.com (Mahboud Zabetian) writes:
>
>In macsbug I notice that my DITL list is still pointed to by the Control Panel
>window and that my cdev file is still open.  So why am I not getting a valid
>Handle back from GetDItem?
>
>mahboud

Off the top of my head...

I think the first 2 bytes of DITL information is the number of items
in the list (zero based).  Check to see if your item ID is not greater
than this number or you might get a bad handle even if your DITL is
there.

==========================================================================
Alex Kazim
Apple Computer 
Grunt Programmer's Opinions
==========================================================================

thecloud@dhw68k.cts.com (Ken McLeod) (07/22/89)

In article <783@kinetics.UUCP> mahboud@kinetics.com (Mahboud Zabetian) writes:
>
>Does anyone know what state the Control Panel is in at the time of a closeDev
>call?  I do a GetDItem and SetIText when I get a closeDev call, but it never
>works, and sometimes it even crashes.

  When your cdev gets a 'closeDev' message, your appended dialog items
have already been un-appended from the Control Panel's DITL, and are
no longer valid. If you have text in an editText item, keep a current
copy around (in your private block of storage) and update it whenever
you get a keyEvtDev or a hitDev involving the editText item. That way,
you won't have to read it right at closing time. I don't understand
why you'd want to do a SetIText on a closeDev... you meant GetIText?


-- 
==========     .......     =============================================
Ken McLeod    :.     .:    UUCP: ...{spsd,zardoz,felix}!dhw68k!thecloud
==========   :::.. ..:::   INTERNET: thecloud@dhw68k.cts.com
                ////       =============================================

tim@hoptoad.uucp (Tim Maroney) (07/22/89)

In article <783@kinetics.UUCP> mahboud@kinetics.com (Mahboud Zabetian) writes:
>Does anyone know what state the Control Panel is in at the time of a closeDev
>call?  I do a GetDItem and SetIText when I get a closeDev call, but it never
>works, and sometimes it even crashes.

Well, there's no documentation of this point and it's been over a year
since I wrote my last CDEV, but as I recall, closeDev is sent only
after your items have been removed from the dialog item list.  If you
try to access them at that point, you will likely crash.

>In macsbug I notice that my DITL list is still pointed to by the Control Panel
>window and that my cdev file is still open.  So why am I not getting a valid
>Handle back from GetDItem?

Your file's still open, sure.  How else could it acess your 'cdev'
resource?  However, with respect to the dialog item list, there is *a*
dialog item list, but if you check more carefully I think you will find
that it contains only the generic CDEV dialog items, not yours.

>On a related note- what happens when you get an updateDev call?  I do some
>drawing in the cdev window, which will get erased as soon as I get another
>message(other than a nulDev), but this drawing almost never is seen.  I know
>that the code for it gets executed, but the drawing seems to be wiped out with
>something.

You should only draw into user items in your dialog, and before doing
so you should clip to either the user item or to the whole window to
make sure you aren't clipped out.  To do the latter,
"ClipRect(&CPDialog->portRect);" before drawing.
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"What's the ugliest part of your body?
 Some say your nose, some say your toes,
 But I think it's your mind."
-- Frank Zappa

jkjl@cs.mu.oz.au (John Keong-Jin Lim) (07/24/89)

In article <783@kinetics.UUCP> mahboud@kinetics.com (Mahboud Zabetian) writes:
>
>Does anyone know what state the Control Panel is in at the time of a closeDev
>call?  I do a GetDItem and SetIText when I get a closeDev call, but it never
>works, and sometimes it even crashes.
>

You need to do that before the cdev is closed ( i presume you mean GetIText -
SetIText seems pretty useless when closing a cdev !). What you need to do
is check for keyDown events and save the characters then. Alternately 
poll for keyDown events, then on the next null event do a GetIText; that
way you dont need to worry about backspace.

>In macsbug I notice that my DITL list is still pointed to by the Control Panel
>window and that my cdev file is still open.  So why am I not getting a valid
>Handle back from GetDItem?
>

If i recall, the TEHandle for your text has been disposed off already.

>On a related note- what happens when you get an updateDev call?  I do some
>drawing in the cdev window, which will get erased as soon as I get another
>message(other than a nulDev), but this drawing almost never is seen.  I know
>that the code for it gets executed, but the drawing seems to be wiped out with
>something.
>

Are you using BeginUpdate EndUpdate ? Have you set the nrct resource 
properly ?

	Have fun (i did when i wrote my first cdev !)
	john