Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
5.9 KiB

  1. /*--------------------------------------------------------------------------*
  2. *
  3. * Microsoft Windows
  4. * Copyright (C) Microsoft Corporation, 1992 - 1999
  5. *
  6. * File: wrapper.cpp
  7. *
  8. * Contents: Implementation file for simple wrapper classes
  9. *
  10. * History: 02-Feb-98 jeffro Created
  11. *
  12. *--------------------------------------------------------------------------*/
  13. #include "stdafx.h"
  14. #include "wrapper.h"
  15. /*+-------------------------------------------------------------------------*
  16. * CAccel::CAccel
  17. *
  18. *
  19. *--------------------------------------------------------------------------*/
  20. CAccel::CAccel (HACCEL hAccel /* =NULL */)
  21. :
  22. m_hAccel (hAccel)
  23. {
  24. }
  25. CAccel::CAccel (LPACCEL paccl, int cEntries)
  26. :
  27. m_hAccel (::CreateAcceleratorTable (paccl, cEntries))
  28. {
  29. }
  30. /*+-------------------------------------------------------------------------*
  31. * CAccel::~CAccel
  32. *
  33. *
  34. *--------------------------------------------------------------------------*/
  35. CAccel::~CAccel ()
  36. {
  37. DestroyAcceleratorTable ();
  38. }
  39. /*+-------------------------------------------------------------------------*
  40. * CAccel::CreateAcceleratorTable
  41. *
  42. *
  43. *--------------------------------------------------------------------------*/
  44. bool CAccel::CreateAcceleratorTable (LPACCEL paccl, int cEntries)
  45. {
  46. DestroyAcceleratorTable ();
  47. ASSERT (m_hAccel == NULL);
  48. if(paccl != NULL)
  49. m_hAccel = ::CreateAcceleratorTable (paccl, cEntries);
  50. return (m_hAccel != NULL);
  51. }
  52. /*+-------------------------------------------------------------------------*
  53. * CAccel::CopyAcceleratorTable
  54. *
  55. *
  56. *--------------------------------------------------------------------------*/
  57. int CAccel::CopyAcceleratorTable (LPACCEL paccl, int cEntries) const
  58. {
  59. return (::CopyAcceleratorTable (m_hAccel, paccl, cEntries));
  60. }
  61. /*+-------------------------------------------------------------------------*
  62. * CAccel::DestroyAcceleratorTable
  63. *
  64. *
  65. *--------------------------------------------------------------------------*/
  66. void CAccel::DestroyAcceleratorTable ()
  67. {
  68. if (m_hAccel != NULL)
  69. {
  70. ::DestroyAcceleratorTable (m_hAccel);
  71. m_hAccel = NULL;
  72. }
  73. }
  74. /*+-------------------------------------------------------------------------*
  75. * CAccel::LoadAccelerators
  76. *
  77. *
  78. *--------------------------------------------------------------------------*/
  79. bool CAccel::LoadAccelerators (int nAccelID)
  80. {
  81. return (LoadAccelerators (MAKEINTRESOURCE (nAccelID)));
  82. }
  83. /*+-------------------------------------------------------------------------*
  84. * CAccel::LoadAccelerators
  85. *
  86. *
  87. *--------------------------------------------------------------------------*/
  88. bool CAccel::LoadAccelerators (LPCTSTR pszAccelName)
  89. {
  90. HINSTANCE hInst = AfxFindResourceHandle (pszAccelName, RT_ACCELERATOR);
  91. return (LoadAccelerators (hInst, pszAccelName));
  92. }
  93. /*+-------------------------------------------------------------------------*
  94. * CAccel::LoadAccelerators
  95. *
  96. *
  97. *--------------------------------------------------------------------------*/
  98. bool CAccel::LoadAccelerators (HINSTANCE hInst, LPCTSTR pszAccelName)
  99. {
  100. DestroyAcceleratorTable ();
  101. ASSERT (m_hAccel == NULL);
  102. m_hAccel = ::LoadAccelerators (hInst, pszAccelName);
  103. return (m_hAccel != NULL);
  104. }
  105. /*+-------------------------------------------------------------------------*
  106. * CAccel::TranslateAccelerator
  107. *
  108. *
  109. *--------------------------------------------------------------------------*/
  110. bool CAccel::TranslateAccelerator (HWND hwnd, LPMSG pmsg) const
  111. {
  112. return ((m_hAccel != NULL) &&
  113. ::TranslateAccelerator (hwnd, m_hAccel, pmsg));
  114. }
  115. /*+-------------------------------------------------------------------------*
  116. * CDeferWindowPos::CDeferWindowPos
  117. *
  118. *
  119. *--------------------------------------------------------------------------*/
  120. CDeferWindowPos::CDeferWindowPos (
  121. int cWindows,
  122. bool fSynchronousPositioningForDebugging)
  123. : m_hdwp (NULL),
  124. m_fSynchronousPositioningForDebugging (fSynchronousPositioningForDebugging)
  125. {
  126. Begin (cWindows);
  127. }
  128. /*+-------------------------------------------------------------------------*
  129. * CDeferWindowPos::~CDeferWindowPos
  130. *
  131. *
  132. *--------------------------------------------------------------------------*/
  133. CDeferWindowPos::~CDeferWindowPos ()
  134. {
  135. if (m_hdwp)
  136. End();
  137. }
  138. /*+-------------------------------------------------------------------------*
  139. * CDeferWindowPos::Begin
  140. *
  141. *
  142. *--------------------------------------------------------------------------*/
  143. bool CDeferWindowPos::Begin (int cWindows)
  144. {
  145. ASSERT (m_hdwp == NULL);
  146. ASSERT (cWindows > 0);
  147. m_hdwp = ::BeginDeferWindowPos (cWindows);
  148. return (m_hdwp != NULL);
  149. }
  150. /*+-------------------------------------------------------------------------*
  151. * CDeferWindowPos::End
  152. *
  153. *
  154. *--------------------------------------------------------------------------*/
  155. bool CDeferWindowPos::End ()
  156. {
  157. ASSERT (m_hdwp != NULL);
  158. HDWP hdwp = m_hdwp;
  159. m_hdwp = NULL;
  160. if ( hdwp == NULL )
  161. return false;
  162. return (::EndDeferWindowPos (hdwp) != 0);
  163. }
  164. /*+-------------------------------------------------------------------------*
  165. * CDeferWindowPos::AddWindow
  166. *
  167. *
  168. *--------------------------------------------------------------------------*/
  169. bool CDeferWindowPos::AddWindow (
  170. const CWnd* pwnd,
  171. const CRect& rect,
  172. DWORD dwFlags,
  173. const CWnd* pwndInsertAfter /* =NULL */)
  174. {
  175. ASSERT (IsWindow (pwnd->GetSafeHwnd()));
  176. if (pwndInsertAfter == NULL)
  177. dwFlags |= SWP_NOZORDER;
  178. if ( m_hdwp == NULL )
  179. return false;
  180. m_hdwp = ::DeferWindowPos (m_hdwp,
  181. pwnd->GetSafeHwnd(),
  182. pwndInsertAfter->GetSafeHwnd(),
  183. rect.left, rect.top,
  184. rect.Width(), rect.Height(),
  185. dwFlags);
  186. #ifdef DBG
  187. if (m_fSynchronousPositioningForDebugging)
  188. {
  189. End ();
  190. Begin (1);
  191. }
  192. #endif
  193. return (m_hdwp != NULL);
  194. }