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.

170 lines
4.2 KiB

  1. // eventrap.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "eventrap.h"
  5. #include "trapdlg.h"
  6. #include "globals.h"
  7. #include "utils.h"
  8. #include "trapreg.h"
  9. #include "busy.h"
  10. #include "dlgsavep.h"
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CEventrapApp
  13. BEGIN_MESSAGE_MAP(CEventrapApp, CWinApp)
  14. //{{AFX_MSG_MAP(CEventrapApp)
  15. // NOTE - the ClassWizard will add and remove mapping macros here.
  16. // DO NOT EDIT what you see in these blocks of generated code!
  17. //}}AFX_MSG
  18. END_MESSAGE_MAP()
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CEventrapApp construction
  21. CEventrapApp::CEventrapApp()
  22. {
  23. // TODO: add construction code here,
  24. // Place all significant initialization in InitInstance
  25. }
  26. /////////////////////////////////////////////////////////////////////////////
  27. // The one and only CEventrapApp object
  28. CEventrapApp theApp;
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CEventrapApp initialization
  31. LPCTSTR GetNextParam(LPTSTR pszDst, LPCTSTR pszSrc, LONG nchDst)
  32. {
  33. // Skip any leading white space
  34. while((*pszSrc==' ') || (*pszSrc=='\t')) {
  35. ++pszSrc;
  36. }
  37. // Reserve a byte for the null terminator
  38. ASSERT(nchDst >= 1);
  39. --nchDst;
  40. // Copy the next parameter to the destination buffer.
  41. while (nchDst > 0) {
  42. INT iCh = *pszSrc;
  43. if ((iCh == 0) || (iCh==' ') || (iCh=='\t')) {
  44. break;
  45. }
  46. ++pszSrc;
  47. *pszDst++ = (TCHAR)iCh;
  48. --nchDst;
  49. }
  50. *pszDst = 0;
  51. return pszSrc;
  52. }
  53. void ParseParams(CStringArray& asParams, LPCTSTR pszParams)
  54. {
  55. TCHAR szParam[MAX_STRING];
  56. while(pszParams != NULL) {
  57. pszParams = GetNextParam(szParam, pszParams, MAX_STRING);
  58. if (szParam[0] == 0) {
  59. break;
  60. }
  61. asParams.Add(szParam);
  62. }
  63. }
  64. BOOL CEventrapApp::InitInstance()
  65. {
  66. GetThousandSeparator(&g_chThousandSep);
  67. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  68. CStringArray asParams;
  69. ParseParams(asParams, m_lpCmdLine);
  70. SCODE sc;
  71. LPCTSTR pszComputerName = NULL;
  72. switch(asParams.GetSize()) {
  73. case 0:
  74. break;
  75. case 1:
  76. if (!asParams[0].IsEmpty()) {
  77. pszComputerName = asParams[0];
  78. }
  79. break;
  80. default:
  81. AfxMessageBox(IDS_ERR_INVALID_ARGUMENT);
  82. return FALSE;
  83. break;
  84. }
  85. CBusy busy;
  86. g_reg.m_pdlgLoadProgress = new CDlgSaveProgress;
  87. g_reg.m_pdlgLoadProgress->Create(IDD_LOAD_PROGRESS, NULL);
  88. g_reg.m_pdlgLoadProgress->BringWindowToTop();
  89. //if the local machine is the same as
  90. //the machine name passed as an argument
  91. //don't use a machine name.
  92. if (NULL != pszComputerName)
  93. {
  94. TCHAR t_buff[MAX_COMPUTERNAME_LENGTH + 1];
  95. DWORD dwLen = MAX_COMPUTERNAME_LENGTH + 1;
  96. if (GetComputerName(t_buff, &dwLen))
  97. {
  98. if (_tcsicmp(t_buff, pszComputerName) == 0)
  99. {
  100. pszComputerName = NULL;
  101. }
  102. }
  103. }
  104. sc = g_reg.Connect(pszComputerName);
  105. if ((sc==S_LOAD_CANCELED) || FAILED(sc)) {
  106. delete g_reg.m_pdlgLoadProgress;
  107. g_reg.m_pdlgLoadProgress = NULL;
  108. return FALSE;
  109. }
  110. // Read the current event to trap configuration from the registry
  111. sc = g_reg.Deserialize();
  112. if ((sc==S_LOAD_CANCELED) || FAILED(sc)) {
  113. delete g_reg.m_pdlgLoadProgress;
  114. g_reg.m_pdlgLoadProgress = NULL;
  115. return FALSE;
  116. }
  117. CEventTrapDlg* pdlg = new CEventTrapDlg;
  118. m_pMainWnd = pdlg;
  119. pdlg->Create(IDD_EVNTTRAPDLG, NULL);
  120. pdlg->BringWindowToTop();
  121. // Since we are running a modeless dialog, return TRUE so that the message
  122. // pump is run.
  123. return TRUE;
  124. }
  125. int CEventrapApp::ExitInstance()
  126. {
  127. return CWinApp::ExitInstance();
  128. }
  129. BOOL CEventrapApp::ProcessMessageFilter(int code, LPMSG lpMsg)
  130. {
  131. // TODO: Add your specialized code here and/or call the base class
  132. return CWinApp::ProcessMessageFilter(code, lpMsg);
  133. }