home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.os.ms-windows.programmer.misc:1111 comp.windows.ms.programmer:7442
- Path: sparky!uunet!usna!faculty!baldwin
- From: baldwin@csservera.scs.usna.navy.mil (J.D. Baldwin)
- Newsgroups: comp.os.ms-windows.programmer.misc,comp.windows.ms.programmer
- Subject: How many children does this window have?
- Message-ID: <BALDWIN.92Jul30214638@csservera.scs.usna.navy.mil>
- Date: 31 Jul 92 01:46:38 GMT
- Sender: news@usna.NAVY.MIL
- Followup-To: comp.os.ms-windows.programmer.misc
- Organization: Comp. Sci. Dep't., U.S. Naval Academy, Annapolis, MD
- Lines: 58
-
- Subject: How many children does this window have?
-
- This is something that ought to be REAL simple, but I just can't figure it
- out. I am using ObjectWindows with Borland C++ 3.0 to develop a Windows
- 3.1 application.
-
- In function CanClose() of my application's main window, I wish to check
- whether the window has any children before asking whether the user is sure
- he wants to close the window. That is, the window will close immediately
- if there are NO children; but a MessageBox will ask "Are you sure?" if there
- are any children.
-
- I thought I'd just do the following (in CanClose()):
-
- PTWindowsObject kid;
-
- kid = GetFirstChild();
-
- if (kid != NULL)
- {
- /* DO MESSAGEBOX HERE */
- }
- else
- return TRUE;
-
- This works fine if there are children, but causes a general protection
- fault if there are no children. Why? Well it seems that GetFirstChild()
- is an inline function that returns, simply:
-
- ChildList -> SiblingList
-
- If there are no children, ChildList is NULL. (Is this brain-dead,
- or what? A call to GetFirstChild() when there are no children will
- always cause a general protection fault since it dereferences NULL.)
-
- "So," I hear you saying to yourselves, "if ChildList is NULL when
- there are no children, then why not just test (ChildList != NULL)?" An
- excellent idea, but thanks to the data-hiding instincts of the same
- software designers who gave us the bug described above, ChildList is a
- private data member of TWindowsObject.
-
- The only thing I can think of is to use ForEach() on a pointer to a function
- whose only purpose is to increment a counter; this will return a count
- of the child windows. However, this is a gross kludge and, for all I know,
- ForEach() suffers from the same idiotic bug as GetFirstChild().
-
- So, does anyone out there have the simple answer? If you do, please post
- *and* e-mail me at baldwin@spectrum.lanl.gov, as my access to my normal
- mail machine and news-reading machine is unreliable at best (it requires
- a 3000-mile telnet connection).
-
- SUMMER ADDRESS: baldwin@spectrum.lanl.gov (Los Alamos National Laboratories)
- --
- From the catapult of: |+| "If anyone disagrees with anything I
- _,_ J. D. Baldwin, Comp Sci Dept|+| say, I am quite prepared not only to
- _|70|___:::)=}- U.S. Naval Academy|+| retract it, but also to deny under
- \ / baldwin@usna.navy.mil |+| oath that I ever said it." --T. Lehrer
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-