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.

206 lines
6.5 KiB

  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // Utils.h
  4. //
  5. // General-purpose windows utilities routines.
  6. //
  7. // HISTORY
  8. // t-danmo 96.09.22 Creation.
  9. //
  10. /////////////////////////////////////////////////////////////////////
  11. #ifndef __UTILS_H__
  12. #define __UTILS_H__
  13. extern HINSTANCE g_hInstanceSave; // Instance handle of the DLL (initialized during CFileMgmtComponent::Initialize)
  14. HRESULT
  15. GetErrorMessage(
  16. IN DWORD i_dwError,
  17. OUT CString& cstrErrorMsg
  18. );
  19. void mystrtok(
  20. IN LPCTSTR pszString,
  21. IN OUT int* pnIndex, // start from 0
  22. IN LPCTSTR pszCharSet,
  23. OUT CString& strToken
  24. );
  25. BOOL IsInvalidSharename(LPCTSTR psz);
  26. /////////////////////////////////////////////////////////////////////
  27. // Structure used to add items to a listbox or combobox.
  28. //
  29. struct TStringParamEntry // spe
  30. {
  31. UINT uStringId; // Id of the resource string
  32. LPARAM lItemData; // Optional parameter for the string (stored in lParam field)
  33. };
  34. void ComboBox_FlushContent(HWND hwndCombo);
  35. BOOL ComboBox_FFill(
  36. const HWND hwndCombo, // IN: Handle of the combobox
  37. const TStringParamEntry rgzSPE[], // IN: SPE aray zero terminated
  38. const LPARAM lItemDataSelect); // IN: Which item to select
  39. LPARAM ComboBox_GetSelectedItemData(HWND hwndComboBox);
  40. HWND HGetDlgItem(HWND hdlg, INT nIdDlgItem);
  41. void SetDlgItemFocus(HWND hdlg, INT nIdDlgItem);
  42. void EnableDlgItem(HWND hdlg, INT nIdDlgItem, BOOL fEnable);
  43. void EnableDlgItemGroup(
  44. HWND hdlg,
  45. const UINT rgzidCtl[],
  46. BOOL fEnable);
  47. void ShowDlgItemGroup(
  48. HWND hdlg,
  49. const UINT rgzidCtl[],
  50. BOOL fShowAll);
  51. TCHAR * Str_PchCopyChN(
  52. TCHAR * szDst, // OUT: Destination buffer
  53. CONST TCHAR * szSrc, // IN: Source buffer
  54. TCHAR chStop, // IN: Character to stop the copying
  55. INT cchDstMax); // IN: Length of the output buffer
  56. INT Str_SubstituteStrStr(
  57. TCHAR * szDst, // OUT: Destination buffer
  58. CONST TCHAR * szSrc, // IN: Source buffer
  59. CONST TCHAR * szToken, // IN: Token to find
  60. CONST TCHAR * szReplace); // IN: Token to replace
  61. TCHAR * PchParseCommandLine(
  62. CONST TCHAR szFullCommand[], // IN: Full command line
  63. TCHAR szBinPath[], // OUT: Path of the executable binary
  64. INT cchBinPathBuf); // IN: Size of the buffer
  65. void TrimString(CString& rString);
  66. /////////////////////////////////////////////////////////////////////
  67. struct TColumnHeaderItem
  68. {
  69. UINT uStringId; // Resource Id of the string
  70. INT nColWidth; // % of total width of the column (0 = autowidth, -1 = fill rest of space)
  71. };
  72. void ListView_AddColumnHeaders(
  73. HWND hwndListview,
  74. const TColumnHeaderItem rgzColumnHeader[]);
  75. int ListView_InsertItemEx(
  76. HWND hwndListview,
  77. CONST LV_ITEM * pLvItem);
  78. LPTSTR * PargzpszFromPgrsz(CONST LPCTSTR pgrsz, INT * pcStringCount);
  79. BOOL UiGetFileName(HWND hwnd, TCHAR szFileName[], INT cchBufferLength);
  80. //
  81. // Printf-type functions
  82. //
  83. TCHAR * PaszLoadStringPrintf(UINT wIdString, va_list arglist);
  84. void LoadStringPrintf(UINT wIdString, CString * pString, ...);
  85. void SetWindowTextPrintf(HWND hwnd, UINT wIdString, ...);
  86. // If you are looking for MsgBoxPrintf() for slate, go
  87. // take a look at DoErrMsgBox()/DoServicesErrMsgBox() in svcutils.h
  88. // Function LoadStringWithInsertions() is exactly LoadStringPrintf()
  89. #define LoadStringWithInsertions LoadStringPrintf
  90. #ifdef SNAPIN_PROTOTYPER
  91. ///////////////////////////////////////
  92. struct TParseIntegerInfo // pi
  93. {
  94. int nFlags; // IN: Parsing flags
  95. const TCHAR * pchSrc; // IN: Source string
  96. const TCHAR * pchStop; // OUT: Pointer to where the parsing stopped
  97. int nErrCode; // OUT: Error code
  98. UINT uData; // OUT: Integer value
  99. UINT uRangeBegin; // IN: Lowest value for range checking
  100. UINT uRangeEnd; // IN: Highest value for range checking (inclusive)
  101. };
  102. #define PI_mskfDecimalBase 0x0000 // Use decimal base (default)
  103. #define PI_mskfHexBaseOnly 0x0001 // Use hexadecimal base only
  104. #define PI_mskfAllowHexBase 0x0002 // Look for a 0x prefix and select the appropriate base
  105. #define PI_mskfAllowRandomTail 0x0010 // Stop parsing as soon as you reach a non-digit character without returning an error
  106. #define PI_mskfNoEmptyString 0x0020 // Interpret an empty string as an error instead of the value zero
  107. #define PI_mskfNoMinusSign 0x0040 // Interpret the minus sign as an error
  108. #define PI_mskfSingleEntry 0x0080 // Return an error if there are more than one integer
  109. #define PI_mskfCheckRange 0x0100 // NYI: Use uRangeBegin and uRangeEnd to validate uData
  110. #define PI_mskfSilentParse 0x8000 // NYI: Used only when calling GetWindowInteger()
  111. #define PI_errOK 0 // No error
  112. #define PI_errIntegerOverflow 1 // Integer too large
  113. #define PI_errInvalidInteger 2 // String is not a valid integer (typically an invalid digit)
  114. #define PI_errEmptyString 3 // Empty string found while not allowed
  115. #define PI_errMinusSignFound 4 // The number was negative
  116. BOOL FParseInteger(INOUT TParseIntegerInfo * pPI);
  117. ///////////////////////////////////////
  118. typedef struct _SCANF_INFO // Scanf info structure (sfi)
  119. {
  120. const TCHAR * pchSrc; // IN: Source string to be parsed
  121. const TCHAR * pchSrcStop; // OUT: Pointer to where the parsing stopped
  122. int nErrCode; // OUT: Error code
  123. int cArgParsed; // OUT: Number of argument parsed
  124. } SCANF_INFO;
  125. #define SF_errInvalidFormat (-1) // Illegal format
  126. #define SF_errOK 0 // No error parsing
  127. #define SF_errTemplateMismatch 1 // Source string do not match with template string pchFmt
  128. ///////////////////////////////////////////////////////////
  129. BOOL FScanf(INOUT SCANF_INFO * pSFI, IN const TCHAR * pchFmt, OUT ...);
  130. BOOL RegKey_FQueryString(
  131. HKEY hKey,
  132. LPCTSTR pszValueName,
  133. CString& rstrKeyData);
  134. #endif // SNAPIN_PROTOTYPER
  135. class CStartStopHelper : public CComObjectRoot,
  136. public ISvcMgmtStartStopHelper,
  137. public CComCoClass<CStartStopHelper, &CLSID_SvcMgmt>
  138. {
  139. BEGIN_COM_MAP(CStartStopHelper)
  140. COM_INTERFACE_ENTRY(ISvcMgmtStartStopHelper)
  141. END_COM_MAP()
  142. public:
  143. // CStartStopHelper () {}
  144. // ~CStartStopHelper () {}
  145. DECLARE_AGGREGATABLE(CStartStopHelper)
  146. DECLARE_REGISTRY(CStartStopHelper, _T("SVCMGMT.StartStopObject.1"), _T("SVCMGMT.StartStopObject.1"), IDS_SVCVWR_DESC, THREADFLAGS_BOTH)
  147. STDMETHOD(StartServiceHelper)(
  148. HWND hwndParent,
  149. BSTR pszMachineName,
  150. BSTR pszServiceName,
  151. DWORD dwNumServiceArgs,
  152. BSTR * lpServiceArgVectors );
  153. STDMETHOD(ControlServiceHelper)(
  154. HWND hwndParent,
  155. BSTR pszMachineName,
  156. BSTR pszServiceName,
  157. DWORD dwControlCode );
  158. };
  159. DEFINE_GUID(IID_ISvcMgmtStartStopHelper,0xF62DEC25,0xE3CB,0x4D45,0x9E,0x98,0x93,0x3D,0xB9,0x5B,0xCA,0xEA);
  160. #endif // ~__UTILS_H__