// SetupShowonExpand.cpp : implementation file
//

#include "stdafx.h"
#include "SetupShowonExpand.h"
#include "apl_api.h"
#include "aplBaseTreeItem.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetupShowonExpandDlg dialog

CTreeExpandOptionsDlg::CTreeExpandOptionsDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(CTreeExpandOptionsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTreeExpandOptionsDlg)
	//}}AFX_DATA_INIT
	m_old_state = -1;
}


void CTreeExpandOptionsDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTreeExpandOptionsDlg)
	DDX_Control(pDX, IDC_SI_CHECK9, m_check9);
	DDX_Control(pDX, IDC_SI_CHECK8, m_check8);
	DDX_Control(pDX, IDC_SI_CHECK7, m_check7);
	DDX_Control(pDX, IDC_SI_CHECK6, m_check6);
	DDX_Control(pDX, IDC_SI_CHECK5, m_check5);
	DDX_Control(pDX, IDC_SI_CHECK4, m_check4);
	DDX_Control(pDX, IDC_SI_CHECK3, m_check3);
	DDX_Control(pDX, IDC_SI_CHECK2, m_check2);
	DDX_Control(pDX, IDC_SI_CHECK10, m_check10);
	DDX_Control(pDX, IDC_SI_CHECK1, m_check1);
	DDX_Control(pDX, IDOK, m_ok_btn);
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Control(pDX, IDC_SI_LIST, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTreeExpandOptionsDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(CTreeExpandOptionsDlg)
	ON_LBN_SELCHANGE(IDC_SI_LIST, OnSelchangeList)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTreeExpandOptionsDlg message handlers

BOOL CTreeExpandOptionsDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();
	
	m_ok_btn.SetIcon(GetAplStdIco16(APLSTDICO_OK));
	m_ok_btn.SetFlat(FALSE);
	m_cancel_btn.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));
	m_cancel_btn.SetFlat(FALSE);
	CWinApp *app=AfxGetApp(); // При вызове из ActiveX возвращает 0
	if(0!=app)
	{
		m_states[0] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Prd"),0);
		m_states[1] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Pdf"),0);
		m_states[2] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("PrdInst"),0);
		m_states[3] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Doc"),0);
		m_states[4] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Charact"),APL_SHOW_CHARACT|APL_SHOW_APPROVAL);
		m_states[5] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Change"),APL_SHOW_APPROVAL);
		m_states[6] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("BP"),0);
		m_states[7] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("BPRes"),0);
		m_states[8] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("BPInst"),0);
		m_states[9] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Categ"),0);
		m_states[10] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Lot"),0);
		m_states[11] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Project"),0);
		m_states[12] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Organization"),0);
		m_states[13] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Official"),0);
		m_states[14] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("Person"),0);
		m_states[15] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("ClassifierSystem"),0);
		m_states[16] = (UINT)app->GetProfileInt(_T("ShowInTree"),_T("ClassifierLevel"),0);
	}
	int i = 0;
	i = m_list.AddString( APL_T("Изделие"));
	m_list.SetItemData(i,0);
	i = m_list.AddString( APL_T("Версия изделия"));
	m_list.SetItemData(i,1);
	i = m_list.AddString( APL_T("Экземпляр изделия"));
	m_list.SetItemData(i,2);
	i = m_list.AddString( APL_T("Документ"));
	m_list.SetItemData(i,3);
	i = m_list.AddString( APL_T("Характеристика"));
	m_list.SetItemData(i,4);
	i = m_list.AddString( APL_T("Изменение"));
	m_list.SetItemData(i,5);
	i = m_list.AddString( APL_T("Бизнес процесс"));
	m_list.SetItemData(i,6);
	i = m_list.AddString( APL_T("Ресурс бизнес процесса"));
	m_list.SetItemData(i,7);
	i = m_list.AddString( APL_T("Экземпляр бизнес процесса"));
	m_list.SetItemData(i,8);
	i = m_list.AddString( APL_T("Категория"));
	m_list.SetItemData(i,9);
	i = m_list.AddString( APL_T("Партия изделия"));
	m_list.SetItemData(i,10);
	i = m_list.AddString( APL_T("Проект"));
	m_list.SetItemData(i,11);
	i = m_list.AddString( APL_T("Подразделение"));
	m_list.SetItemData(i,12);
	i = m_list.AddString( APL_T("Абонент"));
	m_list.SetItemData(i,13);
	i = m_list.AddString( APL_T("Сотрудник"));
	m_list.SetItemData(i,14);
