HookList.cpp
上传用户:songshun
上传日期:2007-01-04
资源大小:51k
文件大小:3k
源码类别:

按钮控件

开发平台:

Visual C++

  1. //===========================================================================
  2. //
  3. // HomeWork from Belgium Not licensed software  
  4. // 1999 - 2000 No rights reserved
  5. //
  6. //===========================================================================
  7. //
  8. // Project/Product : Iconizer
  9. //  FileName : HookList.cpp
  10. // Author(s) : Bart Gysens
  11. //
  12. // Description : Implementation file for the CHookList class
  13. //
  14. // Classes : CHookList
  15. //
  16. // Information :
  17. //   Compiler(s) : Visual C++ 6.0
  18. //   Target(s) : Windows 95/98 and Windows NT (x86)
  19. //   Editor : Visual C++ 5.0 internal editor
  20. //
  21. // History
  22. // Vers.  Date      Aut.  Type     Description
  23. //  -----  --------  ----  -------  -----------------------------------------
  24. // 1.00   22 05 99  BG    Create   Original
  25. //
  26. //===========================================================================
  27. #include "stdafx.h"
  28. #include "malloc.h"
  29. #include "assert.h"
  30. #include "hooklist.h"
  31. //===========================================================================
  32. // Macros and typedefs
  33. //===========================================================================
  34. //===========================================================================
  35. // 
  36. // Class : CHookList
  37. // Author(s) : Bart Gysens
  38. //
  39. // Description : Declaration of the CHookList class
  40. //
  41. // Comments : This class is used by the CCom class
  42. //
  43. // History : 1.00  : Create
  44. //
  45. //===========================================================================
  46. CHookList::CHookList()
  47. {
  48. m_NbrItems  = 0;
  49. m_pHookItem = NULL;
  50. }
  51. CHookList::~CHookList()
  52. {
  53. if ( m_pHookItem != NULL )
  54. free( m_pHookItem );
  55. }
  56. BOOL CHookList::AddItem( CHookItem& Item )
  57. {
  58. m_NbrItems++;
  59. if ( m_pHookItem == NULL )
  60. m_pHookItem = (CHookItem*) malloc( m_NbrItems * sizeof( CHookItem ) );
  61. else
  62. m_pHookItem = (CHookItem*) realloc( m_pHookItem, m_NbrItems * sizeof( CHookItem ) );
  63. memcpy( m_pHookItem, &Item, sizeof( CHookItem ) );
  64. return FALSE;
  65. }
  66. CHookItem * CHookList::GetItem( HWND hWnd )
  67. {
  68. for( UINT i=0; i<m_NbrItems; i++ )
  69. {
  70. if ( m_pHookItem[i].m_hWnd == hWnd )
  71. return &m_pHookItem[i];
  72. }
  73. return NULL;
  74. }
  75. BOOL CHookList::DelItem( HWND hWnd )
  76. {
  77. BOOL RetVal = FALSE;
  78. for( UINT i=0; i<m_NbrItems; i++ )
  79. {
  80. if ( m_pHookItem[i].m_hWnd = hWnd )
  81. {
  82. m_NbrItems--;
  83. memcpy( &m_pHookItem[i], &m_pHookItem[i+1], ( m_NbrItems - i ) * sizeof( CHookItem ) );
  84. m_pHookItem = (CHookItem*) realloc( m_pHookItem, m_NbrItems * sizeof( CHookItem ) ); 
  85. }
  86. }
  87. return RetVal;
  88. }
  89. BOOL CHookList::DelAllItems()
  90. {
  91. free( m_pHookItem );
  92. m_pHookItem = NULL;
  93. m_NbrItems  = 0;
  94. return FALSE;
  95. }