lvutil.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "shellprv.h"
  2. #pragma  hdrstop
  3. //========================================================================
  4. // ScreenToLV & ClientToLV
  5. //========================================================================
  6. // convert screen coords to listview view coordinates
  7. // convert listview client window coords into listview view coordinates
  8. void LVUtil_ClientToLV(HWND hwndLV, LPPOINT ppt)
  9. {
  10.     POINT ptOrigin;
  11.     if (!ListView_GetOrigin(hwndLV, &ptOrigin))
  12.         return;
  13.     ppt->x += ptOrigin.x;
  14.     ppt->y += ptOrigin.y;
  15. }
  16. void LVUtil_ScreenToLV(HWND hwndLV, LPPOINT ppt)
  17. {
  18.     ScreenToClient(hwndLV, ppt);
  19.     LVUtil_ClientToLV(hwndLV, ppt);
  20. }
  21. // convert listview client window coords into listview view coordinates
  22. void LVUtil_LVToClient(HWND hwndLV, LPPOINT ppt)
  23. {
  24.     POINT ptOrigin;
  25.     if (!ListView_GetOrigin(hwndLV, &ptOrigin))
  26.         return;
  27.     ppt->x -= ptOrigin.x;
  28.     ppt->y -= ptOrigin.y;
  29. }
  30. //
  31. // Parameters:
  32. //  hwndLV      -- Specifies the listview window
  33. //  nItem       -- Specifies the item to be altered
  34. //  uState      -- Specifies the new state of the item
  35. //  uMask       -- Specifies the state mask
  36. //
  37. void LVUtil_DragSetItemState(HWND hwndLV, int nItem, UINT uState, UINT uMask)
  38. {
  39.     // check the state to see if it is already as we want to avoid
  40.     // flashing while dragging
  41.     if (ListView_GetItemState(hwndLV, nItem, uMask) != (uState & uMask))
  42.     {
  43.         DAD_ShowDragImage(FALSE);
  44.         ListView_SetItemState(hwndLV, nItem, uState, uMask);
  45.         UpdateWindow(hwndLV);   // REVIEW, needed?
  46.         DAD_ShowDragImage(TRUE);
  47.     }
  48. }
  49. void LVUtil_DragSelectItem(HWND hwndLV, int nItem)
  50. {
  51.     int nTemp;
  52.     for (nTemp = ListView_GetItemCount(hwndLV) - 1; nTemp >= 0; --nTemp)
  53.     {
  54.         LVUtil_DragSetItemState(hwndLV, nTemp, nTemp == nItem ? LVIS_DROPHILITED : 0, LVIS_DROPHILITED);
  55.     }
  56. }
  57. // reposition the selected items in a listview by dx, dy
  58. const TCHAR c_szRegPathCustomPrefs[] =
  59.     TEXT("Software\Microsoft\Windows\CurrentVersion\Explorer\CustomPrefs");
  60. void LVUtil_MoveSelectedItems(HWND hwndLV, int dx, int dy, BOOL fAll)
  61. {
  62.     int iItem;
  63.     POINT pt;
  64.     HKEY  hKey;
  65.     DWORD dwType;
  66.     DWORD dwGrid;
  67.     DWORD dwSize = SIZEOF(dwGrid);
  68.     UINT  uiFlags = (fAll ? LVNI_ALL : LVNI_SELECTED);
  69.     SendMessage(hwndLV, WM_SETREDRAW, FALSE, 0L);
  70.     for (iItem = ListView_GetNextItem(hwndLV, -1, uiFlags);
  71.          iItem >= 0;
  72.          iItem = ListView_GetNextItem(hwndLV, iItem, uiFlags)) {
  73.         ListView_GetItemPosition(hwndLV, iItem, &pt);
  74.     pt.x += dx;
  75.     pt.y += dy;
  76.     //
  77.     // Adjust the drop point to correspond to line up on the drop grid,
  78.     // if the user has the custom prefs setting for "DropGrid"
  79.     //
  80.     if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER,
  81.                                     c_szRegPathCustomPrefs,
  82.                                     &hKey))
  83.     {
  84.         if (ERROR_SUCCESS == SHQueryValueEx(hKey,
  85.                                              TEXT("DropGrid"),
  86.                                              NULL,
  87.                                              &dwType,
  88.                                              (LPBYTE) &dwGrid,
  89.                                              &dwSize))
  90.         {
  91.             pt.x += (dwGrid / 2);
  92.             pt.y += (dwGrid / 2);
  93.             pt.x -= pt.x % dwGrid;
  94.             pt.y -= pt.y % dwGrid;
  95.         }
  96.         RegCloseKey(hKey);
  97.     }
  98.         ListView_SetItemPosition32(hwndLV, iItem, pt.x, pt.y);
  99.     }
  100.     SendMessage(hwndLV, WM_SETREDRAW, TRUE, 0L);
  101. }
  102. //
  103. // Note that it returns NULL, if iItem is -1.
  104. //
  105. LPARAM LVUtil_GetLParam(HWND hwndLV, int i)
  106. {
  107.     LV_ITEM item;
  108.     item.mask = LVIF_PARAM;
  109.     item.iItem = i;
  110.     item.iSubItem = 0;
  111.     item.lParam = 0;
  112.     if (i != -1)
  113.     {
  114.         ListView_GetItem(hwndLV, &item);
  115.     }
  116.     return item.lParam;
  117. }