Leaked source code of windows server 2003
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.

227 lines
5.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: tfc.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <pch.cpp>
  11. #pragma hdrstop
  12. #include "tfc.h"
  13. #include <stdarg.h>
  14. #define __dwFILE__ __dwFILE_CERTLIB_TFC_CPP__
  15. extern HINSTANCE g_hInstance;
  16. BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
  17. {
  18. WCHAR szMessage[_MAX_PATH*2];
  19. // format message into buffer
  20. wsprintf(szMessage, L"File %hs, Line %d\n",
  21. lpszFileName, nLine);
  22. OutputDebugString(szMessage);
  23. int iCode = MessageBox(NULL, szMessage, L"Assertion Failed!",
  24. MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
  25. if (iCode == IDIGNORE)
  26. return FALSE;
  27. if (iCode == IDRETRY)
  28. return TRUE;
  29. // abort!
  30. ExitProcess(0);
  31. // NOTREACHED return FALSE;
  32. }
  33. //////////////////////////////////////////////////////////////////////////////////
  34. //////////////////////////////////////////////////////////////////////////////////
  35. // CBitmap
  36. //////////////////////////////////////////////////////////////////////////////////
  37. //////////////////////////////////////////////////////////////////////////////////
  38. CBitmap::CBitmap()
  39. {
  40. m_hBmp = NULL;
  41. }
  42. CBitmap::~CBitmap()
  43. {
  44. if(m_hBmp)
  45. DeleteObject(m_hBmp);
  46. m_hBmp = NULL;
  47. }
  48. HBITMAP CBitmap::LoadBitmap(UINT iRsc)
  49. {
  50. m_hBmp = (HBITMAP)LoadImage(g_hInstance, MAKEINTRESOURCE(iRsc), IMAGE_BITMAP, 0, 0, 0);
  51. return m_hBmp;
  52. }
  53. //////////////////////////////////////////////////////////////////////////////////
  54. //////////////////////////////////////////////////////////////////////////////////
  55. // CComboBox
  56. //////////////////////////////////////////////////////////////////////////////////
  57. //////////////////////////////////////////////////////////////////////////////////
  58. void CComboBox::Init(HWND hWnd)
  59. {
  60. m_hWnd = hWnd;
  61. }
  62. void CComboBox::ResetContent()
  63. {
  64. ASSERT(m_hWnd);
  65. SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0);
  66. }
  67. int CComboBox::SetItemData(int idx, DWORD dwData)
  68. {
  69. ASSERT(m_hWnd);
  70. return (INT)SendMessage(m_hWnd, CB_SETITEMDATA, (WPARAM)idx, (LPARAM)dwData);
  71. }
  72. DWORD CComboBox::GetItemData(int idx)
  73. {
  74. ASSERT(m_hWnd);
  75. return (DWORD)SendMessage(m_hWnd, CB_GETITEMDATA, (WPARAM)idx, 0);
  76. }
  77. int CComboBox::AddString(LPWSTR sz)
  78. {
  79. ASSERT(m_hWnd);
  80. return (INT)SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM) sz);
  81. }
  82. int CComboBox::AddString(LPCWSTR sz)
  83. {
  84. return (INT)AddString((LPWSTR)sz);
  85. }
  86. int CComboBox::GetCurSel()
  87. {
  88. ASSERT(m_hWnd);
  89. return (INT)SendMessage(m_hWnd, CB_GETCURSEL, 0, 0);
  90. }
  91. int CComboBox::SetCurSel(int iSel)
  92. {
  93. ASSERT(m_hWnd);
  94. return (INT)SendMessage(m_hWnd, CB_SETCURSEL, (WPARAM)iSel, 0);
  95. }
  96. int CComboBox::SelectString(int nAfter, LPCWSTR szItem)
  97. {
  98. ASSERT(m_hWnd);
  99. return (INT)SendMessage(m_hWnd, CB_SELECTSTRING, (WPARAM) nAfter, (LPARAM)szItem);
  100. }
  101. int ListView_NewItem(HWND hList, int iIndex, LPCWSTR szText, LPARAM lParam /* = NULL*/, int iImage /*=-1*/)
  102. {
  103. LVITEM sItem;
  104. ZeroMemory(&sItem, sizeof(sItem));
  105. sItem.iItem = iIndex;
  106. sItem.iImage = iImage;
  107. if (lParam)
  108. {
  109. sItem.mask = LVIF_PARAM;
  110. if(-1!=iImage)
  111. sItem.mask |= LVIF_IMAGE;
  112. sItem.lParam = lParam;
  113. }
  114. sItem.iItem = ListView_InsertItem(hList, &sItem);
  115. ListView_SetItemText(hList, sItem.iItem, 0, (LPWSTR)szText);
  116. return sItem.iItem;
  117. }
  118. int ListView_NewColumn(HWND hwndListView, int iCol, int cx, LPCWSTR szHeading /*=NULL*/, int fmt/*=0*/)
  119. {
  120. LVCOLUMN lvCol;
  121. lvCol.mask = LVCF_WIDTH;
  122. lvCol.cx = cx;
  123. if (szHeading)
  124. {
  125. lvCol.mask |= LVCF_TEXT;
  126. lvCol.pszText = (LPWSTR)szHeading;
  127. }
  128. if (fmt)
  129. {
  130. lvCol.mask |= LVCF_FMT;
  131. lvCol.fmt = fmt;
  132. }
  133. return ListView_InsertColumn(hwndListView, iCol, &lvCol);
  134. }
  135. LPARAM ListView_GetItemData(HWND hListView, int iItem)
  136. {
  137. LVITEM lvItem;
  138. lvItem.iItem = iItem;
  139. lvItem.mask = LVIF_PARAM;
  140. lvItem.iSubItem = 0;
  141. ListView_GetItem(hListView, &lvItem);
  142. return lvItem.lParam;
  143. }
  144. int ListView_GetCurSel(HWND hwndList)
  145. {
  146. int iTot = ListView_GetItemCount(hwndList);
  147. int i=0;
  148. while(i<iTot)
  149. {
  150. if (LVIS_SELECTED == ListView_GetItemState(hwndList, i, LVIS_SELECTED))
  151. break;
  152. i++;
  153. }
  154. return (i<iTot) ? i : -1;
  155. }
  156. void
  157. ListView_SetItemFiletime(
  158. IN HWND hwndList,
  159. IN int iItem,
  160. IN int iColumn,
  161. IN FILETIME const *pft)
  162. {
  163. HRESULT hr;
  164. WCHAR *pwszDateTime = NULL;
  165. // convert filetime to string
  166. hr = myGMTFileTimeToWszLocalTime(pft, FALSE, &pwszDateTime);
  167. if (S_OK != hr)
  168. {
  169. _PrintError(hr, "myGMTFileTimeToWszLocalTime");
  170. }
  171. else
  172. {
  173. ListView_SetItemText(hwndList, iItem, iColumn, pwszDateTime);
  174. }
  175. if (NULL != pwszDateTime)
  176. {
  177. LocalFree(pwszDateTime);
  178. }
  179. }