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.

134 lines
4.4 KiB

  1. //=--------------------------------------------------------------------------=
  2. // Util.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1997 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // contains utilities that we will find useful.
  13. //
  14. #ifndef _UTIL_H_
  15. //=--------------------------------------------------------------------------=
  16. // miscellaneous [useful] numerical constants
  17. //=--------------------------------------------------------------------------=
  18. //=--------------------------------------------------------------------------=
  19. // allocates a temporary buffer that will disappear when it goes out of scope
  20. // NOTE: be careful of that -- make sure you use the string in the same or
  21. // nested scope in which you created this buffer. people should not use this
  22. // class directly. use the macro(s) below.
  23. //
  24. class TempBuffer {
  25. public:
  26. TempBuffer(ULONG cBytes) {
  27. m_pBuf = (cBytes <= 120) ? &m_szTmpBuf : lcMalloc(cBytes);
  28. m_fHeapAlloc = (cBytes > 120);
  29. }
  30. ~TempBuffer() {
  31. if (m_pBuf && m_fHeapAlloc)
  32. lcFree(m_pBuf);
  33. }
  34. void *GetBuffer() {
  35. return m_pBuf;
  36. }
  37. private:
  38. void *m_pBuf;
  39. // we'll use this temp buffer for small cases.
  40. //
  41. char m_szTmpBuf[120];
  42. unsigned m_fHeapAlloc:1;
  43. };
  44. //=--------------------------------------------------------------------------=
  45. // string helpers.
  46. //
  47. // given and ANSI String, copy it into a wide buffer.
  48. // be careful about scoping when using this macro!
  49. //
  50. // how to use the below two macros:
  51. //
  52. // ...
  53. // LPSTR pszA;
  54. // pszA = MyGetAnsiStringRoutine();
  55. // MAKE_WIDEPTR_FROMANSI(pwsz, pszA);
  56. // MyUseWideStringRoutine(pwsz);
  57. // ...
  58. //
  59. // similarily for MAKE_ANSIPTR_FROMWIDE. note that the first param does not
  60. // have to be declared, and no clean up must be done.
  61. //
  62. #define MAKE_WIDEPTR_FROMANSI(ptrname, ansistr) \
  63. long __l##ptrname = (lstrlen(ansistr) + 1) * sizeof(WCHAR); \
  64. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  65. MultiByteToWideChar(CP_ACP, 0, ansistr, -1, (LPWSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname); \
  66. LPWSTR ptrname = (LPWSTR)__TempBuffer##ptrname.GetBuffer()
  67. #define MAKE_ANSIPTR_FROMWIDE(ptrname, widestr) \
  68. long __l##ptrname = (lstrlenW(widestr) + 1) * sizeof(WCHAR); \
  69. TempBuffer __TempBuffer##ptrname(__l##ptrname); \
  70. WideCharToMultiByte(CP_ACP, 0, widestr, -1, (LPSTR)__TempBuffer##ptrname.GetBuffer(), __l##ptrname, NULL, NULL); \
  71. LPSTR ptrname = (LPSTR)__TempBuffer##ptrname.GetBuffer()
  72. BOOL NoRun( void );
  73. BOOL IsFile( LPCSTR lpszPathname );
  74. BOOL IsDirectory( LPCSTR lpszPathname );
  75. void __cdecl SplitPath (
  76. register const char *path,
  77. char *drive,
  78. char *dir,
  79. char *fname,
  80. char *ext
  81. );
  82. // Normalize the URL by stripping off protocol, storage type, storage name goo from the URL then make sure
  83. // we only have forward slashes.
  84. void NormalizeUrlInPlace(LPSTR szURL) ;
  85. // Get the moniker for the filename. For a col, its the moniker of the master chm.
  86. bool NormalizeFileName(CStr& cszFileName) ;
  87. void QRect(HDC hdc, INT x, INT y, INT cx, INT cy, INT color);
  88. // To create a global window type, use the following prefix.
  89. const char GLOBAL_WINDOWTYPE_PREFIX[] = "$global_" ;
  90. const wchar_t GLOBAL_WINDOWTYPE_PREFIX_W[] = L"$global_" ;
  91. // Hack for Office.
  92. const char GLOBAL_WINDOWTYPE_PREFIX_OFFICE[] = "MSO_Small" ;
  93. const wchar_t GLOBAL_WINDOWTYPE_PREFIX_OFFICE_W[] = L"MSO_Small" ;
  94. // Determine if the wintype is a global wintype.
  95. bool IsGlobalWinType(const char* szType) ;
  96. // Determine if the wintype is a global wintype.
  97. bool IsGlobalWinTypeW(LPCWSTR szType) ;
  98. // Checks for the http: reference. Assumes its a URL if this exists.
  99. inline bool
  100. IsHttp(const char* szUrl)
  101. {
  102. if (szUrl)
  103. return (stristr(szUrl, txtHttpHeader) != 0); // Is this a internet URL?
  104. else
  105. return false;
  106. }
  107. ///////////////////////////////////////////////////////////
  108. //
  109. // NT Keyboard hidden UI support functions.
  110. //
  111. void UiStateInitialize(HWND hwnd) ;
  112. void UiStateChangeOnTab(HWND hwnd) ;
  113. void UiStateChangeOnAlt(HWND hwnd) ;
  114. #define _UTIL_H_
  115. #endif // _UTIL_H_