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.

153 lines
3.7 KiB

  1. // stdafx.cpp : source file that includes just the standard includes
  2. // stdafx.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4. #include "stdafx.h"
  5. #ifdef _ATL_STATIC_REGISTRY
  6. #include <statreg.h>
  7. #include <statreg.cpp>
  8. #endif
  9. #include <atlimpl.cpp>
  10. HRESULT LoadImages(IImageList* pImageList)
  11. {
  12. HRESULT hr = E_FAIL;
  13. HBITMAP hBitmap16 = LoadBitmap( _Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_Small) );
  14. if (hBitmap16 != NULL)
  15. {
  16. HBITMAP hBitmap32 = LoadBitmap( _Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_Large) );
  17. if (hBitmap32 != NULL)
  18. {
  19. hr = pImageList->ImageListSetStrip( reinterpret_cast<LONG_PTR*>( hBitmap16 ), reinterpret_cast<LONG_PTR*>( hBitmap32 ), 0, RGB(255, 0, 255));
  20. }
  21. }
  22. return hr;
  23. }
  24. tstring StrLoadString(UINT uID)
  25. {
  26. tstring strRet = _T("");
  27. HINSTANCE hInst = _Module.GetResourceInstance();
  28. INT iSize = MAX_PATH;
  29. TCHAR* psz = new TCHAR[iSize];
  30. if( !psz ) return strRet;
  31. while( LoadString(hInst, uID, psz, iSize) == (iSize - 1) )
  32. {
  33. iSize += MAX_PATH;
  34. delete[] psz;
  35. psz = NULL;
  36. psz = new TCHAR[iSize];
  37. if( !psz ) return strRet;
  38. }
  39. strRet = psz;
  40. delete[] psz;
  41. return strRet;
  42. }
  43. void StrGetEditText( HWND hWndParent, UINT uID, tstring& strRet )
  44. {
  45. if( !hWndParent ||
  46. !IsWindow(hWndParent) )
  47. {
  48. strRet = _T("");
  49. return;
  50. }
  51. INT iLen = SendDlgItemMessage( hWndParent, uID, WM_GETTEXTLENGTH, 0, 0 );
  52. TCHAR* pszText = new TCHAR[ iLen + 1 ];
  53. if( !pszText )
  54. {
  55. strRet = _T("");
  56. return;
  57. }
  58. GetDlgItemText( hWndParent, uID, pszText, iLen + 1 );
  59. strRet = pszText;
  60. SecureZeroMemory( pszText, sizeof(TCHAR)*(iLen + 1) );
  61. delete[] pszText;
  62. }
  63. void DisplayError(HWND hWnd, LPCTSTR pszMessage, LPCTSTR pszTitle, HRESULT hrErr )
  64. {
  65. LPVOID lpMsgBuf = NULL;
  66. tstring strMessage = pszMessage;
  67. if ( ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  68. FORMAT_MESSAGE_FROM_SYSTEM |
  69. FORMAT_MESSAGE_IGNORE_INSERTS,
  70. NULL,
  71. hrErr,
  72. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  73. (LPTSTR)&lpMsgBuf,
  74. 0,
  75. NULL ))
  76. {
  77. strMessage += (LPTSTR)lpMsgBuf;
  78. LocalFree( lpMsgBuf );
  79. }
  80. else
  81. {
  82. tstring strTemp = StrLoadString( IDS_ERROR_UNSPECIFIED );
  83. strMessage += strTemp;
  84. }
  85. // Output the Messagebox
  86. ::MessageBox( hWnd, strMessage.c_str(), pszTitle, MB_OK | MB_ICONWARNING );
  87. }
  88. BOOL Prefix_EnableWindow( HWND hDlg, UINT uCtrlID, BOOL bEnable )
  89. {
  90. if ((NULL == hDlg) || !IsWindow( hDlg ))
  91. return FALSE;
  92. HWND h = 0;
  93. if (uCtrlID)
  94. {
  95. h = GetDlgItem( hDlg, uCtrlID );
  96. if( !h || !::IsWindow(h) )
  97. return FALSE;
  98. }
  99. else
  100. h = hDlg;
  101. return ::EnableWindow( h, bEnable );
  102. }
  103. BOOL IsAdmin()
  104. {
  105. // Verify Permissions
  106. PSID psid = NULL;
  107. SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
  108. BOOL bRet = AllocateAndInitializeSid( &sia,
  109. 2,
  110. SECURITY_BUILTIN_DOMAIN_RID,
  111. DOMAIN_ALIAS_RID_ADMINS,
  112. 0, 0, 0, 0, 0, 0,
  113. &psid);
  114. if( !bRet )
  115. {
  116. return FALSE;
  117. }
  118. else if( !psid )
  119. {
  120. return FALSE;
  121. }
  122. if( !CheckTokenMembership(NULL, psid, &bRet) )
  123. {
  124. return FALSE;
  125. }
  126. FreeSid( psid );
  127. return bRet;
  128. }