// PrismII.cpp : Defines the class behaviors for the application. // #include "stdafx.h" #include "PrismII.h" #include "PageDllStatus.h" #include //view window.. #include "WindowContainer.h" #include "EmWindow.h" #include "MainControlDlg.h" #ifdef _DEBUG #include "PUBLIB\inc/bsu/BugslayerUtil.h" #pragma comment(lib,"PUBLIB/lib/bsu/BugslayerUtil.lib") #endif #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPrismIIApp BEGIN_MESSAGE_MAP(CPrismIIApp, CWinApp) //{{AFX_MSG_MAP(CPrismIIApp) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG ON_COMMAND(ID_HELP, CWinApp::OnHelp) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPrismIIApp construction CPrismIIApp::CPrismIIApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_hMutexMultipleInstance = NULL; } ///////////////////////////////////////////////////////////////////////////// // The one and only CPrismIIApp object CPrismIIApp theApp; ///////////////////////////////////////////////////////////////////////////// // CPrismIIApp initialization #ifdef _DEBUG LONG __stdcall ExceptCallBack ( EXCEPTION_POINTERS * pExPtrs ) { DWORD dwOpts=GSTSO_PARAMS | GSTSO_MODULE | GSTSO_SYMBOL | GSTSO_SRCLINE; char* buf=new char[64*1024]; buf[0]=0; const char * szBuff = GetFirstStackTraceString ( dwOpts , pExPtrs ) ; do { strcat(buf,szBuff); strcat(buf,"\r\n"); szBuff = GetNextStackTraceString ( dwOpts , pExPtrs ) ; } while ( NULL != szBuff ) ; CMessageDlg dlg; dlg.m_pMessage=buf; dlg.DoModal(); delete buf; return ( EXCEPTION_EXECUTE_HANDLER ) ; } class CSEHError { public: CSEHError(void) { m_uiErrCode=0; } CSEHError(unsigned int u) { m_uiErrCode=u; } ~CSEHError(void) { m_uiErrCode=0; } unsigned int m_uiErrCode; }; void TransFunc(unsigned int u, EXCEPTION_POINTERS* pEP) { ExceptCallBack(pEP); throw CSEHError(u); } // catch( CSEHError e ) #endif CMessageDlg * g_pMsgDlg = NULL; BOOL CPrismIIApp::InitInstance() { BOOL AlreadyRunning; m_hMutexMultipleInstance = ::CreateMutex( NULL, FALSE, _T("PRISMII-DD18CAF2-839B-4add-BDA9-F8B04F8E3AFC")); AlreadyRunning = ( ::GetLastError() == ERROR_ALREADY_EXISTS || ::GetLastError() == ERROR_ACCESS_DENIED); // The call fails with ERROR_ACCESS_DENIED if the Mutex was // created in a different users session because of passing // NULL for the SECURITY_ATTRIBUTES on Mutex creation); if ( AlreadyRunning ) { int rs = MessageBox(NULL, _T("There is already another instance of this application. Do you wish to run anyway?"), _T("PrismII"), MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON2 | MB_APPLMODAL | MB_TOPMOST); if (IDYES!=rs) { return FALSE; } } // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. CoInitialize(NULL); g_pMsgDlg=new CMessageDlg; g_pMsgDlg->Create(IDD_DIALOG_MESSAGE,NULL); CMainControlDlg dlg; m_pMainWnd = &dlg; int nResponse; if(IsDebuggerPresent()){ nResponse = dlg.DoModal(); g_pMsgDlg->DestroyWindow(); delete g_pMsgDlg; g_pMsgDlg = NULL; }else{ #if _DEBUG SetCrashHandlerFilter(NULL); BOOL ret=SetCrashHandlerFilter ( ExceptCallBack ); _set_se_translator(TransFunc); try { #endif nResponse = dlg.DoModal(); g_pMsgDlg->DestroyWindow(); delete g_pMsgDlg; g_pMsgDlg = NULL; #if _DEBUG } catch( CSEHError e ) //catch( ExceptCallBack ( GetExceptionInformation ( ) ) ) { } #endif } if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; } int CPrismIIApp::ExitInstance() { if (m_hMutexMultipleInstance) { CloseHandle(m_hMutexMultipleInstance); m_hMutexMultipleInstance = NULL; } return CWinApp::ExitInstance(); } ///////////////////////////////////////////////////////////////////////////// // CMessageDlg dialog CMessageDlg::CMessageDlg(CWnd* pParent /*=NULL*/) : CDialog(CMessageDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMessageDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_pMessage = NULL; m_iCurPage = -1; m_dwThreadID= NULL; m_indexCount=0; m_dwThreadID = GetCurrentThreadId(); } CMessageDlg::~CMessageDlg() { for(int i=0;i4096)strLen=4096-m_msgPointer[index]-1; CopyMemory(m_lpMsg[index]+m_msgPointer[index],string,strLen+1); m_msgPointer[index]+=strLen; PostMessage(WM_USER+110,index,0); } return FALSE; } LRESULT CMessageDlg::OnDelayedMessage(WPARAM index,LPARAM msg) { if(msg==0){//addMessage if(m_msgPointer[index]){ int nLen = m_Edit[index].GetWindowTextLength(); m_Edit[index].SetSel(nLen,nLen); m_Edit[index].ReplaceSel(m_lpMsg[index]); m_msgPointer[index]=0; } }else if(msg==1){//Deactivate ShowWindow(SW_HIDE); }else{//Activate if(m_iCurPage>=0){ m_Edit[m_iCurPage].ShowWindow(SW_HIDE); } m_Tab.SetCurSel(index); m_Edit[index].ShowWindow(SW_SHOW); m_iCurPage = index; ShowWindow(SW_SHOW); } return 0; } BOOL CMessageDlg::Activate(BOOL bActivate,int index) { if(m_dwThreadID==GetCurrentThreadId()){ if(bActivate){ if(m_iCurPage>=0){ m_Edit[m_iCurPage].ShowWindow(SW_HIDE); } m_Tab.SetCurSel(index); m_Edit[index].ShowWindow(SW_SHOW); m_iCurPage = index; ShowWindow(SW_SHOW); }else{ ShowWindow(SW_HIDE); } }else{ PostMessage(WM_USER+110,index,1+bActivate); } return FALSE; } void CMessageDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult) { if(m_iCurPage>=0){ m_Edit[m_iCurPage].ShowWindow(SW_HIDE); } int iPage=m_Tab.GetCurSel(); m_Edit[iPage].ShowWindow(SW_SHOW); m_iCurPage=iPage; *pResult = 0; } void CMessageDlg::OnClear() { int iPage=m_Tab.GetCurSel(); m_Edit[iPage].SetWindowText(""); } void CMessageDlg::OnOK() { if(m_pMessage){ CDialog::OnOK(); }else{ ShowWindow(SW_HIDE); } } void CMessageDlg::OnClose() { // TODO: Add your message handler code here and/or call default if(m_pMessage){ CDialog::OnClose(); }else{ ShowWindow(SW_HIDE); } }