// CancelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "psm.h"
#include "CancelDlg.h"
#include <afxmt.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCancelDlg dialog


CCancelDlg::CCancelDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CCancelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCancelDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_trd=0;
}


void CCancelDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCancelDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCancelDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CCancelDlg)
	ON_BN_CLICKED(ID_BTN, OnBtn)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCancelDlg message handlers

void CCancelDlg::OnCancel() 
{
	CaplTranslateDialog::OnCancel();
}

void CCancelDlg::OnBtn() 
{
	if(m_trd->m_bEndExpand!=0) *(m_trd->m_bEndExpand)=true;
	
}
/* DIV 05_06_02 
UINT CancelDlgThreadProc( LPVOID pParam )
{
	bool *bEndExpand=(bool*)pParam;
    CCancelDlg dlg;
	dlg.bEndExpand=(bool*)pParam;
	dlg.DoModal();
	if(bEndExpand!=0) *bEndExpand=true;
    return 0;   // thread completed successfully
}
/* */

void CCancelDlg::OnTimer(UINT nIDEvent){
	if(m_trd!=0){
		if(m_trd->m_cur_level!=0){
			TCHAR buf[100];
			_sprintf(buf, APL_T("Уровень рекурсии %i"),*(m_trd->m_cur_level));
			SetWindowText(buf);
		}
		if(m_trd->m_bIsActive!=0){
			if(*(m_trd->m_bIsActive))SetForegroundWindow();
			//if(*(m_trd->m_bIsActive))SetActiveWindow( );
		}
	}
}
BOOL CCancelDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();
	SetTimer(100001,500,0);
	return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CCancelDlgThread

IMPLEMENT_DYNCREATE(CCancelDlgThread, CWinThread)

CCancelDlgThread::CCancelDlgThread()
{
	m_bEndExpand=0;
	m_cur_level=0;
	m_bIsActive=0;
}

CCancelDlgThread::~CCancelDlgThread()
{
}


BOOL CCancelDlgThread::InitInstance()
{
	CCancelDlg dlg;
	m_pMainWnd = &dlg;
	dlg.m_trd=this;
	dlg.DoModal();
	return FALSE;
}

int CCancelDlgThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CCancelDlgThread, CWinThread)
//{{AFX_MSG_MAP(CCancelDlgThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCancelDlgThread message handlers


/////////////////////////////////////////////////////////////////////////////
// CCancelDlgThread message handlers