//	i = m_list.AddString(APL_T("Справочник"));
//	m_list.SetItemData(i,15);
//	i = m_list.AddString(APL_T("Элемент структуры справочника"));
//	m_list.SetItemData(i,16);
	m_list.SetCurSel(0);
	ShowCheckBoxes();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTreeExpandOptionsDlg::ShowCheckBoxes()
{
	int i = m_list.GetCurSel();

	if(m_old_state>-1)
		m_states[m_old_state] = 0;
	if(m_old_state==0)//Изделие
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_BP;
		if(m_check5.GetCheck()) m_states[m_old_state]|=APL_SHOW_BPINST;
	}
	if(m_old_state==1)//Версия Изделие
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_MATERIAL;
		if(m_check5.GetCheck()) m_states[m_old_state]|=APL_SHOW_LOT;
		if(m_check6.GetCheck()) m_states[m_old_state]|=APL_SHOW_BP;
		if(m_check7.GetCheck()) m_states[m_old_state]|=APL_SHOW_BPINST;
		if(m_check8.GetCheck()) m_states[m_old_state]|=APL_SHOW_SUBSTITUTE;
	}
	else if(m_old_state==2)//Экземпляр изделия
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_BP;
		if(m_check5.GetCheck()) m_states[m_old_state]|=APL_SHOW_BPINST;
	}
	else if(m_old_state==3)//Документ
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_BP;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_VER;
	}
	else if(m_old_state==4)//Характеристика
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_VER;
	}
	else if(m_old_state==5)//Изменения
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
	}
	else if(m_old_state==6)//BP
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_RES;
		if(m_check5.GetCheck()) m_states[m_old_state]|=APL_SHOW_VER;
		if(m_check6.GetCheck()) m_states[m_old_state]|=APL_SHOW_BPINST;
	}
	else if(m_old_state==7)//BPRes
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
	}
	else if(m_old_state==8)//BPInst
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_RES;
	}
	else if(m_old_state==9)//Categ
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_VER;
	}
	else if(m_old_state==10)//Lot
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
		if(m_check4.GetCheck()) m_states[m_old_state]|=APL_SHOW_INST;
	}
	else if(m_old_state==11)//Project
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
		if(m_check3.GetCheck()) m_states[m_old_state]|=APL_SHOW_APPROVAL;
	}
	else if(m_old_state>=12 && m_old_state<=14)//Орг структура
	{
		if(m_check1.GetCheck()) m_states[m_old_state]|=APL_SHOW_DOC;
		if(m_check2.GetCheck()) m_states[m_old_state]|=APL_SHOW_CHARACT;
	}

	if(i<0) return;
	if(i==m_old_state) return;

	if(m_old_state == (int)m_list.GetItemData(i)) return;

	m_check1.ShowWindow(SW_HIDE);
	m_check2.ShowWindow(SW_HIDE);
	m_check3.ShowWindow(SW_HIDE);
	m_check4.ShowWindow(SW_HIDE);
	m_check5.ShowWindow(SW_HIDE);
	m_check6.ShowWindow(SW_HIDE);
	m_check7.ShowWindow(SW_HIDE);
	m_check8.ShowWindow(SW_HIDE);
	m_check9.ShowWindow(SW_HIDE);
	m_check10.ShowWindow(SW_HIDE);

	m_old_state = m_list.GetItemData(i);
	DWORD state = m_states[m_old_state];
	if(m_old_state==0)//Изделие
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_BP);
		m_check4.SetWindowText( APL_T("Бизнес процессы"));
		m_check5.SetCheck(state&APL_SHOW_BPINST);
		m_check5.SetWindowText( APL_T("Экземпляры бизнес процессов"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
		m_check5.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==1)//версии изд.
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_MATERIAL);
		m_check4.SetWindowText( APL_T("Материалы и нормы расхода"));
		m_check5.SetCheck(state&APL_SHOW_LOT);
		m_check5.SetWindowText( APL_T("Партии изделия"));
		m_check6.SetCheck(state&APL_SHOW_BP);
		m_check6.SetWindowText( APL_T("Бизнес процессы"));
		m_check7.SetCheck(state&APL_SHOW_BPINST);
		m_check7.SetWindowText( APL_T("Экземпляры бизнес процессов"));
		m_check8.SetCheck(state&APL_SHOW_SUBSTITUTE);
		m_check8.SetWindowText( APL_T("Заменители в контексте сборки"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
		m_check5.ShowWindow(SW_SHOW);
		m_check6.ShowWindow(SW_SHOW);
		m_check7.ShowWindow(SW_SHOW);
		m_check8.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==2)//Экземпляры изделия
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_BP);
		m_check4.SetWindowText( APL_T("Бизнес процессы"));
		m_check5.SetCheck(state&APL_SHOW_BPINST);
		m_check5.SetWindowText( APL_T("Экземпляры бизнес процессов"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
		m_check5.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==3)//Документ
	{
		m_check1.SetCheck(state&APL_SHOW_CHARACT);
		m_check1.SetWindowText( APL_T("Характеристики"));
		m_check2.SetCheck(state&APL_SHOW_APPROVAL);
		m_check2.SetWindowText( APL_T("Электронные подписи"));
		m_check3.SetCheck(state&APL_SHOW_BP);
		m_check3.SetWindowText( APL_T("Бизнес процессы"));
		m_check4.SetCheck(state&APL_SHOW_VER);
		m_check4.SetWindowText( APL_T("Версии"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==4)//Характеристика
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_VER);
		m_check4.SetWindowText( APL_T("Версии"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==5)//Изменения
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_APPROVAL);
		m_check2.SetWindowText( APL_T("Электронные подписи"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==6)//BP
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_RES);
		m_check4.SetWindowText( APL_T("Ресурсы"));
		m_check5.SetCheck(state&APL_SHOW_VER);
		m_check5.SetWindowText( APL_T("Версии"));
		m_check6.SetCheck(state&APL_SHOW_BPINST);
		m_check6.SetWindowText( APL_T("Экземпляры бизнес процессов"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
		m_check5.ShowWindow(SW_SHOW);
		m_check6.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==7)//BPRes
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==8)//BPInst
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_RES);
		m_check4.SetWindowText( APL_T("Ресурсы"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==9)//Categ
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_VER);
		m_check3.SetWindowText( APL_T("Версии"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==10)//Lot
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check4.SetCheck(state&APL_SHOW_INST);
		m_check4.SetWindowText( APL_T("Экземпляры изделия"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
		m_check4.ShowWindow(SW_SHOW);
	}
	else if(m_old_state==11)//Project
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check3.SetCheck(state&APL_SHOW_APPROVAL);
		m_check3.SetWindowText( APL_T("Электронные подписи"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
		m_check3.ShowWindow(SW_SHOW);
	}
	else if(m_old_state>=12 && m_old_state<=14)//Орг структура
	{
		m_check1.SetCheck(state&APL_SHOW_DOC);
		m_check1.SetWindowText( APL_T("Документы"));
		m_check2.SetCheck(state&APL_SHOW_CHARACT);
		m_check2.SetWindowText( APL_T("Характеристики"));
		m_check1.ShowWindow(SW_SHOW);
		m_check2.ShowWindow(SW_SHOW);
	}
}

void CTreeExpandOptionsDlg::OnSelchangeList() 
{
	ShowCheckBoxes();
}

void CTreeExpandOptionsDlg::OnOK() 
{
	ShowCheckBoxes();
	CWinApp *app=AfxGetApp(); // При вызове из ActiveX возвращает 0
	if(0==app) return;
	app->WriteProfileInt(_T("ShowInTree"),_T("Prd"),m_states[0]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Pdf"),m_states[1]);
	app->WriteProfileInt(_T("ShowInTree"),_T("PrdInst"),m_states[2]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Doc"),m_states[3]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Charact"),m_states[4]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Change"),m_states[5]);
	app->WriteProfileInt(_T("ShowInTree"),_T("BP"),m_states[6]);
	app->WriteProfileInt(_T("ShowInTree"),_T("BPRes"),m_states[7]);
	app->WriteProfileInt(_T("ShowInTree"),_T("BPInst"),m_states[8]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Categ"),m_states[9]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Lot"),m_states[10]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Project"),m_states[11]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Organization"),m_states[12]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Official"),m_states[13]);
	app->WriteProfileInt(_T("ShowInTree"),_T("Person"),m_states[14]);
	app->WriteProfileInt(_T("ShowInTree"),_T("ClassifierSystem"),m_states[15]);
	app->WriteProfileInt(_T("ShowInTree"),_T("ClassifierLevel"),m_states[16]);
	
	CaplTranslateDialog::OnOK();
}
