home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / mswindo / programm / misc / 1111 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  3.0 KB

  1. Xref: sparky comp.os.ms-windows.programmer.misc:1111 comp.windows.ms.programmer:7442
  2. Path: sparky!uunet!usna!faculty!baldwin
  3. From: baldwin@csservera.scs.usna.navy.mil (J.D. Baldwin)
  4. Newsgroups: comp.os.ms-windows.programmer.misc,comp.windows.ms.programmer
  5. Subject: How many children does this window have?
  6. Message-ID: <BALDWIN.92Jul30214638@csservera.scs.usna.navy.mil>
  7. Date: 31 Jul 92 01:46:38 GMT
  8. Sender: news@usna.NAVY.MIL
  9. Followup-To: comp.os.ms-windows.programmer.misc
  10. Organization: Comp. Sci. Dep't., U.S. Naval Academy, Annapolis, MD
  11. Lines: 58
  12.  
  13. Subject: How many children does this window have?
  14.  
  15. This is something that ought to be REAL simple, but I just can't figure it
  16. out.  I am using ObjectWindows with Borland C++ 3.0 to develop a Windows
  17. 3.1 application.
  18.  
  19. In function CanClose() of my application's main window, I wish to check
  20. whether the window has any children before asking whether the user is sure
  21. he wants to close the window.  That is, the window will close immediately
  22. if there are NO children; but a MessageBox will ask "Are you sure?" if there
  23. are any children.
  24.  
  25. I thought I'd just do the following (in CanClose()):
  26.  
  27.    PTWindowsObject kid;
  28.  
  29.    kid = GetFirstChild();
  30.  
  31.    if (kid != NULL)
  32.    {
  33.       /*  DO MESSAGEBOX HERE */
  34.    }
  35.    else
  36.       return TRUE;
  37.  
  38. This works fine if there are children, but causes a general protection
  39. fault if there are no children.  Why?  Well it seems that GetFirstChild()
  40. is an inline function that returns, simply:
  41.  
  42.      ChildList -> SiblingList
  43.  
  44. If there are no children, ChildList is NULL.  (Is this brain-dead,
  45. or what?  A call to GetFirstChild() when there are no children will
  46. always cause a general protection fault since it dereferences NULL.)
  47.  
  48. "So," I hear you saying to yourselves, "if ChildList is NULL when
  49. there are no children, then why not just test (ChildList != NULL)?"  An
  50. excellent idea, but thanks to the data-hiding instincts of the same
  51. software designers who gave us the bug described above, ChildList is a
  52. private data member of TWindowsObject.
  53.  
  54. The only thing I can think of is to use ForEach() on a pointer to a function
  55. whose only purpose is to increment a counter; this will return a count
  56. of the child windows.  However, this is a gross kludge and, for all I know,
  57. ForEach() suffers from the same idiotic bug as GetFirstChild().
  58.  
  59. So, does anyone out there have the simple answer?  If you do, please post
  60. *and* e-mail me at baldwin@spectrum.lanl.gov, as my access to my normal
  61. mail machine and news-reading machine is unreliable at best (it requires
  62. a 3000-mile telnet connection).
  63.  
  64. SUMMER ADDRESS:  baldwin@spectrum.lanl.gov (Los Alamos National Laboratories)
  65. --
  66.  From the catapult of:              |+| "If anyone disagrees with anything I
  67.    _,_  J. D. Baldwin, Comp Sci Dept|+| say, I am quite prepared not only to
  68.  _|70|___:::)=}-  U.S. Naval Academy|+| retract it, but also to deny under
  69.  \      /   baldwin@usna.navy.mil   |+| oath that I ever said it." --T. Lehrer
  70. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  71.