PZMedical2121Z.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // PZMedical2121Z.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "PZMedical2121Z.h"
  5. #include "PZMedical2121ZDlg.h"
  6. #ifndef _DEBUG
  7. #include ".\\AutoDmp\\AutoDmp.h"
  8. #endif
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////
  13. #include <windows.h>
  14. #include <Dbghelp.h>
  15. #pragma comment( lib, "DbgHelp" )
  16. //////////////////////////////
  17. CString strAppPath;
  18. extern CString strAppDYNHandleName;
  19. extern CString strAppMechCompHandleName;
  20. extern CString strAppRFDTHandleName;
  21. extern CString strAppDRDTHandleName;
  22. extern CString strAppHardwareHandleName;
  23. extern CString strAppRFOCHandleName;
  24. // PZMedical2121ZApp
  25. BEGIN_MESSAGE_MAP(PZMedical2121ZApp, CWinApp)
  26. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  27. END_MESSAGE_MAP()
  28. // PZMedical2121ZApp construction
  29. PZMedical2121ZApp::PZMedical2121ZApp()
  30. {
  31. // support Restart Manager
  32. m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
  33. // TODO: add construction code here,
  34. // Place all significant initialization in InitInstance
  35. }
  36. // The one and only PZMedical2121ZApp object
  37. PZMedical2121ZApp theApp;
  38. // PZMedical2121ZApp initialization
  39. LONG WINAPI UEFilter(PEXCEPTION_POINTERS ExceptionInfo)
  40. {
  41. CString strFileName, strTime;
  42. CTime tm = CTime::GetCurrentTime();
  43. SYSTEMTIME st;
  44. GetSystemTime(&st);
  45. strTime.Format("%04d%02d%02d.%02d%02d%02d%03d", tm.GetYear(), tm.GetMonth(), tm.GetDay(), tm.GetHour(), tm.GetMinute(), tm.GetSecond(), st.wMilliseconds);//modify by zhenglh 20130710
  46. strFileName = strAppPath + "\\log\\PZMedical2121Z." + strTime + ".dmp";
  47. HANDLE lhDumpFile = CreateFile(strFileName.GetBuffer(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  48. MINIDUMP_EXCEPTION_INFORMATION loExceptionInfo;
  49. loExceptionInfo.ExceptionPointers = ExceptionInfo;
  50. loExceptionInfo.ThreadId = GetCurrentThreadId();
  51. loExceptionInfo.ClientPointers = TRUE;
  52. MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), lhDumpFile, MiniDumpNormal, &loExceptionInfo, NULL, NULL);
  53. CloseHandle(lhDumpFile);
  54. return EXCEPTION_CONTINUE_SEARCH;
  55. }
  56. bool PZMedical2121ZApp::GetLastInstance()
  57. {
  58. HANDLE hSem=CreateSemaphore(NULL,1,1,m_pszExeName);
  59. if(GetLastError() == ERROR_ALREADY_EXISTS)
  60. {
  61. CloseHandle(hSem);
  62. HWND hWndPrevious = ::GetWindow(::GetDesktopWindow(), GW_CHILD);
  63. while (::IsWindow(hWndPrevious))
  64. {
  65. // if the window has our tag?
  66. if (::GetProp(hWndPrevious, m_pszExeName))
  67. {
  68. if (::IsIconic(hWndPrevious))
  69. ::ShowWindow(hWndPrevious, SW_RESTORE);
  70. ::SetForegroundWindow(hWndPrevious);
  71. ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
  72. return FALSE;
  73. }
  74. // continue find next window
  75. hWndPrevious = ::GetWindow(hWndPrevious, GW_HWNDNEXT);
  76. }
  77. // the previous instance is exist, but can not be found
  78. // something wrong?
  79. return FALSE;
  80. }
  81. return true;
  82. }
  83. BOOL PZMedical2121ZApp::InitInstance()
  84. {
  85. // InitCommonControlsEx() is required on Windows XP if an application
  86. // manifest specifies use of ComCtl32.dll version 6 or later to enable
  87. // visual styles. Otherwise, any window creation will fail.
  88. INITCOMMONCONTROLSEX InitCtrls;
  89. InitCtrls.dwSize = sizeof(InitCtrls);
  90. // Set this to include all the common control classes you want to use
  91. // in your application.
  92. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  93. InitCommonControlsEx(&InitCtrls);
  94. CWinApp::InitInstance();
  95. if(!GetLastInstance())
  96. return false;
  97. GetAppPath();
  98. ::SetUnhandledExceptionFilter(UEFilter); //20170922 zhangfeng
  99. #ifndef _DEBUG
  100. AutoDmp atdmp;
  101. #endif
  102. SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
  103. AfxEnableControlContainer();
  104. // Create the shell manager, in case the dialog contains
  105. // any shell tree view or shell list view controls.
  106. CShellManager *pShellManager = new CShellManager;
  107. // Standard initialization
  108. // If you are not using these features and wish to reduce the size
  109. // of your final executable, you should remove from the following
  110. // the specific initialization routines you do not need
  111. // Change the registry key under which our settings are stored
  112. // TODO: You should modify this string to be something appropriate
  113. // such as the name of your company or organization
  114. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  115. CPZMedical2121ZDlg dlg;
  116. m_pMainWnd = &dlg;
  117. INT_PTR nResponse = dlg.DoModal();
  118. if (nResponse == IDOK)
  119. {
  120. // TODO: Place code here to handle when the dialog is
  121. // dismissed with OK
  122. }
  123. else if (nResponse == IDCANCEL)
  124. {
  125. // TODO: Place code here to handle when the dialog is
  126. // dismissed with Cancel
  127. }
  128. // Delete the shell manager created above.
  129. if (pShellManager != NULL)
  130. {
  131. delete pShellManager;
  132. }
  133. // Since the dialog has been closed, return FALSE so that we exit the
  134. // application, rather than start the application's message pump.
  135. return FALSE;
  136. }
  137. bool PZMedical2121ZApp::GetAppPath()
  138. {
  139. TCHAR FullPath[MAX_PATH];
  140. strAppPath = "";
  141. GetModuleFileName(NULL , FullPath, MAX_PATH);
  142. strAppPath.Format("%s" , FullPath);
  143. int nPos = 1;
  144. int nBackUpPos = 0;
  145. while (nPos > 0) {
  146. nPos = strAppPath.Find("\\", nPos + 1);
  147. if (nPos > 0)
  148. {
  149. nBackUpPos = nPos ;
  150. }
  151. }
  152. strAppPath = strAppPath.Left(nBackUpPos);
  153. return true;
  154. }