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.

209 lines
4.1 KiB

  1. #include "stdafx.h"
  2. #include <cstrinout.h>
  3. //
  4. // Globals
  5. //
  6. DWORD g_dwComCtlIEVersion;
  7. //
  8. //
  9. //
  10. DWORD GetComCtlIEVersion()
  11. {
  12. DWORD dwVersion = 0;
  13. HMODULE hComCtl = LoadLibrary(L"comctl32.dll");
  14. if (hComCtl)
  15. {
  16. HRESULT (*DllGetVersion)(DLLVERSIONINFO* pdvi) = (HRESULT (*)(DLLVERSIONINFO*))GetProcAddress(hComCtl, "DllGetVersion");
  17. if (DllGetVersion)
  18. {
  19. DLLVERSIONINFO dvi;
  20. dvi.cbSize = sizeof(dvi);
  21. DllGetVersion(&dvi);
  22. dwVersion = dvi.dwMajorVersion;
  23. }
  24. else
  25. {
  26. BOOL (*InitCommonControlsEx)(LPINITCOMMONCONTROLSEX) = (BOOL (*)(LPINITCOMMONCONTROLSEX))GetProcAddress(hComCtl, "InitCommonControlsEx");
  27. dwVersion = InitCommonControlsEx ? 3 : 2;
  28. }
  29. FreeLibrary(hComCtl);
  30. }
  31. return dwVersion;
  32. }
  33. LRESULT ListView_InsertColumnWrap(HWND hwnd, int nCol, LVCOLUMN* pCol)
  34. {
  35. LRESULT lRet;
  36. if (g_dwComCtlIEVersion >= 3)
  37. {
  38. lRet = ListView_InsertColumn(hwnd, nCol, pCol);
  39. }
  40. else
  41. {
  42. ASSERT(!(pCol->mask & (LVCF_IMAGE | LVCF_ORDER | LVCF_TEXT)));
  43. lRet = SendMessage(hwnd, LVM_INSERTCOLUMNA, nCol, (LPARAM)pCol);
  44. }
  45. return lRet;
  46. }
  47. void ListView_SetExtendedListViewStyleExWrap(HWND hwnd, DWORD dwMask, DWORD dwStyle)
  48. {
  49. if (g_dwComCtlIEVersion >= 3)
  50. {
  51. ListView_SetExtendedListViewStyleEx(hwnd, dwMask, dwStyle);
  52. }
  53. else
  54. {
  55. }
  56. }
  57. int ListView_InsertItemWrap(HWND hwnd, const LVITEM* pItem)
  58. {
  59. int iRet;
  60. if (g_dwComCtlIEVersion >= 3)
  61. {
  62. iRet = ListView_InsertItem(hwnd, pItem);
  63. }
  64. else
  65. {
  66. if (pItem->mask & LVIF_TEXT)
  67. {
  68. LVITEMA ItemA = *(LVITEMA*)pItem;
  69. CStrIn strText(pItem->pszText);
  70. ItemA.pszText = strText;
  71. iRet = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&ItemA);
  72. }
  73. else
  74. {
  75. iRet = SendMessage(hwnd, LVM_INSERTITEMA, 0, (LPARAM)pItem);
  76. }
  77. }
  78. return iRet;
  79. }
  80. void ListView_SetItemTextWrap(HWND hwnd, int iItem, int iSubItem, LPWSTR pszText)
  81. {
  82. if (g_dwComCtlIEVersion >= 3)
  83. {
  84. ListView_SetItemText(hwnd, iItem, iSubItem, pszText);
  85. }
  86. else
  87. {
  88. CStrIn strText(pszText);
  89. LV_ITEMA ItemA;
  90. ItemA.iSubItem = iSubItem;
  91. ItemA.pszText = strText;
  92. SendMessage(hwnd, LVM_SETITEMTEXTA, iItem, (LPARAM)&ItemA);
  93. }
  94. }
  95. BOOL ListView_SetColumnWidthWrap(HWND hwnd, int iCol, int cx)
  96. {
  97. BOOL fRet;
  98. if (g_dwComCtlIEVersion >= 2)
  99. {
  100. fRet = ListView_SetColumnWidth(hwnd, iCol, cx);
  101. }
  102. else
  103. {
  104. if (LVSCW_AUTOSIZE == cx || LVSCW_AUTOSIZE_USEHEADER == cx)
  105. {
  106. // HACK set to 150 for now.
  107. fRet = ListView_SetColumnWidth(hwnd, iCol, 150);
  108. }
  109. else
  110. {
  111. fRet = ListView_SetColumnWidth(hwnd, iCol, cx);
  112. }
  113. }
  114. return fRet;
  115. }
  116. BOOL ListView_GetItemWrap(HWND hwnd, LVITEM* pItem)
  117. {
  118. BOOL fRet;
  119. if (g_dwComCtlIEVersion >= 3)
  120. {
  121. fRet = ListView_GetItem(hwnd, pItem);
  122. }
  123. else
  124. {
  125. ASSERT (!(pItem->mask & LVIF_TEXT));
  126. fRet = SendMessage(hwnd, LVM_GETITEMA, 0, (LPARAM)pItem);
  127. }
  128. return fRet;
  129. }
  130. BOOL ListView_GetCheckStateWrap(HWND hwnd, UINT iItem)
  131. {
  132. BOOL fRet;
  133. if (g_dwComCtlIEVersion >= 3)
  134. {
  135. fRet = ListView_GetCheckState(hwnd, iItem);
  136. }
  137. else
  138. {
  139. fRet = FALSE;
  140. }
  141. return fRet;
  142. }
  143. void ListView_SetCheckStateWrap(HWND hwnd, UINT iItem, BOOL fCheck)
  144. {
  145. if (g_dwComCtlIEVersion >= 3)
  146. {
  147. ListView_SetCheckState(hwnd, iItem, fCheck);
  148. }
  149. else
  150. {
  151. }
  152. }
  153. void ListView_GetItemTextWrap(HWND hwnd, int iItem, int iSubItem, WCHAR* pszText, int cchText)
  154. {
  155. if (g_dwComCtlIEVersion >= 3)
  156. {
  157. ListView_GetItemText(hwnd, iItem, iSubItem, pszText, cchText)
  158. }
  159. else
  160. {
  161. CStrOut strText(pszText, cchText);
  162. LVITEMA ItemA;
  163. ItemA.iSubItem = iSubItem;
  164. ItemA.pszText = strText;
  165. ItemA.cchTextMax = strText.BufSize();
  166. SendMessage(hwnd, LVM_GETITEMTEXTA, iItem, (LPARAM)&ItemA);
  167. }
  168. }