home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / mswindo / programm / misc / 1425 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.6 KB  |  74 lines

  1. Newsgroups: comp.windows.ms.programmer,comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!microsoft!wingnut!stevesi
  3. From: stevesi@microsoft.com (Steven Sinofsky)
  4. Subject: Re: MFC and Custom Controls / WM_NCPAINT
  5. Message-ID: <1992Aug20.202109.18466@microsoft.com>
  6. Date: 20 Aug 92 20:21:09 GMT
  7. Organization: Microsoft Corporation
  8. References: <8304@ncratl.AtlantaGA.NCR.COM>
  9. Keywords: Windows Development, Microsoft C/C++
  10. Lines: 60
  11.  
  12. In article <8304@ncratl.AtlantaGA.NCR.COM> kso@ncratl.AtlantaGA.NCR.COM (Khun So) writes:
  13. >
  14. >
  15. >    I have a couple of questions on Windows developement using C/C++ 7.0.
  16. >    Any insights on the subjects will be greatly appreciated.
  17. >
  18. >
  19. >        1. How does one extend MFC to support custom controls
  20. >           and other window classes?  Specifically I would like
  21. >           to derive a class from CWnd for the custom controls
  22. >           I had developed.  Many of my controls use extra bytes
  23. >           per window instance (cbWndExtra!=0 in WNDCLASS data
  24. >           structure).  The current AfxRegisterWndClass always
  25. >           sets cbWndExtra=cbClsExtra=0.  Is there a simple way
  26. >           to do this without modifying MFC source?
  27. Let's say you have a Window class called "MYCLASS", then all you
  28. need to do to have a C++ class is the following:
  29.  
  30. class CMyClass : public CWnd
  31. {
  32. public:
  33.     BOOL Create(LPCSTR lpszWindowName, DWORD dwExtraStyles, 
  34.             const RECT& rect, CWnd* pParentWnd)
  35.         {
  36.             static char BASED_CODE szMyClass[] = "MYCLASS";
  37.             return CWnd::Create(szMyClass, lpszWindowName,
  38.                 dwStyles, rect, pParentWnd);
  39.         }
  40.  
  41.     // add additional member functions to support custome WM_
  42.     // SendMessages here
  43.  
  44.  
  45.     DECLARE_MESSAGE_MAP() // use this to handle messages as
  46.                 // you would expect
  47. };
  48.  
  49. You don't even need to derive your own class if you don't plan
  50. on customizing the Window at all, since CWnd::Create will
  51. allow you to pass a Window class name.  The window will still then be
  52. part of the normal MFC message routing.    
  53.             
  54. >
  55. >        2. In processing WM_PAINT, BeginPaint() API is called
  56. >           and an invalidated region of the window is returned.
  57. >           What about WM_NCPAINT?  Is there a way to detect only
  58. >           the invalidated area in the non-client area for
  59. >           painting?  Or do I have to paint the entire non-client
  60. >           area everytime?
  61. >
  62. >    Thanks in advance.
  63.  
  64. Painting in the non-client area of a Window is "not recommended" (from
  65. page 475 of the Programmers Reference v2).  If you must, then
  66. you retrieve a DC via CWnd::GetWindowDC.  In your code you should
  67. paint everything.
  68.  
  69.  
  70. -- 
  71. Steven Sinofsky
  72. stevesi@microsoft.com
  73. Disclaimer: I don't speak for Microsoft, BillG does that.
  74.