home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1603 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.7 KB  |  41 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!microsoft!hexnut!jonka
  3. From: jonka@microsoft.com (Jonathan Kagle)
  4. Subject: Re: PETZOLD's COLOR PROGRAM AFU??
  5. Message-ID: <1992Aug31.181958.20704@microsoft.com>
  6. Date: 31 Aug 92 18:19:58 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Aug28.004811.7803@cis.ohio-state.edu>
  9. Distribution: usa
  10. Lines: 29
  11.  
  12. In article <1992Aug28.004811.7803@cis.ohio-state.edu> lavigne@spaghetti.cis.ohio-state.edu (david lavigne) writes:
  13. >Has anybody else had the following problem with the colors program is PETZOLDs
  14. >PROGRAMMING WINDOWS book.
  15. >
  16. >The program is not giving up some resource and will eventually cause windows to
  17. >UAE or whatever the new term is.  This happens after moving the scrollbox 
  18. >thumbs for quite a while.  Even terminating the program does not free the 
  19. >resources. 
  20. >
  21.  
  22. This is a known problem with COLORS and Windows 3.1. The code uses 
  23. DeleteObject to delete the colored brush before deselecting it from the
  24. device context (with SetClassWord). As a result, the DeleteObject fails
  25. and the brush is never deleted. When you run the slider up and down, you
  26. fill memory with brushes created by CreateSolidBrush.
  27.  
  28. For some reason, Windows 3.0 was more forgiving, though the API guide 
  29. clearly states (under DeleteObject):
  30.  
  31. "An application should not delete an object that is currently selected into
  32. a device context."
  33.  
  34. This problem isn't instantly obvious when glacing at the code because of
  35. all of the cute tricks that Petzold uses (in this case to save the use of
  36. a temporary variable). In general, when using a modern optimizing compiler,
  37. these tricks rarely pay off in terms of code quality, and can really make
  38. your programs harder to read and debug.
  39.  
  40.        -Jonathan
  41.