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.

294 lines
6.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991-1996 **/
  4. /**********************************************************************/
  5. /*
  6. stdafx.cpp
  7. Romaine.cpp : Defines the class behaviors for the application.
  8. FILE HISTORY:
  9. jony Apr-1996 created
  10. */
  11. #include "stdafx.h"
  12. #include "NetTree.h"
  13. #include "Romaine.h"
  14. #include "Welcome.h"
  15. #include "Where.h"
  16. #include "Type.h"
  17. #include "What.h"
  18. #include "userlist.h"
  19. #include "LUsers.h"
  20. #include "GUsers.h"
  21. #include "finish.h"
  22. #include "ExGrp.h"
  23. #include "LRem.h"
  24. #include <winreg.h>
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. TCHAR pszTreeEvent[] = _T("TreeThread");
  31. extern int ClassifyMachine(CString& csMachine);
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CRomaineApp
  34. BEGIN_MESSAGE_MAP(CRomaineApp, CWinApp)
  35. //{{AFX_MSG_MAP(CRomaineApp)
  36. //}}AFX_MSG
  37. // ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CRomaineApp construction
  41. CRomaineApp::CRomaineApp()
  42. {
  43. bRestart1 = FALSE;
  44. bRestart2 = FALSE;
  45. // get our primary domain and save it for NETTREE
  46. DWORD dwRet;
  47. HKEY hKey;
  48. DWORD cbProv = 0;
  49. TCHAR* lpProv = NULL;
  50. CRomaineApp* pApp = (CRomaineApp*)AfxGetApp();
  51. dwRet = RegOpenKey(HKEY_LOCAL_MACHINE,
  52. TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hKey );
  53. TCHAR* lpPrimaryDomain = NULL;
  54. if ((dwRet = RegQueryValueEx( hKey, TEXT("CachePrimaryDomain"), NULL, NULL, NULL, &cbProv )) == ERROR_SUCCESS)
  55. {
  56. lpPrimaryDomain = (TCHAR*)malloc(cbProv);
  57. if (lpPrimaryDomain == NULL)
  58. {
  59. AfxMessageBox(IDS_GENERIC_NO_HEAP, MB_ICONEXCLAMATION);
  60. exit(1);
  61. }
  62. dwRet = RegQueryValueEx( hKey, TEXT("CachePrimaryDomain"), NULL, NULL, (LPBYTE) lpPrimaryDomain, &cbProv );
  63. }
  64. RegCloseKey(hKey);
  65. pApp->m_csCurrentDomain = lpPrimaryDomain;
  66. // store the machine name too
  67. CString csMachineName;
  68. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  69. GetComputerName(csMachineName.GetBufferSetLength(MAX_COMPUTERNAME_LENGTH + 1), &dwSize);
  70. pApp->m_csCurrentMachine = "\\\\";
  71. pApp->m_csCurrentMachine += csMachineName;
  72. free(lpPrimaryDomain);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. // The one and only CRomaineApp object
  76. CRomaineApp theApp;
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CRomaineApp initialization
  79. BOOL CRomaineApp::IsSecondInstance()
  80. {
  81. HANDLE hSem;
  82. //create a semaphore object with max count of 1
  83. hSem = CreateSemaphore(NULL, 0, 1, L"Group Wizard Semaphore");
  84. if (hSem!=NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
  85. CloseHandle(hSem);
  86. CString csAppName;
  87. csAppName.LoadString(AFX_IDS_APP_TITLE);
  88. CWnd* pWnd = CWnd::FindWindow(NULL, (LPCTSTR)csAppName);
  89. if (pWnd)
  90. pWnd->SetForegroundWindow();
  91. return TRUE;
  92. }
  93. return FALSE;
  94. }
  95. BOOL CRomaineApp::InitInstance()
  96. {
  97. // check for OS version
  98. OSVERSIONINFO os;
  99. os.dwOSVersionInfoSize = sizeof(os);
  100. GetVersionEx(&os);
  101. if (os.dwMajorVersion < 4)
  102. {
  103. AfxMessageBox(IDS_BAD_VERSION, MB_ICONSTOP);
  104. ExitProcess(0);
  105. }
  106. if (IsSecondInstance())
  107. return FALSE;
  108. // if there is a directory name on the command line, load an extra class
  109. if (m_lpCmdLine[0] != '\0')
  110. {
  111. m_csCmdLine = m_lpCmdLine;
  112. m_sCmdLine = __argc;
  113. TCHAR* pFolder = _tcstok(m_lpCmdLine, L" ");
  114. if (_tcsicmp(pFolder, L"/folder")) return FALSE; // anything else on the cmdline and boot it out
  115. m_sMode = 1;
  116. if (m_sCmdLine == 3)
  117. {
  118. TCHAR* pParam3 = _tcstok(NULL, L" ");
  119. if (*(pParam3 + 1) == 'g')
  120. {
  121. pParam3+=3;
  122. m_csCmdLineGroupName = pParam3;
  123. }
  124. else
  125. {
  126. pParam3+=3;
  127. m_csServer = pParam3;
  128. if (ClassifyMachine(m_csServer) == -1) ExitProcess(1);
  129. }
  130. }
  131. if (m_sCmdLine == 4)
  132. {
  133. TCHAR* pParam3 = _tcstok(NULL, L" ");
  134. TCHAR* pParam4 = _tcstok(NULL, L" ");
  135. if (*(pParam3 + 1) == 'g')
  136. {
  137. pParam3+=3;
  138. pParam4+=3;
  139. m_csCmdLineGroupName = pParam3;
  140. m_csServer = pParam4;
  141. }
  142. else
  143. {
  144. pParam3+=3;
  145. pParam4+=3;
  146. m_csServer = pParam3;
  147. m_csCmdLineGroupName = pParam4;
  148. }
  149. if (ClassifyMachine(m_csServer) == -1) ExitProcess(1);
  150. }
  151. }
  152. #ifdef _AFXDLL
  153. Enable3dControls(); // Call this when using MFC in a shared DLL
  154. #else
  155. Enable3dControlsStatic(); // Call this when linking to MFC statically
  156. #endif
  157. // create the property sheet,set 'wizmode' & set app icon
  158. m_cps1.SetTitle(TEXT("Group Management Wizard"), 0);
  159. m_cps1.SetWizardMode();
  160. CWelcome* pWelcome = new CWelcome;
  161. CLRem* pLRem = new CLRem;
  162. CWhere* pWhere = new CWhere;
  163. CType* pType = new CType;
  164. CWhat* pWhat = new CWhat;
  165. CExGrp* pEx = new CExGrp;
  166. CLUsers* pLUsers = new CLUsers;
  167. CGUsers* pGUsers = new CGUsers;
  168. CFinish* pFinish = new CFinish;
  169. // add pages
  170. m_cps1.AddPage(pEx);
  171. m_cps1.AddPage(pWelcome);
  172. m_cps1.AddPage(pWhat);
  173. m_cps1.AddPage(pLRem);
  174. m_cps1.AddPage(pWhere);
  175. m_cps1.AddPage(pType);
  176. m_cps1.AddPage(pLUsers);
  177. m_cps1.AddPage(pGUsers);
  178. m_cps1.AddPage(pFinish);
  179. // show the wizard
  180. if (m_csServer != L"") m_cps1.SetActivePage(0);
  181. else m_cps1.SetActivePage(1);
  182. m_cps1.DoModal();
  183. // clean up
  184. delete pWelcome;
  185. delete pWhere;
  186. delete pLRem;
  187. delete pType;
  188. delete pWhat;
  189. delete pLUsers;
  190. delete pGUsers;
  191. delete pFinish;
  192. delete pEx;
  193. return FALSE;
  194. }
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CMySheet
  197. IMPLEMENT_DYNAMIC(CMySheet, CPropertySheet)
  198. CMySheet::CMySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  199. :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  200. {
  201. }
  202. CMySheet::CMySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  203. :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  204. {
  205. }
  206. CMySheet::CMySheet() : CPropertySheet()
  207. {
  208. }
  209. CMySheet::~CMySheet()
  210. {
  211. }
  212. BEGIN_MESSAGE_MAP(CMySheet, CPropertySheet)
  213. //{{AFX_MSG_MAP(CMySheet)
  214. ON_WM_CREATE()
  215. //}}AFX_MSG_MAP
  216. END_MESSAGE_MAP()
  217. /////////////////////////////////////////////////////////////////////////////
  218. // CMySheet message handlers
  219. BOOL CMySheet::OnInitDialog()
  220. {
  221. CRomaineApp* pApp = (CRomaineApp*)AfxGetApp();
  222. HICON hIcon = LoadIcon(pApp->m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  223. ::SetClassLong(m_hWnd, GCL_HICON, (long)hIcon);
  224. return CPropertySheet::OnInitDialog();
  225. }
  226. int CMySheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
  227. {
  228. if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
  229. return -1;
  230. // lpCreateStruct->style = WS_OVERLAPPEDWINDOW;
  231. return 0;
  232. }