www.pudn.com > daothreadfix.zip > DAOTHREADView.cpp
// DAOTHREADView.cpp : implementation of the CDAOTHREADView class
//
#include "stdafx.h"
#include "multidaorecordset.h"
#include "DAOTHREAD.h"
#include "DAOTHREADSet.h"
#include "DAOTHREADDoc.h"
#include "DAOTHREADView.h"
#include "otherset.h"
#include "afxmt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView
const UINT WM_UPDATEVIEWDATA = RegisterWindowMessage("WM_UPDATEVIEWDATA");
IMPLEMENT_DYNCREATE(CDAOTHREADView, CView)
BEGIN_MESSAGE_MAP(CDAOTHREADView, CView)
//{{AFX_MSG_MAP(CDAOTHREADView)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView construction/destruction
CDAOTHREADView::CDAOTHREADView()
: CView()
{
//{{AFX_DATA_INIT(CDAOTHREADView)
m_pSet = NULL;
m_pDAOEdit = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_pDAOThread = NULL;
}
CDAOTHREADView::~CDAOTHREADView()
{
m_bContinueThread = FALSE;
Sleep(250);
}
void CDAOTHREADView::DoDataExchange(CDataExchange* pDX)
{
CView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDAOTHREADView)
DDX_Text(pDX, IDC_EDIT_DAOINFO, m_pDAOEdit);
//}}AFX_DATA_MAP
}
BOOL CDAOTHREADView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
UINT DAOThread( LPVOID pParam )
{
CDAOTHREADView *pView = (CDAOTHREADView *)pParam;
HWND hWnd = (HWND)pView->GetSafeHwnd();
CDAOTHREADApp *pApp = (CDAOTHREADApp*)AfxGetApp();
if (!pApp->m_bOtherSet)
{
pApp->m_bOtherSet = TRUE;
CDAOTHREADSet cSet(pApp->m_pDatabase);
cSet.Open();
int i = 0;
while (IsWindow(hWnd) && pView->m_bContinueThread)
{
while (IsWindow(hWnd) && pView->m_bContinueThread && !cSet.IsEOF() )
{
cSet.MoveNext();
SleepEx(250, FALSE); //dont lock up gui.....
}
cSet.MoveFirst();
}
cSet.Close();
}
else
{
COtherSet cOtherSet(pApp->m_pDatabase);
cOtherSet.Open();
int i = 0;
while (IsWindow(hWnd) && pView->m_bContinueThread)
{
while (IsWindow(hWnd) && !cOtherSet.IsEOF() && pView->m_bContinueThread)
{
cOtherSet.MoveNext();
SleepEx(250, FALSE); //dont lock up gui.....
}
cOtherSet.MoveFirst();
}
cOtherSet.Close();
}
AfxEndThread(0);
return 0;
}
void CDAOTHREADView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_dAOTHREADSet;
m_bContinueThread = TRUE;
m_pDAOThread = AfxBeginThread(DAOThread, this);
CView::OnInitialUpdate();
}
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView printing
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView diagnostics
#ifdef _DEBUG
void CDAOTHREADView::AssertValid() const
{
CView::AssertValid();
}
void CDAOTHREADView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDAOTHREADDoc* CDAOTHREADView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDAOTHREADDoc)));
return (CDAOTHREADDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView database support
CDaoRecordset* CDAOTHREADView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CDAOTHREADView message handlers
void CDAOTHREADView::OnDraw(CDC* pDC)
{
}
void CDAOTHREADView::OnClose()
{
CView::OnClose();
}
BOOL CDAOTHREADView::DestroyWindow()
{
return CView::DestroyWindow();
}