winctrl1.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 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 related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifndef _AFX_NO_OCC_SUPPORT
  12. #include "occimpl.h"
  13. #endif
  14. #ifdef AFX_CORE4_SEG
  15. #pragma code_seg(AFX_CORE4_SEG)
  16. #endif
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #define new DEBUG_NEW
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CStatic
  24. BOOL CStatic::Create(LPCTSTR lpszText, DWORD dwStyle,
  25. const RECT& rect, CWnd* pParentWnd, UINT nID)
  26. {
  27. CWnd* pWnd = this;
  28. return pWnd->Create(_T("STATIC"), lpszText, dwStyle, rect, pParentWnd, nID);
  29. }
  30. CStatic::~CStatic()
  31. {
  32. DestroyWindow();
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CButton
  36. BOOL CButton::Create(LPCTSTR lpszCaption, DWORD dwStyle,
  37. const RECT& rect, CWnd* pParentWnd, UINT nID)
  38. {
  39. CWnd* pWnd = this;
  40. return pWnd->Create(_T("BUTTON"), lpszCaption, dwStyle, rect, pParentWnd, nID);
  41. }
  42. CButton::~CButton()
  43. {
  44. DestroyWindow();
  45. }
  46. // Helper for radio buttons
  47. int CWnd::GetCheckedRadioButton(int nIDFirstButton, int nIDLastButton)
  48. {
  49. for (int nID = nIDFirstButton; nID <= nIDLastButton; nID++)
  50. {
  51. if (IsDlgButtonChecked(nID))
  52. return nID; // id that matched
  53. }
  54. return 0; // invalid ID
  55. }
  56. // Derived class is responsible for implementing all of these handlers
  57. // for owner/self draw controls
  58. void CButton::DrawItem(LPDRAWITEMSTRUCT)
  59. {
  60. ASSERT(FALSE);
  61. }
  62. BOOL CButton::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
  63. LRESULT* pResult)
  64. {
  65. if (message != WM_DRAWITEM)
  66. return CWnd::OnChildNotify(message, wParam, lParam, pResult);
  67. ASSERT(pResult == NULL); // no return value expected
  68. UNUSED(pResult); // unused in release builds
  69. DrawItem((LPDRAWITEMSTRUCT)lParam);
  70. return TRUE;
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CListBox
  74. BOOL CListBox::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  75. UINT nID)
  76. {
  77. CWnd* pWnd = this;
  78. return pWnd->Create(_T("LISTBOX"), NULL, dwStyle, rect, pParentWnd, nID);
  79. }
  80. CListBox::~CListBox()
  81. {
  82. DestroyWindow();
  83. }
  84. // Derived class is responsible for implementing these handlers
  85. // for owner/self draw controls (except for the optional DeleteItem)
  86. void CListBox::DrawItem(LPDRAWITEMSTRUCT)
  87. { ASSERT(FALSE); }
  88. void CListBox::MeasureItem(LPMEASUREITEMSTRUCT)
  89. { ASSERT(FALSE); }
  90. int CListBox::CompareItem(LPCOMPAREITEMSTRUCT)
  91. { ASSERT(FALSE); return 0; }
  92. void CListBox::DeleteItem(LPDELETEITEMSTRUCT)
  93. { /* default to nothing */ }
  94. int CListBox::VKeyToItem(UINT, UINT)
  95. { return Default(); }
  96. int CListBox::CharToItem(UINT, UINT)
  97. { return Default(); }
  98. BOOL CListBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
  99. LRESULT* pResult)
  100. {
  101. switch (message)
  102. {
  103. case WM_DRAWITEM:
  104. ASSERT(pResult == NULL); // no return value expected
  105. DrawItem((LPDRAWITEMSTRUCT)lParam);
  106. break;
  107. case WM_MEASUREITEM:
  108. ASSERT(pResult == NULL); // no return value expected
  109. MeasureItem((LPMEASUREITEMSTRUCT)lParam);
  110. break;
  111. case WM_COMPAREITEM:
  112. ASSERT(pResult != NULL); // return value expected
  113. *pResult = CompareItem((LPCOMPAREITEMSTRUCT)lParam);
  114. break;
  115. case WM_DELETEITEM:
  116. ASSERT(pResult == NULL); // no return value expected
  117. DeleteItem((LPDELETEITEMSTRUCT)lParam);
  118. break;
  119. case WM_VKEYTOITEM:
  120. *pResult = VKeyToItem(LOWORD(wParam), HIWORD(wParam));
  121. break;
  122. case WM_CHARTOITEM:
  123. *pResult = CharToItem(LOWORD(wParam), HIWORD(wParam));
  124. break;
  125. default:
  126. return CWnd::OnChildNotify(message, wParam, lParam, pResult);
  127. }
  128. return TRUE;
  129. }
  130. void CListBox::GetText(int nIndex, CString& rString) const
  131. {
  132. ASSERT(::IsWindow(m_hWnd));
  133. GetText(nIndex, rString.GetBufferSetLength(GetTextLen(nIndex)));
  134. rString.ReleaseBuffer();
  135. }
  136. #if (WINVER >= 0x400)
  137. UINT CListBox::ItemFromPoint(CPoint pt, BOOL& bOutside) const
  138. {
  139. ASSERT(::IsWindow(m_hWnd));
  140. DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
  141. bOutside = !!HIWORD(dw);
  142. return LOWORD(dw);
  143. }
  144. #endif
  145. /////////////////////////////////////////////////////////////////////////////
  146. // CComboBox
  147. BOOL CComboBox::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  148. UINT nID)
  149. {
  150. CWnd* pWnd = this;
  151. return pWnd->Create(_T("COMBOBOX"), NULL, dwStyle, rect, pParentWnd, nID);
  152. }
  153. CComboBox::~CComboBox()
  154. {
  155. DestroyWindow();
  156. }
  157. // Derived class is responsible for implementing these handlers
  158. // for owner/self draw controls (except for the optional DeleteItem)
  159. void CComboBox::DrawItem(LPDRAWITEMSTRUCT)
  160. { ASSERT(FALSE); }
  161. void CComboBox::MeasureItem(LPMEASUREITEMSTRUCT)
  162. { ASSERT(FALSE); }
  163. int CComboBox::CompareItem(LPCOMPAREITEMSTRUCT)
  164. { ASSERT(FALSE); return 0; }
  165. void CComboBox::DeleteItem(LPDELETEITEMSTRUCT)
  166. { /* default to nothing */ }
  167. BOOL CComboBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
  168. LRESULT* pResult)
  169. {
  170. switch (message)
  171. {
  172. case WM_DRAWITEM:
  173. ASSERT(pResult == NULL); // no return value expected
  174. DrawItem((LPDRAWITEMSTRUCT)lParam);
  175. break;
  176. case WM_MEASUREITEM:
  177. ASSERT(pResult == NULL); // no return value expected
  178. MeasureItem((LPMEASUREITEMSTRUCT)lParam);
  179. break;
  180. case WM_COMPAREITEM:
  181. ASSERT(pResult != NULL); // return value expected
  182. *pResult = CompareItem((LPCOMPAREITEMSTRUCT)lParam);
  183. break;
  184. case WM_DELETEITEM:
  185. ASSERT(pResult == NULL); // no return value expected
  186. DeleteItem((LPDELETEITEMSTRUCT)lParam);
  187. break;
  188. default:
  189. return CWnd::OnChildNotify(message, wParam, lParam, pResult);
  190. }
  191. return TRUE;
  192. }
  193. void CComboBox::GetLBText(int nIndex, CString& rString) const
  194. {
  195. ASSERT(::IsWindow(m_hWnd));
  196. GetLBText(nIndex, rString.GetBufferSetLength(GetLBTextLen(nIndex)));
  197. rString.ReleaseBuffer();
  198. }
  199. /////////////////////////////////////////////////////////////////////////////
  200. // CEdit
  201. BOOL CEdit::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
  202. {
  203. CWnd* pWnd = this;
  204. return pWnd->Create(_T("EDIT"), NULL, dwStyle, rect, pParentWnd, nID);
  205. }
  206. CEdit::~CEdit()
  207. {
  208. DestroyWindow();
  209. }
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CScrollBar
  212. BOOL CScrollBar::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  213. UINT nID)
  214. {
  215. CWnd* pWnd = this;
  216. return pWnd->Create(_T("SCROLLBAR"), NULL, dwStyle, rect, pParentWnd, nID);
  217. }
  218. CScrollBar::~CScrollBar()
  219. {
  220. DestroyWindow();
  221. }
  222. #ifdef AFX_INIT_SEG
  223. #pragma code_seg(AFX_INIT_SEG)
  224. #endif
  225. IMPLEMENT_DYNAMIC(CStatic, CWnd)
  226. IMPLEMENT_DYNAMIC(CButton, CWnd)
  227. IMPLEMENT_DYNAMIC(CListBox, CWnd)
  228. IMPLEMENT_DYNAMIC(CComboBox, CWnd)
  229. IMPLEMENT_DYNAMIC(CEdit, CWnd)
  230. IMPLEMENT_DYNAMIC(CScrollBar, CWnd)
  231. /////////////////////////////////////////////////////////////////////////////