home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / SRC / WINCTRL.CP$ / winctrl
Encoding:
Text File  |  1992-03-18  |  5.2 KB  |  195 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "afxwin.h"
  13. #pragma hdrstop
  14.  
  15. #ifdef AFX_CORE_SEG
  16. #pragma code_seg(AFX_CORE_SEG)
  17. #endif
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #define new DEBUG_NEW
  23. #endif
  24.  
  25.  
  26. // NOTE: the IMPLEMENT_DYNAMIC lines for CListBox, CComboBox, CButton
  27. // are in WINDOW.CPP, since they are only used by Self Draw controls we reduce
  28. // granularity by putting them there.
  29.  
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CStatic
  33.  
  34. IMPLEMENT_DYNAMIC(CStatic, CWnd)
  35.  
  36. WNDPROC* CStatic::GetSuperWndProcAddr()
  37. {
  38.     static WNDPROC pfnSuper;
  39.     return &pfnSuper;
  40. }
  41.  
  42. BOOL CStatic::Create(LPCSTR lpText, DWORD dwStyle,
  43.         const RECT& rect, CWnd* pParentWnd, UINT nID)
  44. {
  45.     return CWnd::Create("STATIC", lpText, dwStyle, rect, pParentWnd, nID);
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CButton
  50.  
  51.  
  52. WNDPROC* CButton::GetSuperWndProcAddr()
  53. {
  54.     static WNDPROC pfnSuper;
  55.     return &pfnSuper;
  56. }
  57.  
  58. BOOL CButton::Create(LPCSTR lpCaption, DWORD dwStyle,
  59.         const RECT& rect, CWnd* pParentWnd, UINT nID)
  60. {
  61.     return CWnd::Create("BUTTON", lpCaption, dwStyle, rect, pParentWnd, nID);
  62. }
  63.  
  64. // Helper for radio buttons
  65. int CWnd::GetCheckedRadioButton(int nIDFirstButton, int nIDLastButton)
  66. {
  67.     for (int nID = nIDFirstButton; nID <= nIDLastButton; nID++)
  68.     {
  69.         if (IsDlgButtonChecked(nID))
  70.             return nID; // id that matched
  71.     }
  72.     return 0; // invalid ID
  73. }
  74.  
  75. // Derived class is responsible for implementing all of these handlers
  76. //   for owner/self draw controls
  77. void CButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
  78.     { ASSERT(FALSE); }
  79.  
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CListBox
  82.  
  83.  
  84. WNDPROC* CListBox::GetSuperWndProcAddr()
  85. {
  86.     static WNDPROC pfnSuper;
  87.     return &pfnSuper;
  88. }
  89.  
  90. BOOL CListBox::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  91.         UINT nID)
  92. {
  93.     return CWnd::Create("LISTBOX", NULL, dwStyle, rect, pParentWnd, nID);
  94. }
  95.  
  96. // Derived class is responsible for implementing these handlers
  97. //   for owner/self draw controls (except for the optional DeleteItem)
  98. void CListBox::DrawItem(LPDRAWITEMSTRUCT)
  99.     { ASSERT(FALSE); }
  100. void CListBox::MeasureItem(LPMEASUREITEMSTRUCT)
  101.     { ASSERT(FALSE); }
  102. int CListBox::CompareItem(LPCOMPAREITEMSTRUCT)
  103.     { ASSERT(FALSE); return 0; }
  104. void CListBox::DeleteItem(LPDELETEITEMSTRUCT)
  105.     { /* default to nothing */ }
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CComboBox
  109.  
  110.  
  111. WNDPROC* CComboBox::GetSuperWndProcAddr()
  112. {
  113.     static WNDPROC pfnSuper;
  114.     return &pfnSuper;
  115. }
  116.  
  117. BOOL CComboBox::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  118.         UINT nID)
  119. {
  120.     return CWnd::Create("COMBOBOX", NULL, dwStyle, rect, pParentWnd, nID);
  121. }
  122.  
  123. // Derived class is responsible for implementing these handlers
  124. //   for owner/self draw controls (except for the optional DeleteItem)
  125. void CComboBox::DrawItem(LPDRAWITEMSTRUCT)
  126.     { ASSERT(FALSE); }
  127. void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
  128.     { ASSERT(FALSE); }
  129. int CComboBox::CompareItem(LPCOMPAREITEMSTRUCT)
  130.     { ASSERT(FALSE); return 0; }
  131. void CComboBox::DeleteItem(LPDELETEITEMSTRUCT)
  132.     { /* default to nothing */ }
  133.  
  134. /////////////////////////////////////////////////////////////////////////////
  135. // CEdit
  136.  
  137. IMPLEMENT_DYNAMIC(CEdit, CWnd)
  138.  
  139. WNDPROC* CEdit::GetSuperWndProcAddr()
  140. {
  141.     static WNDPROC pfnSuper;
  142.     return &pfnSuper;
  143. }
  144.  
  145. BOOL CEdit::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  146. {
  147.     return CWnd::Create("EDIT", NULL, dwStyle, rect, pParentWnd, nID);
  148. }
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CScrollBar
  152.  
  153. IMPLEMENT_DYNAMIC(CScrollBar, CWnd)
  154.  
  155. WNDPROC* CScrollBar::GetSuperWndProcAddr()
  156. {
  157.     static WNDPROC pfnSuper;
  158.     return &pfnSuper;
  159. }
  160.  
  161. BOOL CScrollBar::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  162.         UINT nID)
  163. {
  164.     return CWnd::Create("SCROLLBAR", NULL, dwStyle, rect, pParentWnd, nID);
  165. }
  166.  
  167. /////////////////////////////////////////////////////////////////////////////
  168. // Extra CWnd support for dynamic subclassing of controls
  169.  
  170. BOOL CWnd::SubclassWindow(HWND hWnd)
  171. {
  172.     if (!Attach(hWnd))
  173.         return NULL;
  174.  
  175.     // now hook into the AFX WndProc
  176.     WNDPROC* lplpfn = GetSuperWndProcAddr();
  177.     WNDPROC oldWndProc = (WNDPROC)::SetWindowLong(hWnd, GWL_WNDPROC,
  178.         (DWORD)(WNDPROC)AfxWndProc);
  179.     ASSERT(oldWndProc != (WNDPROC)AfxWndProc);
  180.     
  181.     if (*lplpfn == NULL)
  182.         *lplpfn = oldWndProc;   // the first edit control created
  183.     return TRUE;
  184. }
  185.  
  186. BOOL CWnd::SubclassDlgItem(UINT nID, CWnd* pParent)
  187. {
  188.     HWND hWndControl = ::GetDlgItem(pParent->m_hWnd, nID);
  189.     if (hWndControl == NULL)
  190.         return FALSE;
  191.     return SubclassWindow(hWndControl);
  192. }
  193.  
  194. /////////////////////////////////////////////////////////////////////////////
  195.