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.

163 lines
3.9 KiB

  1. //==========================================================================
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright 1998 - 1999 Microsoft Corporation. All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------
  11. // just some stuff to help out.
  12. #include "precomp.h"
  13. //+---------------------------------------------------------------------------
  14. //
  15. // Function: CalcListViewWidth, public
  16. //
  17. // Synopsis: Given a ListView determines width of client size
  18. // subtracting off the scrollbar.
  19. //
  20. // Arguments:
  21. //
  22. // Returns:
  23. //
  24. // Modifies:
  25. //
  26. //----------------------------------------------------------------------------
  27. int CalcListViewWidth(HWND hwndList,int iDefault)
  28. {
  29. NONCLIENTMETRICSA metrics;
  30. RECT rcClientRect;
  31. metrics.cbSize = sizeof(metrics);
  32. // explicitly ask for ANSI version of SystemParametersInfo since we just
  33. // care about the ScrollWidth and don't want to conver the LOGFONT info.
  34. if (GetClientRect(hwndList,&rcClientRect)
  35. && SystemParametersInfoA(SPI_GETNONCLIENTMETRICS,sizeof(metrics),(PVOID) &metrics,0))
  36. {
  37. // subtract off scroll bar distance
  38. rcClientRect.right -= (metrics.iScrollWidth);
  39. }
  40. else
  41. {
  42. rcClientRect.right = iDefault; // if fail, use default
  43. }
  44. return rcClientRect.right;
  45. }
  46. //+---------------------------------------------------------------------------
  47. //
  48. // Function: IsValidDir, public
  49. //
  50. // Synopsis: Determines pDirName is a valid fullpath to a directory.
  51. //
  52. // Arguments:
  53. //
  54. // Returns:
  55. //
  56. // Modifies:
  57. //
  58. //----------------------------------------------------------------------------
  59. BOOL IsValidDir(TCHAR *pDirName)
  60. {
  61. BOOL fReturn = FALSE;
  62. HANDLE hFind;
  63. WIN32_FIND_DATA finddata;
  64. hFind = FindFirstFile(pDirName, &finddata);
  65. if (hFind != (HANDLE) -1)
  66. {
  67. fReturn = (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? TRUE : FALSE;
  68. FindClose(hFind);
  69. }
  70. return fReturn;
  71. }
  72. //+---------------------------------------------------------------------------
  73. //
  74. // Function: FormatDateTime, public
  75. //
  76. // Synopsis: Formats the filetime into a string.
  77. //
  78. // Arguments:
  79. //
  80. // Returns:
  81. //
  82. // Modifies:
  83. //
  84. //----------------------------------------------------------------------------
  85. TCHAR *FormatDateTime(FILETIME *pft,TCHAR *pszDatetimeBuf,DWORD cbBufSize)
  86. {
  87. TCHAR * pDateTime = pszDatetimeBuf;
  88. int cchWritten;
  89. SYSTEMTIME sysTime;
  90. FILETIME ftLocal;
  91. FileTimeToLocalFileTime(pft,&ftLocal);
  92. FileTimeToSystemTime(&ftLocal,&sysTime);
  93. // insert date in form of date<space>hour
  94. *pDateTime = NULL;
  95. // want to insert the date
  96. if (cchWritten = GetDateFormat(NULL,DATE_SHORTDATE,&sysTime,NULL,pDateTime,cbBufSize))
  97. {
  98. pDateTime += (cchWritten -1); // move number of characters written. (cchWritten includes the NULL)
  99. *pDateTime = TEXT(' '); // pDateTime is now ponting at the NULL character.
  100. ++pDateTime;
  101. // no try to get the hours if fails we make sure that the last char is NULL;
  102. if (!GetTimeFormat(NULL,TIME_NOSECONDS,&sysTime,NULL,pDateTime,cbBufSize - cchWritten))
  103. {
  104. *pDateTime = NULL;
  105. }
  106. }
  107. return pszDatetimeBuf;
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // Function: lstrcpyX, public
  112. //
  113. // Synopsis: Implements WideChar strcpy so can use on Win9x
  114. //
  115. // Arguments:
  116. //
  117. // Returns:
  118. //
  119. // Modifies:
  120. //
  121. //----------------------------------------------------------------------------
  122. LPWSTR lstrcpyX(
  123. LPWSTR lpString1,
  124. LPCWSTR lpString2
  125. )
  126. {
  127. LPWSTR lpDest = lpString1;
  128. Assert(lpString1);
  129. Assert(lpString2);
  130. while( *lpDest++ = *lpString2++ )
  131. ;
  132. return lpString1;
  133. }