ImageListUtil.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:2k
源码类别:

状态条

开发平台:

C#

  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UtilityLibrary.Win32;
  4. namespace UtilityLibrary.General
  5. {
  6. /// <summary>
  7. /// Summary description for ImageListUtil.
  8. /// </summary>
  9. public class ImageListUtil : IDisposable
  10. {
  11. #region Class Variables
  12. IntPtr handle = IntPtr.Zero;
  13. const int IMAGELIST_GROW = 10;
  14. #endregion
  15.         
  16. #region Constructors
  17. public ImageListUtil(int width, int height, uint flags, int count)
  18. {
  19. // Initialize CommonLibrary 
  20. WindowsAPI.InitCommonControls();
  21. // Create imageList
  22.             handle = WindowsAPI.ImageList_Create(width, height, flags, count, IMAGELIST_GROW);                        
  23. }
  24. public void Dispose()
  25. {
  26. // Destroy image list
  27. if ( handle != IntPtr.Zero )
  28. {
  29. WindowsAPI.ImageList_Destroy(handle);
  30. }
  31.             
  32. }
  33. #endregion
  34. #region Methods
  35. public void AddImage(IntPtr hBitmap, IntPtr hMask)
  36. {
  37. int rc = WindowsAPI.ImageList_Add(handle, hBitmap, hMask);
  38. }
  39.         
  40. public void RemoveImage(int index)
  41. {
  42. WindowsAPI.ImageList_Remove(handle, index);
  43. }
  44. public void BeginDrag(int imageIndex, int xHotSpot, int yHotSpot)
  45. {
  46.             WindowsAPI.ImageList_BeginDrag(handle, imageIndex, xHotSpot, yHotSpot);
  47. }
  48.         
  49. public void DragEnter(IntPtr hWndLock, int x, int y)
  50. {
  51. WindowsAPI.ImageList_DragEnter(hWndLock, x, y);
  52. }
  53. public void DragMove(int x, int y)
  54. {
  55. WindowsAPI.ImageList_DragMove(x, y);
  56. }
  57. public void DragLeave(IntPtr hWndLock)
  58. {
  59. WindowsAPI.ImageList_DragLeave(hWndLock);
  60. }
  61. public void EndDrag()
  62. {
  63. WindowsAPI.ImageList_EndDrag();
  64. }
  65.         #endregion
  66. }
  67. }