1 // MyFrame.cpp : implementation file
2 // frame class used to demonstrate UI-threads
3 /* Copyright 2000, International Business Machines Corporation and others.
6 This software has been released under the terms of the IBM Public
7 License. For details, see the LICENSE file in the top-level source
8 directory or online at http://www.openafs.org/dl/license10.html
13 #include "ProgBarDlg.h"
16 #include "WinAfsLoad.h"
20 static char THIS_FILE[] = __FILE__;
25 HANDLE CMyUIThread::m_hEventThreadKilled=NULL;
27 IMPLEMENT_DYNCREATE(CMyUIThread, CWinThread)
29 CMyUIThread::CMyUIThread()
34 CMyUIThread::~CMyUIThread()
38 void CMyUIThread::operator delete(void* p)
40 // The exiting main application thread waits for this event before completely
41 // terminating in order to avoid a false memory leak detection. See also
42 // CMyUIThread::OnNcDestroy in bounce.cpp.
44 SetEvent(m_hEventThreadKilled);
45 CWinThread::operator delete(p);
48 BOOL CMyUIThread::InitInstance()
51 // Enable3dControls(); // Call this when using MFC in a shared DLL
53 // Enable3dControlsStatic(); // Call this when linking to MFC statically
55 // we use the modeless dialog box so we can create it invisable
57 m_pMainWnd = new CProgBarDlg; //we use the window pointer so MFC will delete the thread when Main window is destroyed
61 AfxMessageBox("AFS - Memory allocation error",MB_OK);
64 if (!((CProgBarDlg *)m_pMainWnd)->Create())
66 AfxMessageBox("AFS - Thread Memory allocation error",MB_OK);
71 if (!((CProgBarDlg *)m_pMainWnd)->Connect(msg))
73 AfxMessageBox(msg,MB_OK);
76 m_pLog = new CDatalog();
77 if (m_pLog->Create() != TRUE)
85 int CMyUIThread::ExitInstance()
87 // TODO: perform any per-thread cleanup here
88 if (m_cPrint.m_hFile!=CFile::hFileNull)
90 return CWinThread::ExitInstance();
93 BEGIN_MESSAGE_MAP(CMyUIThread, CWinThread)
94 //{{AFX_MSG_MAP(CMyUIThread)
95 // NOTE - the ClassWizard will add and remove mapping macros here.
97 ON_THREAD_MESSAGE(WM_UIONPARM,OnParm)
98 ON_THREAD_MESSAGE(WM_UICONNECT,OnConnect)
99 ON_THREAD_MESSAGE(WM_LOG,OnLog)
103 void CMyUIThread::OnParm( UINT wp, LONG lp)
108 m_pMainWnd->DestroyWindow(); // this will also destroy the datalog window
110 if (m_cPrint.m_hFile!=CFile::hFileNull)
113 case ONPARMDISCONNECT:
114 ((CProgBarDlg *)m_pMainWnd)->DisConnect();
115 CWINAFSLOADAPP->WSANotifyFromUI(AFS_EXITCODE_NORMAL,NULL);
124 // these routines must either return null or point to a message
125 void CMyUIThread::OnConnect( UINT wParam, LONG lp)
128 if (((CProgBarDlg *)m_pMainWnd)->Connect(sStatus))
130 CWINAFSLOADAPP->NotifyFromUI(wParam,NULL);
133 CWINAFSLOADAPP->NotifyFromUI(wParam,sStatus);
136 void CMyUIThread::OnLog( UINT wp, LONG lp)
143 if ((lp) && (m_cPrint.m_hFile!=CFile::hFileNull))
145 CString *pMsg=(CString *)lp;
146 m_cPrint.Write((const char *)*pMsg, lstrlen((const char *)*pMsg));
149 if (m_pLog==NULL) break;
152 CString *pMsg=(CString *)lp;
153 m_pLog->m_sEdit+=*pMsg;
154 delete pMsg; //FREE up date
157 m_pLog->UpdateData(FALSE);
158 m_pLog->m_cEdit.LineScroll(10000);
159 if ( (m_pLog->GetStyle() & (WS_VISIBLE|WS_MINIMIZE))==WS_VISIBLE)
160 m_pLog->SendMessage(WM_PAINT);
163 if (m_pLog==NULL) break;
164 m_pLog->ShowWindow((lp)?SW_SHOWNORMAL:SW_HIDE);
169 if (m_cPrint.m_hFile!=CFile::hFileNull)
172 CString *mp=(CString *)lp;
173 if (m_cPrint.Open((const char *)*mp
174 ,CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite,&m_cPrintException)==NULL)
177 m_cPrintException.GetErrorMessage(szError, 1024);
178 LOG("Log file(%s) open error %s",(const char *)lp,szError);
181 m_cPrint.SeekToEnd();
182 delete mp; //this was passed as a pointer to a created CString;
185 GetSystemTime(&timeDest);
186 mt.Format("\nNew Session:(%02d:%02d:%2d-%03d)\n",
190 timeDest.wMilliseconds);
191 m_cPrint.Write((const char *)mt, lstrlen(mt));
198 CATCH(CFileException, e)
200 if (m_cPrint.m_hFile!=CFile::hFileNull)
203 e->GetErrorMessage(szError, 1024);
204 LOG("Open Log file error %s",szError);