//////////////////////////////////////////////////////////////////////
//
// Разработчик: Алексей Фёдоров aka АЛьФ, mailto: alf@dorex.pro
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "sizecbar.h"
#include "afxpriv.h"
#define DELETE_EXCEPTION(e) do { e->Delete(); } while (0)

#include "painthook.h"
#include "FormExFormView.h"
#include "Service.h"

#include "InitFormEx.h"
#include "artbear\events.h"
#include "artbear\GlobalMethods.h"

#include "artbear\lock.h"
#include "artbear\LogFile.h"

BOOL bSetDrawWrap = FALSE;
//extern CSizingControlBar* pWndToDock;
extern CWnd* pWndToDock;
extern CMainMessageHandler* pMainMessageHandler;
extern CMainMessageHandler* pMMHandlerToCapture;
extern DWORD dwMMHCaptureMask;
extern BOOL m_bNoInvalidate;


typedef void (CWrapModule::*PF_NULL)(void);

DEFINE_WRAP_v2(AssignContext);


// CMapStringToPtr DocNamesArray;
// struct SDocNames{
// 	DWORD id;
// 	CString strFolder;
// };

/*
typedef int(CTabFrame::*PF_OnCmdMsg)(unsigned int, int, void *, struct AFX_CMDHANDLERINFO *);
DEFINE_WRAP(OnCmdMsg, PF_OnCmdMsg);
*/
/*
typedef int(SECStatusBar::*PF_SPT)(int, const char *, int);
DEFINE_WRAP(SetPaneText, PF_SPT);

typedef void(SECStatusBar::*PF_UAP)(int,int);
DEFINE_WRAP(UpdateAllPanes, PF_UAP);
*/
typedef void(CSheetView::*PF_PT)(class CSheetGDI &,class CDC *,char const *,class CSheetFormat const &,struct tagRECT const *,int,struct tagRECT const *);
DEFINE_WRAP(PaintText, PF_PT);

typedef int(SECStatusBar::*PF_SI)(unsigned int const *,int);
DEFINE_WRAP(SetIndicators, PF_SI);

typedef void(SECControlBar::*PF_OLBDC)(unsigned int,class CPoint);
DEFINE_WRAP(OnLButtonDblClk, PF_OLBDC);

typedef void(CChildFrame7::*PF_ONMDIA)(int,class CWnd *,class CWnd *);
DEFINE_WRAP(OnMDIActivate, PF_ONMDIA);

typedef int(CBrowse::*PF_GHTB)(int);
DEFINE_WRAP(GetHiTrackBound, PF_GHTB);

typedef int(CBrowse::*PF_GLTB)(int);
DEFINE_WRAP(GetLoTrackBound, PF_GLTB);

typedef void(CBrowse::*PF_CENTER)(void);
DEFINE_WRAP(center, PF_CENTER);

typedef void(CBrowse::*PF_TOP)(void);
DEFINE_WRAP(top, PF_TOP);

typedef void(CBrowse::*PF_REFRESH)(void);
DEFINE_WRAP(refresh, PF_REFRESH);

typedef void(CBrowse::*PF_REFRESHALL)(void);
DEFINE_WRAP(RefreshAll, PF_REFRESHALL);

typedef int(CValueTable::*PF_NEWROW)(int);
DEFINE_WRAP(NewRow, PF_NEWROW);

typedef class CWnd * (CGetDoc7::*PF_GDCC)(class CGetField *,unsigned int,class CRect const &,class CWnd *,unsigned long,unsigned long);
DEFINE_WRAP(CreateControl, PF_GDCC);

typedef void (CGetDoc7::*PF_PSO)(class CValue*);
DEFINE_WRAP(ProcessSecondOpen, PF_PSO);

typedef void (CBrowseView7::*PF_ONINITUP)(void);
DEFINE_WRAP(OnInitialUpdate, PF_ONINITUP);

typedef int (CGetDlg::*PF_ONINITDLG)(void);
DEFINE_WRAP(OnInitDialog, PF_ONINITDLG);

typedef int (CDialog/*COlePropertyPageSite*/::*PF_PPONINITDLG)(void);
DEFINE_WRAP(PPOnInitDialog, PF_PPONINITDLG);

typedef int(CGetDoc7::*PF_LayF)(class CFormView *);
DEFINE_WRAP(LayoutForm, PF_LayF);

typedef struct HBRUSH__ *  (CDrawTrasparentCtrl::*PF_CC_TC)(class CDC *,unsigned int);
static BYTE*   adrCtlColorTrans;

typedef struct HBRUSH__ *  (CDrawStatic::*PF_CC)(class CDC *,unsigned int);
static BYTE*   adrCtlColor;

typedef void (*PF_DX_T)(class CGetExchange *,int,class CValue &);
DEFINE_WRAP(DX_Text, PF_DX_T);

typedef class CGetDoc7* (*PF_ActivateDocForm)(long,class CObjID,long,unsigned int,class CObjID,long,int,long,int,int,int,int,class CValue *,class CValue *);
DEFINE_WRAP(ActivateDocForm, PF_ActivateDocForm);

typedef int (CRightsContainer::*PF_ISACCESS)(unsigned int,long,unsigned int);
DEFINE_WRAP(IsAccess, PF_ISACCESS);

typedef int(CBLModule7::*PF_ONNEXTLINE)(void);
DEFINE_WRAP(OnNextLine, PF_ONNEXTLINE);

typedef void(CBLModule7::*PF_ONENTERPROC)(int);
DEFINE_WRAP(OnEnterProc, PF_ONENTERPROC);

typedef void(CBLModule7::*PF_ONEXITPROC)(int);
DEFINE_WRAP(OnExitProc, PF_ONEXITPROC);

typedef int(CBLModule7::*PF_ONSTARTEXECUTION)(void);
DEFINE_WRAP(OnStartExecution, PF_ONSTARTEXECUTION);

typedef int(CBLModule7::*PF_ONSTOPEXECUTION)(void);
DEFINE_WRAP(OnStopExecution, PF_ONSTOPEXECUTION);

// typedef void (CBLModule::*PF_ASSIGNSOURCE)(LPCSTR);
// DEFINE_WRAP(AssignSource, PF_ASSIGNSOURCE);

typedef void (CGetDoc7::*PF_ONCD)(void);
DEFINE_WRAP(OnCloseDocument, PF_ONCD);

//typedef void(CGetDoc7::*PF_ONUPWATCH)(int,int,int,class CGetField *);
//DEFINE_WRAP(UpdateWatchs, PF_ONUPWATCH);
typedef int(CGetDoc7::*PF_ONUPDATA)(int, UINT);
DEFINE_WRAP(UpdateData, PF_ONUPDATA);

typedef int(CGetDoc7::*PF_LOADFORM)(long,char const *);
DEFINE_WRAP(LoadForm, PF_LOADFORM);

typedef int(CEditDoc::*PF_DOLOADEX)(LPCSTR);
DEFINE_WRAP(DoLoadExternal, PF_DOLOADEX);

typedef int(CEditDoc::*PF_DOLOADLAYOUT)(LPCSTR);
DEFINE_WRAP(DoLoadLayout, PF_DOLOADLAYOUT);

typedef void(CImageCol::*PF_GETDATAIMAGECOL)(CString&);
DEFINE_WRAP(GetData, PF_GETDATAIMAGECOL);

typedef void (CApp7::*PF_UNLOADADDINS)(void);
DEFINE_WRAP(UnloadAddIns, PF_UNLOADADDINS);

typedef int(CGetDoc7::*PF_LOADDIALOG)(long,char const *);
DEFINE_WRAP(LoadDialog, PF_LOADDIALOG);

typedef void(CSheetView::*PF_ONPRINT)(class CDC *,struct CPrintInfo *);
DEFINE_WRAP(OnPrint, PF_ONPRINT);

typedef int(CSheetView::*PF_ONPREPAREPRINTING)(struct CPrintInfo *);
DEFINE_WRAP(OnPreparePrinting, PF_ONPREPAREPRINTING);

//typedef static void (CGetDlg::*PF_OPENDOCUMENTFILEEX)(unsigned int,char const *,long,class CValue *,unsigned int,unsigned int,unsigned int,unsigned int);
DEFINE_WRAP(OpenDocumentFileEx, void*);

typedef void (CCheckListBox::*PF_CLBDI)(LPDRAWITEMSTRUCT);
typedef BOOL (CCheckListBox::*PF_CLBOCN)(UINT , WPARAM , LPARAM , LRESULT* );

typedef int(CRepHistory::*PF_READHISTORY)(void);
DEFINE_WRAP(ReadHistory, PF_READHISTORY);

typedef int(CRepHistory::*PF_WRITEHISTORY)(void);
DEFINE_WRAP(WriteHistory, PF_WRITEHISTORY);

typedef int(CSheetDoc::*PF_SHEETDOCSAVEAS)(char const *,enum CSheetSaveAsType);
DEFINE_WRAP(SheetDocSaveAs, PF_SHEETDOCSAVEAS);

typedef int(CPictureHolder7::*PF_CreateFromFile)(const char *);
DEFINE_WRAP(CreateFromFile, PF_CreateFromFile);

typedef void(CMainMessageHandler::*PF_WriteMessage)(char const *,class CMessageInfo &,int);
DEFINE_WRAP(WriteMessage, PF_WriteMessage);

//typedef class CDocument *(CTemplate7::*PF_Template7OpenDocumentFileEx)(char const *,long,int);
//DEFINE_WRAP(Template7OpenDocumentFileEx, PF_Template7OpenDocumentFileEx);

typedef void (SECMDIFrameWnd::*PF_SHOWCONTROLBAR)(class CControlBar *,int,int);
DEFINE_WRAP(ShowControlBar, PF_SHOWCONTROLBAR);

typedef void (SECControlBar::*PF_ONHIDE)(void);
DEFINE_WRAP(OnHide, PF_ONHIDE);

typedef void(*PF_WriteStatusLine)(char const *);
DEFINE_WRAP(WriteStatusLine, PF_WriteStatusLine);

typedef void(*PF_WriteStatusLineUINT)(UINT);
DEFINE_WRAP(WriteStatusLineUINT, PF_WriteStatusLineUINT);

typedef class CGetDoc7* (CGetDoc7::*PF_CGETDOC7)(void);
DEFINE_WRAP(CGetDoc7_Constructor, PF_CGETDOC7);

static DWORD jmpIsError;
static DWORD* adrIsError;

extern BOOL bMessageConfigMode;
BOOL bMessageEvent = TRUE;
BOOL bStatusLineEvent = TRUE;

BOOL EventWriteStatusLine(CString& ccMessage)
{
	if(bStatusLineEvent)
	{ // вызов предопределенной процедуры

		CValue vText = ccMessage;
		CValue vFSO = 1;
		CValue vSrcLineNum = -1;
		CValue vObjectID = 0L;
		CValue vObjectName = "";

		CBLModule7* pModule = (CBLModule7*)CBLModule::GetExecutedModule();
		if(pModule)
		{
			vSrcLineNum = pModule->GetExecutedLineNum();

			CBLModule7* pModuleExec = (CBLModule7*)pModule->GetCurrentModule();
			if(pModuleExec) pModule = pModuleExec;

			vObjectID = pModule->m_nID;
			vObjectName = pModule->GetFullName();
		}

		CValue *lArray[5] = {&vText, &vSrcLineNum, &vObjectID, &vObjectName, &vFSO};
		
		bStatusLineEvent = FALSE; // защита от зацикливания
		CEventsManager::GetManager().SendEventToGlobalModules(meOnWriteStatusLine, lArray);
		bStatusLineEvent = TRUE;
		
		if(0L == (UINT)vFSO.GetNumeric()) return FALSE;

		ccMessage = vText.GetString();
	}

	return TRUE;
}

void WrapWriteStatusLine(const char * ccMessageIn)
{

	CString ccMessage = ccMessageIn;
	if(!EventWriteStatusLine(ccMessage)) return;


	SET_ORIGIN_FUNC(WriteStatusLine)

	WriteStatusLine(ccMessage);

	SET_WRAP_FUNC(WriteStatusLine)

}

void WrapWriteStatusLineUINT(UINT uiMessageNum)
{
	CString ccMessage = "";
	ccMessage.Format("%x", uiMessageNum);

	if(!EventWriteStatusLine(ccMessage)) return;

	SET_ORIGIN_FUNC(WriteStatusLineUINT)

	WriteStatusLine(uiMessageNum);

	SET_WRAP_FUNC(WriteStatusLineUINT)
}

void  CWrapModule::WrapWriteMessage(char const * ccMessageIn,class CMessageInfo & MessageInfo,int iFlag)
{
	CString ccMessage = ccMessageIn;

	if(pMainMessageHandler == NULL)
	if(CString(ccMessage) == CString("%%GetMainMessageHandler%%"))
	{
		pMainMessageHandler = (CMainMessageHandler*)this;
		return;
	}


	if(bMessageEvent)
	{ // вызов предопределенной процедуры

		int idMessageHandler = -1;
		CMainMessageHandler* This = ((CMainMessageHandler*)this);
		if(This == pMainMessageHandler)
			idMessageHandler = 0;
		else
			idMessageHandler = (DWORD)This;

		CValue vID = idMessageHandler;
		CValue vText = ccMessage;
		CValue vMarker = MessageInfo.m_MessageMarker;
		CValue vFSO = 1;
		CValue vSrcLineNum = -1;
		CValue vObjectID = 0L;
		CValue vObjectName = "";

		CBLModule7* pModule = (CBLModule7*)CBLModule::GetExecutedModule();
		if(pModule)
		{
			vSrcLineNum = pModule->GetExecutedLineNum();

			CBLModule7* pModuleExec = (CBLModule7*)pModule->GetCurrentModule();
			if(pModuleExec) pModule = pModuleExec;

			vObjectID = pModule->m_nID;
			vObjectName = pModule->GetFullName();
		}

		CValue *lArray[7] = {&vID, &vText, &vMarker, &vSrcLineNum, &vObjectID, &vObjectName, &vFSO};
		
		bMessageEvent = FALSE; // защита от зацикливания
		CEventsManager::GetManager().SendEventToGlobalModules(meOnWriteMessage, lArray);
		bMessageEvent = TRUE;
		
		if(0L == (UINT)vFSO.GetNumeric()) return;

		ccMessage = vText.GetString();
		MessageInfo.m_MessageMarker = (enum MessageMarker)(int)vMarker.GetNumeric();
	}


	SET_ORIGIN_FUNC(WriteMessage)

		CString csMessageIn = ccMessage;
		CMainMessageHandler* This = ((CMainMessageHandler*)this);
		if(This == pMainMessageHandler)
		{
			if(pMMHandlerToCapture != NULL)
			{
				int iMessageMarker = MessageInfo.m_MessageMarker;
				DWORD dwMask = (1<<iMessageMarker);
				if(dwMask&dwMMHCaptureMask)
					This = pMMHandlerToCapture;
			}
		}

		if(bMessageConfigMode)
		{
			bMessageConfigMode = FALSE; // на случай критической ошибки при выводе сообщения, чтобы не зациклилось
			CMessageInfoError MessageInfoError;
			MessageInfoError.m_MessageMarker = MessageInfo.m_MessageMarker;
			CBLModule7* pModule = (CBLModule7*)CBLModule::GetExecutedModule();
			if(pModule)
			{
				MessageInfoError.m_SrcLineNum = pModule->GetExecutedLineNum() - 1;
				
				CBLModule7* pModuleExec = (CBLModule7*)pModule->GetCurrentModule();
				if(pModuleExec) pModule = pModuleExec;

				MessageInfoError.m_ObjectID = pModule->m_nID;
				MessageInfoError.m_ObjectName = pModule->m_strModulePath;
			}
			else
			{
				MessageInfoError.m_SrcLineNum = -1;
				MessageInfoError.m_ObjectID = -1;
				MessageInfoError.m_ObjectName = NULL;
			}

			CString csMessage = "";
			csMessage.Format("%s\r\n",
				csMessageIn);
			/*
			csMessage.Format("%s\r\n[%s (%s\\%d) (%d)]",
				ccMessage,
				pModule->GetFullName(),
				pModule->m_strModulePath,
				pModule->m_nID,
				MessageInfoError.m_SrcLineNum);
			*/

			This->WriteMessage(csMessage,MessageInfoError,iFlag);
			bMessageConfigMode = TRUE;
		}
		else
		{
			int l = csMessageIn.GetLength();
			int MaxLineLen = This->GetMaxLineLen()-3;
			if(l > MaxLineLen)
			{
				CString csMessageOut;
				TCHAR c;
				int ll = 0;
				for(int n = 0; n < l; n++)
				{
					ll++;
					c = csMessageIn.GetAt(n);
					if(c == 0x0A) ll = 0;
					csMessageOut += c;
					if(ll == MaxLineLen)
					{
						csMessageOut += "\r\n";
						ll = 0;
					}
				}
				This->WriteMessage(csMessageOut,MessageInfo,iFlag);
			}
			else
				This->WriteMessage(csMessageIn,MessageInfo,iFlag);
		}

	SET_WRAP_FUNC(WriteMessage)

}

int CWrapModule::IsError(enum  MessageMarker mmMessage)
{
	int ret = 0;
	if(bMessageConfigMode)
		ret = 1;
	else if((mmMessage == mmBlackErr) || (mmMessage == mmRedErr) || (mmMessage == mmUnderlinedErr))
		ret = 1;
	return ret;
}

int CWrapModule::WrapSheetDocSaveAs(char const * cFileName,enum CSheetSaveAsType eType)
{
	CSheetDoc* This = (CSheetDoc*)this;
	SET_ORIGIN_FUNC(SheetDocSaveAs)

	CValue vCont;

	CBLPtr<CTableWrapEx> pTableOutputContext;
	if (GetTableOutputContextFromDocument(This, pTableOutputContext) 
		&& static_cast<bool>(pTableOutputContext))
 			vCont.AssignContext(pTableOutputContext);

	CString stFileName = cFileName;
	int iType = (int)eType;
	CValue vName = stFileName;
	CValue vType = iType;
	CValue vFSO = 1;

	CValue *lArray[4] = {&vCont, &vName, &vType, &vFSO};

	CEventsManager::GetManager().SendEventToGlobalModules(meOnSaveSheetDoc, lArray);

	int ret = 1;
	if(vFSO.GetNumeric() == 1)
	{
		iType = vType.GetNumeric();
		stFileName = vName.GetString();
		ret = This->SaveAs(stFileName, (enum CSheetSaveAsType)iType);
	}

	SET_WRAP_FUNC(SheetDocSaveAs)
	return ret;
}

int CWrapModule::WrapReadHistory(void)
{
	CRepHistory* This = (CRepHistory*)this;
	SET_ORIGIN_FUNC(ReadHistory)

	CValue vS = This->m_strName;
	CValue vF = 1;

	CValue *lArray[2] = {&vS, &vF};

	CEventsManager::GetManager().SendEvent(This->m_pDoc, meOnReadRepHistory, lArray);

	int ret = 1;
	if(vF.GetNumeric() == 1)
		ret = This->Read();

	SET_WRAP_FUNC(ReadHistory)
	return ret;
};

int CWrapModule::WrapWriteHistory(void)
{
	CRepHistory* This = (CRepHistory*)this;
	SET_ORIGIN_FUNC(WriteHistory)

	CValue vS = This->m_strName;
	CValue vF = 1;
	CValue *lArray[2] = {&vS, &vF};

	CEventsManager::GetManager().SendEvent(This->m_pDoc, meOnWriteRepHistory, lArray);

	int ret = 1;
	if(vF.GetNumeric() == 1)
		ret = This->Write();
	SET_WRAP_FUNC(WriteHistory)

	return ret;
};


CBLModule7* pGlobalModuleFormEx;

AFX_PMSG origOnEnable;
typedef void (CDrawTrasparentCtrl::*PF_OnEn)(int);

// void CWrapModule::WrapAssignSource(LPCSTR lpcSource)
// {
// 	CBLModule7* This = (CBLModule7*)this;
// 
// 	SET_ORIGIN_FUNC(AssignSource)
// 
// 	try
// 	{
// 		if(This && This->pIntInfo)
// 		{
// 			CMetaDataCont* pMDCont = NULL;
// 			CString name = GetModuleFullName(This->m_nID, This->m_strModulePath, 0, pMDCont);
// 			if(!name.IsEmpty())
// 			{
// 				CString strFullName = "";
// 				CApp7* pApp7 = (CApp7*) AfxGetApp();
// 				if(pApp7)
// 				{
// 					if(CProfile7* pProfile7 = pApp7->GetProps())
// 					{
// 						strFullName.Format("%shotfix\\%s.txt",pProfile7->GetStringProp(0x01), name);
// 						
// 						CFile cFile;
// 						if(cFile.Open(strFullName, CFile::modeRead))
// 						{
// 							int l = cFile.GetLength();
// 							char* buf = (char*)malloc(l+1); // TODO а где освобождение памяти ?
// 							cFile.Read(buf, l);
// 							buf[l] = 0;
// 							cFile.Close();
// 							lpcSource = buf;
// 							CString strLog = "";
// 							strLog.Format("Горячая подмена модуля: %s", LPCSTR(name));
// 							pBkEndUI->DoStatusLine(strLog);
// 						}
// 					}
// 				}
// 			}
// 		}
// 	}
// 	catch (...)
// 	{
// 
// 	}
// 	
// 	This->AssignSource(lpcSource);
// 
// 	SET_WRAP_FUNC(AssignSource)
// 
// }

union PtrC{
	void* pV;
	PF_GHTB pGHTB;
	PF_GLTB pGLTB;
	PF_CC_TC pCC_TC;
	PF_CC pCC;
	PF_OnEn pOnEn;
	PF_ONINITUP pOnInitUp;
	PF_ONINITDLG pOnInitDlg;
	PF_ONCD pOnCloseDocument;
	AFX_PMSG pV_M;
	PF_LayF pLayF;
	PF_ONUPDATA pOnUpdateData;
	PF_LOADFORM pLoadForm;
	PF_LOADDIALOG pLoadDialog;
	//PF_DOLOADEX pDoLoadExternal;
	PF_GETDATAIMAGECOL pGetDataImageCol;
	PF_ONPRINT pOnPrint;
	PF_ONPREPAREPRINTING pOnPreparePrinting;
	PF_PPONINITDLG pPPOnInitDlg;
	PF_UNLOADADDINS pUnloadAddIns;
	PF_NEWROW pNewRow;
	PF_ONNEXTLINE pOnNextLine;
	PF_CGETDOC7 pCGetDoc7_Constructor;
	PF_ONSTARTEXECUTION pOnStartExecution;
	PF_ONENTERPROC pOnEnterProc;
	PF_ONEXITPROC pOnExitProc;
	PF_ONSTOPEXECUTION pOnStopExecution;
	//PF_DOLOADLAYOUT pDoLoadLayout;
} conv;

class CGetDoc7* CWrapModule::WrapCGetDoc7_Constructor(void)
{
	CGetDoc7* This = (CGetDoc7*)this;

	SET_ORIGIN_FUNC(CGetDoc7_Constructor)

	//CGetDoc7* ret = This->CGetDoc7();
	conv.pV = adrCGetDoc7_Constructor;
	CGetDoc7* ret = (This->*(conv.pCGetDoc7_Constructor))();

	This->m_Has_OnStartValueChoice = 1;
	This->m_Has_ProcessValueChoice = 1;
	This->m_Has_OnSelectLine = 1;

	SET_WRAP_FUNC(CGetDoc7_Constructor)
	return ret;
};

//?OnInitDialog@COlePropertyPageSite@@MAEHXZ
//	virtual int  COlePropertyPageSite::OnInitDialog(void);
int CWrapModule::WrapPPOnInitDialog(void)
{
	COlePropertyPageSite* This = (COlePropertyPageSite*)this;
	SET_ORIGIN_FUNC(PPOnInitDialog)

	conv.pV = adrPPOnInitDialog;
	int ret = (((COlePropertyPageSite*)this)->*(conv.pPPOnInitDlg))();

	SET_WRAP_FUNC(PPOnInitDialog)

	int oldCount = This->m_TabCtrl.GetRowCount();

	This->m_TabCtrl.InsertItem(This->m_TabCtrl.GetItemCount(),"FormEx",-1);

	CArraySPropPage* PropPages = (CArraySPropPage*)(&This->m_PropPages);
	int sz = PropPages->GetSize();
	int newCount = This->m_TabCtrl.GetRowCount();
	int dHc = newCount - oldCount;
	if(dHc > 0)
	{
		int tabCount = This->m_TabCtrl.GetItemCount();
		CRect rectTab;
		This->m_TabCtrl.GetItemRect(tabCount-1, rectTab);
		int dH = dHc*rectTab.Height();

		CRect rect;
		This->GetWindowRect(&rect);
		rect.bottom += dH;
		This->MoveWindow(rect);
		This->CenterWindow();
		This->m_TabCtrl.GetWindowRect(&rect);
		This->ScreenToClient(&rect);
		rect.bottom += dH;
		This->m_TabCtrl.MoveWindow(rect);

		CWnd* pWnd = This->GetWindow(GW_CHILD);
		while(pWnd)
		{
			if(pWnd->GetSafeHwnd() != This->m_TabCtrl.GetSafeHwnd())
			{
				pWnd->GetWindowRect(&rect);
				This->ScreenToClient(&rect);
				rect.top += dH;
				rect.bottom += dH;
				pWnd->MoveWindow(rect);
			}
			pWnd = pWnd->GetWindow(GW_HWNDNEXT);
		}
	}
	// {9F619FBA-323F-4ea2-B0D0-379BE4F5CC62}
	const GUID clsid = { 0x9f619fba, 0x323f, 0x4ea2, { 0xb0, 0xd0, 0x37, 0x9b, 0xe4, 0xf5, 0xcc, 0x62 } };
	int n = This->FindPropertyPage(clsid);
	if(!n)
	{
		This->AddPropertyPage(clsid, NULL);
		SPropPage* newPropPage = PropPages->GetData();
		newPropPage[sz].m_DlgDoc = new CPropPageDoc;
		newPropPage[sz].m_5 = 0;
		newPropPage[sz].m_6 = 0;
		newPropPage[sz].m_DlgW = 258;
		newPropPage[sz].m_DlgH = 154;
		newPropPage[sz].m_9 = 0;
		newPropPage[sz].m_10 = 0;
		newPropPage[sz].m_ResNum = 0;
		newPropPage[sz].m_ResType = 0;
		newPropPage[sz].m_Path = "";
		newPropPage[sz].m_14 = 0;
		newPropPage[sz].m_15 = 0;
		newPropPage[sz].m_16 = 0;
		newPropPage[sz].m_17 = 0;
		newPropPage[sz].m_18 = 0;
	}

	return ret;
}

int CWrapModule::WrapOnPreparePrinting(struct CPrintInfo * pPrintInfo)
{
	int ret = 0;

	SET_ORIGIN_FUNC(OnPreparePrinting)

	CSheetView* This = (CSheetView*)this;

	if(pGlobalModuleFormEx == NULL)
		pGlobalModuleFormEx = GetGlobalModule();

	int iStatusCode = 1;

	if(pGlobalModuleFormEx)
	{
		iStatusCode = pGlobalModuleFormEx->GetStatusCode();
		pGlobalModuleFormEx->SetStatusCode(1);
	}

	CValue v0;
	CValue v1 = 0L;
	if(pPrintInfo->m_bPreview)
		v1 = 1L;
	CString st = "";
	This->GetWindowText(st);
	CValue v2 = st;
	CValue v3 = "";

	CValue *lArray[4] = {&v0, &v1, &v2, &v3};
	CSheetDoc* pSheetDoc = (CSheetDoc*)This->GetDocument();

	v2 = pSheetDoc->GetTitle();

	CBLPtr<CTableWrapEx> pTableOutputContext;
	if (GetTableOutputContextFromDocument(pSheetDoc, pTableOutputContext) 
		&& static_cast<bool>(pTableOutputContext))
 			v0.AssignContext(pTableOutputContext);

	conv.pV = adrOnPreparePrinting;
	ret = (This->*(conv.pOnPreparePrinting))(pPrintInfo);

	if(ret)
	{
		if(pGlobalModuleFormEx)
		{
			LPDEVNAMES lpDev = *((LPDEVNAMES*)pPrintInfo->m_pPD->m_pd.hDevNames);
			
			v3 = CString((LPCSTR)lpDev + lpDev->wDeviceOffset);
			
			CEventsManager::GetManager().SendEventToGlobalModules(meOnPrintTable, lArray);
		
			ret = pGlobalModuleFormEx->GetStatusCode();
			pGlobalModuleFormEx->SetStatusCode(iStatusCode);
		}
	}

	SET_WRAP_FUNC(OnPreparePrinting)

	return ret;
}

void CWrapModule::WrapOnPrint(class CDC * pDC,struct CPrintInfo * pPrintInfo)
{
	SET_ORIGIN_FUNC(OnPrint)

	CSheetView* This = (CSheetView*)this;

// 	if(pGlobalModuleFormEx == NULL)
// 		pGlobalModuleFormEx = GetGlobalModule();
// 
// 	int iStatusCode = 1;
// 
// 	if(pGlobalModuleFormEx)
// 	{
// 		iStatusCode = pGlobalModuleFormEx->GetStatusCode();
// 		pGlobalModuleFormEx->SetStatusCode(1);
// 	}
// 
// 	CValue v0;
// 	CValue v1 = 0L;
// 	if(pPrintInfo->m_bPreview)
// 		v1 = 1L;
// 	CString st = "";
// 	This->GetWindowText(st);
// 	CValue v2 = st;
// 
// 	CValue *lArray[3] = {&v0, &v1, &v2};
// 	CSheetDoc* pSheetDoc = (CSheetDoc*)This->GetDocument();
// 
// 	v2 = pSheetDoc->GetTitle();
// 
// 	CBLContext* pTabCont = CBLContext::CreateInstance("Table");
// 	if(pTabCont)
// 	{
// 		((CTableWrapEx*)pTabCont)->m_pSheetDocOut = pSheetDoc;
// 		((CTableWrapEx*)pTabCont)->dwFlag1 = CTemplate7::GetDocumentID(pSheetDoc);
// 		DWORD dw = (DWORD)pSheetDoc;
// 		((CTableWrapEx*)pTabCont)->dwFlag2 = (dw + 0xB0);
// 		((DWORD*)pTabCont)[0x118] = 1;
// 		((DWORD*)pTabCont)[0x11D] = 1;
// 		v0.AssignContext(pTabCont);
// 	}
// 
// 
// 	_CallFromGlobalModules(NULL,NULL,"ПриОтправкеНаПечать","PrePrint",3,lArray);
// 
// 	if(pGlobalModuleFormEx)
// 	{
// 		if(pGlobalModuleFormEx->GetStatusCode() == 1)
// 		{
// 			conv.pV = adrOnPrint;
// 			(This->*(conv.pOnPrint))(pDC, pPrintInfo);
// 		}
// 		pGlobalModuleFormEx->SetStatusCode(iStatusCode);
// 	}
// 	else
// 	{
 		conv.pV = adrOnPrint;
 		(This->*(conv.pOnPrint))(pDC, pPrintInfo);
// 	}
// 
// //	if(!pPrintInfo->m_bPreview)
// //		_CallFromGlobalModules(NULL,NULL,"ПослеОтправкиНаПечать","PostPrint",3,lArray);
//

	SET_WRAP_FUNC(OnPrint)
}

void CWrapModule::WrapOnMDIActivate(int bActivate,class CWnd * pActivateWnd,class CWnd * pDeactivateWnd)
{
	CChildFrame7* This = (CChildFrame7*)this;

	SET_ORIGIN_FUNC(OnMDIActivate)
	This->OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
	SET_WRAP_FUNC(OnMDIActivate)

	if(bActivate)
		//_CallModuleProc((CGetDoc7*)This->GetActiveDocument(),"ПриАктивацииОкна","OnActivateWindow",0,NULL);
// 		if (CEventsManager::GetManager().IsHandlerExists((CGetDoc7*)This->GetActiveDocument(), meOnActivateWindow))
			CEventsManager::GetManager().SendEvent((CGetDoc7*)This->GetActiveDocument(), meOnActivateWindow, NULL);
	else
		//_CallModuleProc((CGetDoc7*)This->GetActiveDocument(),"ПриДеактивацииОкна","OnDeactivateWindow",0,NULL);
// 		if (CEventsManager::GetManager().IsHandlerExists((CGetDoc7*)This->GetActiveDocument(), meOnDeactivateWindow))
			CEventsManager::GetManager().SendEvent((CGetDoc7*)This->GetActiveDocument(), meOnDeactivateWindow, NULL);
}

int  CWrapModule::WrapSetIndicators(unsigned int const * num1,int num2)
{
	SET_ORIGIN_FUNC(SetIndicators)

	SECStatusBar* pStatus = (SECStatusBar*)this;

	pStatus->SetIndicators(num1, num2);

	SET_WRAP_FUNC(SetIndicators)

	CInitFormEx::Get().SetIndicatorsForStatusBar(pStatus, num1, num2);

	return 1;
}

/*
void  CWrapModule::WrapUpdateAllPanes(int num1,int num2)
{
	SET_ORIGIN_FUNC(UpdateAllPanes)

	SECStatusBar* pStatus = (SECStatusBar*)this;

	pStatus->UpdateAllPanes(num1, num2);

	SET_WRAP_FUNC(UpdateAllPanes)

//	if((num1 == 1) && (num2 == 1))
//		CInitFormEx::Get().pStatusBarManager->UpdateSystemPanes();
}

int  CWrapModule::WrapSetPaneText(int PaneIndex, const char * buf, int count)
{
	SET_ORIGIN_FUNC(SetPaneText)

	SECStatusBar* pStatus = (SECStatusBar*)this;

	int ret = pStatus->SetPaneText(PaneIndex, buf, count);

	SET_WRAP_FUNC(SetPaneText)

	//CInitFormEx::Get().pStatusBarManager->SetSystemPaneText(PaneIndex, buf, count);

	return ret;
}
*/

/*
BOOL  CWrapModule::WrapOnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
	SET_ORIGIN_FUNC(OnCmdMsg)

	CTabFrame* This = (CTabFrame*)this;

	BOOL ret = This->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

	if(nCode == CN_UPDATE_COMMAND_UI)
	{
		if(nID == 0x2711)
		{
			CValue vID = nID;
			CValue vRes = 0L;
			CValue *lArray[2] = {&vID, &vRes};
			CEventsManager::GetManager().SendEvent((CGetDoc7*)This->GetActiveDocument(), meTestCommandEnable, lArray);

			if(vRes.GetNumeric() == 0L) ((CCmdUI*)pExtra)->Enable(FALSE);
			else ((CCmdUI*)pExtra)->Enable(TRUE);
		}
	}

	SET_WRAP_FUNC(OnCmdMsg)

	return ret;
}
*/

void  CWrapModule::WrapOnLButtonDblClk(unsigned int uiID,class CPoint Point)
{
	SET_ORIGIN_FUNC(OnLButtonDblClk)

	SECControlBar* pControlBar = (SECControlBar*)this;

	pControlBar->OnLButtonDblClk(uiID, Point);

	SECStatusBar* pStatusBar = (SECStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);

	HWND hWndStatusBar = (HWND)pStatusBar;
	HWND hWndControlBar = (HWND)pControlBar;

	if(hWndStatusBar == hWndControlBar)
	{
		int count = pStatusBar->GetCount();

		UINT nID;
		UINT nStyle;
		int cxWidth;
		CString csTitle;
		RECT rect;
		CRect cRect;
		
		for(int i = 0; i<count; i++)
		{
			pStatusBar->GetPaneInfo(i,nID,nStyle,cxWidth);
			pStatusBar->GetPaneText(i,csTitle);
			pStatusBar->GetItemRect(i, &rect);
			cRect = rect;

			if(cRect.PtInRect(Point))
			{
				CValue cVal;
				cVal = nID;
				CValue* pVal;
				pVal = &cVal;
				CEventsManager::GetManager().SendEventForActiveForm(meOnLDblClkStatusBar, &pVal);
			}

		}
	}

	SET_WRAP_FUNC(OnLButtonDblClk)
}

//CGetDoc7::OnCloseDocument
void CWrapModule::WrapOnCloseDocument(void)
{
	SET_ORIGIN_FUNC(OnCloseDocument)

	CGetDoc7* This = (CGetDoc7*)this;
	BOOL bAutoDelete = This->m_bAutoDelete;
	This->m_bAutoDelete = FALSE;

	// отсоединение присоединенной к форме формы
	CFormView* pFView0 = static_cast<CFormView*>(GetFormView(This));
	if(pFView0)
	{
		CWnd* pWnd = pFView0->GetParent();
		if(CString("CFormExFormView") == pWnd->GetRuntimeClass()->m_lpszClassName)
		{
			if(CSplitterWnd* pSWnd = (CSplitterWnd*)pWnd->GetParent())
			{
				int szCol = pSWnd->GetColumnCount();
				int szRow = pSWnd->GetRowCount();
				CFormExFormView* pExFormView = NULL;
				for(int iCol = 0; (iCol < szCol) && (pExFormView == NULL); iCol++)
					for(int iRow = 0; (iRow < szRow) && (pExFormView == NULL); iRow++)
					{
						if(CFormExFormView* pPane = (CFormExFormView*)pSWnd->GetPane(iRow,iCol))
							if(pPane->m_bAttached == true)
								pExFormView = pPane;
					}
				if(pExFormView)
				{
					CFrameWnd* pWndFrame = pExFormView->m_frame;
					pExFormView->m_frame = NULL;
					CMDIFrameWnd* pMain = GetMainFrame();
					pWndFrame->SetParent(CWnd::FromHandle(pMain->m_hWndMDIClient));
					CWnd* pWnd = pExFormView->GetWindow(GW_CHILD);
					while(pWnd)
					{
						pWnd->SetParent(pWndFrame);
						pWnd = pExFormView->GetWindow(GW_CHILD);
					}
					pWndFrame->ShowWindow(SW_SHOW);
					((CTabFrame*)pWndFrame)->RecalcLayout(1);
				}
			}
		}

		// отсоединение присоединенной к реквизиту формы
		CWnd* pWndCld1 = pFView0->GetWindow(GW_CHILD);
		while(pWndCld1)
		{
			CWnd* pWndCld2 = pWndCld1;//->GetWindow(GW_CHILD);
			if(pWndCld2)
			{
				if(CString("CSplitterWnd") == pWndCld2->GetRuntimeClass()->m_lpszClassName)
				{
					CSplitterWnd* pSWnd = (CSplitterWnd*)pWndCld2;

					CFormExFormView* pPane = (CFormExFormView*)pSWnd->GetPane(0,0);
					if(pPane)
					{
						CFrameWnd* pWndFrame = pPane->m_frame;
						if(pWndFrame)
						{
							pPane->m_frame = NULL;
//							CMDIFrameWnd* pMain = GetMainFrame();
//							pWndFrame->SetParent(CWnd::FromHandle(pMain->m_hWndMDIClient));
							CWnd* pWnd = pPane->GetWindow(GW_CHILD);
							while(pWnd)
							{
								pWnd->SetParent(pWndFrame);
								pWnd = pPane->GetWindow(GW_CHILD);
							}
							pWndFrame->ShowWindow(SW_SHOW);
							((CTabFrame*)pWndFrame)->RecalcLayout(1);
						}
					}
				}
			}
			pWndCld1 = pWndCld1->GetNextWindow();
		}
	}

	conv.pV = adrOnCloseDocument;
	(This->*(conv.pOnCloseDocument))();

	SET_WRAP_FUNC(OnCloseDocument)

	//_CallModuleProc(This,"ПослеЗакрытия","OnClosed",0,NULL);
// 	if (CEventsManager::GetManager().IsHandlerExists(This, meOnClosed))
		CEventsManager::GetManager().SendEvent(This, meOnClosed, NULL);
	CEventsManager::GetManager().RemoveDocument(This);

	This->m_bAutoDelete = bAutoDelete;
	if(bAutoDelete)
	{
		CDocument* ThisDoc = (CDocument*)this;
		delete ThisDoc;
	}
}

class CGetDlgMy: public CGetDlg
{
public:
	CGetDlgMy(UINT uTempl,CWnd * pParent):CGetDlg(uTempl,pParent)
	{
	};

	static void SetLParam(long lNewParam)
	{
		m_lParam = lNewParam;
	};
	static long GetLParam(void)
	{
		return m_lParam;
	};

	virtual int DoModal()
	{
		// can be constructed with a resource template or InitModalIndirect
		ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
			m_lpDialogTemplate != NULL);

		// load resource as necessary
		LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
		HGLOBAL hDialogTemplate = m_hDialogTemplate;
		HINSTANCE hInst = AfxGetResourceHandle();
		if (m_lpszTemplateName != NULL)
		{
			hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
			HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
			hDialogTemplate = LoadResource(hInst, hResource);
		}
		if (hDialogTemplate != NULL)
			lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

		// return -1 in case of failure to load the dialog template resource
		if (lpDialogTemplate == NULL)
			return -1;

		// disable parent (before creating dialog)
		HWND hWndParent = PreModal();
		AfxUnhookWindowCreate();
		BOOL bEnableParent = FALSE;
		if (hWndParent != NULL && ::IsWindowEnabled(hWndParent))
		{
			::EnableWindow(hWndParent, FALSE);
			bEnableParent = TRUE;
		}

		TRY
		{
			// create modeless dialog
			AfxHookWindowCreate(this);
			if (CreateDlgIndirect(lpDialogTemplate,
							CWnd::FromHandle(hWndParent), hInst))
			{
				if (m_nFlags & WF_CONTINUEMODAL)
				{
					// enter modal loop
					DWORD dwFlags = MLF_SHOWONIDLE;
					if (GetStyle() & DS_NOIDLEMSG)
						dwFlags |= MLF_NOIDLEMSG;
//					VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
				}

				// hide the window before enabling the parent, etc.
//				if (m_hWnd != NULL)
//					SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
//						SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
			}
		}
		CATCH_ALL(e)
		{
			DELETE_EXCEPTION(e);
			m_nModalResult = -1;
		}
		END_CATCH_ALL

		if (bEnableParent)
			::EnableWindow(hWndParent, TRUE);
		if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
			::SetActiveWindow(hWndParent);

		// destroy modal window
//		DestroyWindow();
//		PostModal();

		// unlock/free resources as necessary
		if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
			UnlockResource(hDialogTemplate);
		if (m_lpszTemplateName != NULL)
			FreeResource(hDialogTemplate);

		return m_nModalResult;
	};

	DECLARE_MESSAGE_MAP()

	void OnDestroy(void);
};

BEGIN_MESSAGE_MAP(CGetDlgMy, CGetDlg)
	ON_WM_DESTROY()
END_MESSAGE_MAP()

void CGetDlgMy::OnDestroy(void)
{
};

//CGetDlg::OpenDocumentFileEx CPlex
void  WrapOpenDocumentFileEx(UINT a_uParam1,LPCSTR a_chStr,long a_lParam,CValue * a_pVal,UINT a_uParam2,UINT a_uParam3,UINT a_uParam4,UINT a_uParam5)
{
	SET_ORIGIN_FUNC(OpenDocumentFileEx)

	if(pWndToDock)
	{
		CWnd* l_pWndToDock = pWndToDock;
		pWndToDock = NULL;

		SET_WRAP_FUNC(OpenDocumentFileEx)

		CGetDlgMy::SetLParam(a_lParam);
		CGetDlgMy* pGetDlg;
		if(l_pWndToDock->IsKindOf(RUNTIME_CLASS(CSizingControlBar)))
		{
			pGetDlg = new CGetDlgMy(a_uParam3,pWndToDock);
		}
		else
		{
			pGetDlg = new CGetDlgMy(a_uParam3,NULL);
		}

		if(a_pVal)
		{
			CType cType(0);
			cType.m_flags = 0;
			cType.m_length = 0;
			cType.m_mdid = 0;
			cType.m_prec = 0;
			cType.type = 0;
			a_pVal->SetType(cType);
		}
		pGetDlg->m_pValue = a_pVal;
		pGetDlg->bufGetDlg[0x00] = a_uParam2;
		pGetDlg->bufGetDlg[0x01] = a_uParam4;
		pGetDlg->bufGetDlg[0x02] = a_uParam5;

		pGetDlg->m_TemplID = a_uParam1;
		pGetDlg->m_cStr = a_chStr;

		//SetModalMode(1);
		SetModalMode(0);

		int n = 0;

		while(((CApp7*)pApp)->IsWaiting())
		{
			((CApp7*)pApp)->StopWait(0xE001);
			n++;
		}

		pGetDlg->DoModal();

		if(l_pWndToDock->IsKindOf(RUNTIME_CLASS(CSizingControlBar)))
		{
			pGetDlg->ModifyStyle(WS_POPUPWINDOW|DS_MODALFRAME|WS_CAPTION,WS_CHILD);
			pGetDlg->ModifyStyleEx(WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, 0);
			pGetDlg->SetParent(l_pWndToDock);
			((CSizingControlBar*)l_pWndToDock)->m_pChildDlg = pGetDlg;
		}

		while(n > 0)
		{
			n--;
			((CApp7*)pApp)->StartWait();
		}

		//SetModalMode(0);

		CGetDlgMy::SetLParam(0);
	}
	else
	{
		CGetDlg::OpenDocumentFileEx(a_uParam1,a_chStr,a_lParam,a_pVal,a_uParam2,a_uParam3,a_uParam4,a_uParam5);
		SET_WRAP_FUNC(OpenDocumentFileEx)
	}
}

//CGetDlg::OnInitDialog
int CWrapModule::WrapOnInitDialog(void)
{
	CGetDlg* This = (CGetDlg*)this;
	SET_ORIGIN_FUNC(OnInitDialog)

	conv.pV = adrOnInitDialog;
	int ret = (This->*(conv.pOnInitDlg))();

	SET_WRAP_FUNC(OnInitDialog)
//*
	int iStatusCode = 1;
	if(This->m_pDoc)
	{
		CBLModule7* pMod = This->m_pDoc->m_pBLModule;
		if(pMod)
			iStatusCode = pMod->GetStatusCode();
	}
	if(iStatusCode)
	{
		This->Invalidate();
		This->CenterWindow();
		This->UpdateData();
		This->ShowWindow(SW_SHOW);
		This->RedrawWindow();
		
			CEventsManager::GetManager().SendEvent(This->m_pDoc, meOnActivate, NULL);

		if(!m_bNoInvalidate) This->Invalidate();
	}
//*/
  return ret;
}

//CBrowseView7::OnInitialUpdate
void CWrapModule::WrapOnInitialUpdate(void)
{
	SET_ORIGIN_FUNC(OnInitialUpdate)

	conv.pV = adrOnInitialUpdate;
	(((CBrowseView7*)this)->*(conv.pOnInitUp))();

	SET_WRAP_FUNC(OnInitialUpdate)

	CGetDoc7* pDoc = ((CBrowseView7*)this)->GetDocument();

	int iStatusCode = 0;
	if(pDoc)
	{
		CBLModule7* pMod = pDoc->m_pBLModule;
		if(pMod)
			iStatusCode = pMod->GetStatusCode();
	}
	if(iStatusCode)
	{
		CWnd* pWnd = ((CBrowseView7*)this)->GetParent();
		if(pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
		{
			CSplitterWnd* pSplitterWnd = (CSplitterWnd*)pWnd;
			int countCol = pSplitterWnd->GetColumnCount();
			int countRow = pSplitterWnd->GetRowCount();
			for(int iCol = 0; iCol < countCol; iCol++)
				for(int iRow = 0; iRow < countRow; iRow++)
				{
					CWnd* pPane = pSplitterWnd->GetPane(iRow, iCol);
					if(pPane->IsKindOf(RUNTIME_CLASS(CSheetView)))
					{
						CSheetViewMy* pSheetView = (CSheetViewMy*)pPane;
						pSheetView->OnInitialUpdate();
					}
				}
		}

// АЛьФ ------------------>
// перерисовка вызывает торможение при открытии форм (формы открываются в два раза медленней)
// однако без перерисовки возможны глюки при включении своей отрисовки контролов.
// пока убираю, но на будущее необходимо это дело запомнить.
// <------------------- АЛьФ

		ActivateOpenDocFrame(pDoc);
//		pMainWindow->RedrawWindow();
		
		//_CallModuleProc(pDoc,"ПослеОткрытия","OnActivate",0,NULL);
// 		if (CEventsManager::GetManager().IsHandlerExists(pDoc, meOnActivate))
			CEventsManager::GetManager().SendEvent(pDoc, meOnActivate, NULL);
		
		pDoc->UpdateAllViews(NULL);
		if(!m_bNoInvalidate)
		{
			((CBrowseView7*)this)->RedrawWindow();
			pMainWindow->RedrawWindow();
		}
	}
}

//CGetDoc::UpdateData
//CGetDoc7::UpdateWatchs(int,int,int,class CGetField *)
int  CWrapModule::WrapUpdateData(int i1,unsigned int ui1)
//void CWrapModule::WrapUpdateWatchs(int f1, int f2, int f3, class CGetField * pField)
{
	int ret = 0;
	SET_ORIGIN_FUNC(UpdateData)

	conv.pV = adrUpdateData;
	ret = (((CGetDoc7*)this)->*(conv.pOnUpdateData))(i1, ui1);

	SET_WRAP_FUNC(UpdateData)

		// TODO возможны тормоза при работе в "толстых" формах - журналах, документах, справочниках
////	_CallModuleProc((CGetDoc7*)this,"ПослеОбновленияФормы","OnRefresh",0,NULL);
//  	if (CEventsManager::GetManager().IsHandlerExists((CGetDoc7*)this, meOnRefresh))
 		CEventsManager::GetManager().SendEvent((CGetDoc7*)this, meOnRefresh, NULL);

	return ret;
}

//CGetDoc7::WrapLoadDialog
int  CWrapModule::WrapLoadDialog(long lID,char const * pFolder)
{
	int ret = 0;
	SET_ORIGIN_FUNC(LoadDialog)

	long _lID = lID;
	char const * _pFolder = pFolder;
	CEditDoc* pEditDoc = NULL;

	CGetDoc7* This = (CGetDoc7*)this;

	CValue cVal;
	CValue* pVal;
	pVal = &cVal;
	CTypedCont* pCont=NULL;
	CString name;
	CConfigCont::IDToPath(lID, pFolder, name, &pCont, FALSE);
	if(pCont)
	{
		CWorkBookDoc* pWBDoc = pCont->GetWorkBook();
		if(pWBDoc)
		{
			pEditDoc = (CEditDoc*)pWBDoc->GetDEditDocument();
		}
	}

	CMetaDataCont * pMDCont = NULL;

	if (lID > 0)
		name = GetModuleFullName(lID, pFolder, 0, pMDCont);
	else
		name = "НеизвестныйОбъект";

	cVal = name;

	//_CallFromGlobalModules(NULL,NULL,"ПриЗагрузкеФормы","OnLoadForm",1,&pVal);
// 	if (CEventsManager::GetManager().IsHandlerExists(meOnLoadForm))
		CEventsManager::GetManager().SendEventToGlobalModules(meOnLoadForm, &pVal);

	CString nameNew;
	nameNew = cVal.GetString();
	nameNew.MakeUpper();
	if(name.CollateNoCase(nameNew) != 0)
	{
// 		SDocNames *pDocNames = NULL;
// 		if(DocNamesArray.Lookup(nameNew, (void*&)pDocNames))
// 		{
// 			_lID = pDocNames->id;
// 			_pFolder = LPCSTR(pDocNames->strFolder);
// 		}
		CAllFormsNamesManager::Get()->Lookup(nameNew, &_lID, &_pFolder); //CAllFormsNamesManager::Get()->Lookup(&_lID, &_pFolder);
	}

	conv.pV = adrLoadDialog;
	ret = (This->*(conv.pLoadDialog))(_lID, _pFolder);

	SET_WRAP_FUNC(LoadDialog)

	CEditDoc* pEditDocNew = This->m_pEditDoc;
	if((pEditDoc != NULL) && (pEditDocNew != NULL) && (pEditDocNew != pEditDoc))
	{
		int szN = pEditDocNew->m_extListSA.GetSize();
		if(szN == 0)
		{
			int sz = pEditDoc->m_extListSA.GetSize();
			int szU = pEditDoc->m_extListUA.GetSize();
			for(int i = 0; i < sz; i++)
			{
				CString str = pEditDoc->m_extListSA.GetAt(i);
				UINT n = 1;
				pEditDocNew->m_extListSA.Add(str);
				pEditDocNew->m_extListUA.Add(n);
				CCtrlHolder* pCtrl = (CCtrlHolder*)pEditDoc->m_extCtrlArray.GetAt(i);

				if(pCtrl)
				{
					POSITION pos = pEditDocNew->m_objList.GetHeadPosition();
					while(pos)
					{
						CCtrlHolder* pCtrlNew = (CCtrlHolder*)pEditDocNew->m_objList.GetNext(pos);
						if(pCtrlNew)
						{
							if(str.CompareNoCase(pCtrlNew->m_pName) == 0)
							{
								pCtrlNew->m_ID = pCtrl->m_ID;
								pos = NULL;
							}
						}
					}
					pos = This->m_cControlList.GetHeadPosition();
					while(pos)
					{
						CControlID* pControlIDNew = (CControlID*)This->m_cControlList.GetNext(pos);
						if(pControlIDNew)
						{
							if(str.CompareNoCase(pControlIDNew->m_CodeName) == 0)
							{
								pControlIDNew->m_LongID = pCtrl->m_ID;
								pos = NULL;
							}
						}
					}
				}
			}
		}
	}

	return ret;
}

//CGetDoc7::LoadForm
int  CWrapModule::WrapLoadForm(long lID,char const * pFolder)
{
	int ret = 0;
	SET_ORIGIN_FUNC(LoadForm)

	long _lID = lID;
	char const * _pFolder = pFolder;
	CEditDoc* pEditDoc = NULL;

	CGetDoc7* This = (CGetDoc7*)this;

	CValue cVal;
	CValue* pVal;
	pVal = &cVal;
	CTypedCont* pCont=NULL;
	CString name;
	CConfigCont::IDToPath(lID, pFolder, name, &pCont, FALSE);
	if(pCont)
	{
		CWorkBookDoc* pWBDoc = pCont->GetWorkBook();
		if(pWBDoc)
		{
			pEditDoc = (CEditDoc*)pWBDoc->GetDEditDocument();
		}
	}

	CMetaDataCont * pMDCont = NULL;

	if (lID > 0)
		name = GetModuleFullName(lID, pFolder, 0, pMDCont);
	else
		name = "НеизвестныйОбъект";

	cVal = name;

	//_CallFromGlobalModules(NULL,NULL,"ПриЗагрузкеМодуляФормы","OnLoadFormModule",1,&pVal);
// 	if (CEventsManager::GetManager().IsHandlerExists(meOnLoadFormModule))
		CEventsManager::GetManager().SendEventToGlobalModules(meOnLoadFormModule, &pVal);

	CString nameNew;
	nameNew = cVal.GetString();
	nameNew.MakeUpper();
	if(name.CollateNoCase(nameNew) != 0)
	{
// 		SDocNames *pDocNames = NULL;
// 		if(DocNamesArray.Lookup(nameNew, (void*&)pDocNames))
// 		{
// 			_lID = pDocNames->id;
// 			_pFolder = LPCSTR(pDocNames->strFolder);
// 		}
		CAllFormsNamesManager::Get()->Lookup(nameNew, &_lID, &_pFolder); //CAllFormsNamesManager::Get()->Lookup(&_lID, &_pFolder);
	}

	conv.pV = adrLoadForm;
	ret = (This->*(conv.pLoadForm))(_lID, _pFolder);

	SET_WRAP_FUNC(LoadForm)

	return ret;
}

//CEditDoc::DoLoadExternal
int CWrapModule::WrapDoLoadExternal(LPCSTR a_strFileName)
{
	int ret = 0;
	SET_ORIGIN_FUNC(DoLoadExternal)

	CEditDoc* This = (CEditDoc*)this;

	CString csFileName = CString(a_strFileName);
	if(csFileName.Right(14).CompareNoCase("\\Dialog Stream") == 0)
		csFileName = csFileName.Left(csFileName.GetLength() - 14);

	CValue vFileName = csFileName;
	CValue *lArray[1] = {&vFileName};

	int iStatusCode = pGlobalModuleFormEx->GetStatusCode();
	pGlobalModuleFormEx->SetStatusCode(1);

	//_CallFromGlobalModules(NULL,NULL,"ПриЗагрузкеВнешнегоОтчета","OnLoadAsExternalForm",1,lArray);
// 	if (CEventsManager::GetManager().IsHandlerExists(meOnLoadAsExternalForm))
		CEventsManager::GetManager().SendEventToGlobalModules(meOnLoadAsExternalForm, lArray);

	if(pGlobalModuleFormEx->GetStatusCode() == 0)
		ret = 1;
	else
	{
		//csFileName = vFileName.GetString() + "\\Dialog Stream";
		//Msg("DoLoadExternal: %s", csFileName);
		//conv.pV = adrDoLoadExternal;
		//ret = (This->*(conv.pDoLoadExternal))((LPCSTR)s_strFileName);
		//ret = This->DoLoadExternal(csFileName);
		ret = This->DoLoadExternal(a_strFileName);
	}

	pGlobalModuleFormEx->SetStatusCode(iStatusCode);

	SET_WRAP_FUNC(DoLoadExternal)

	return ret;
}

int CWrapModule::WrapDoLoadLayout(LPCSTR a_strFileName)
{
	int ret = 0;
	SET_ORIGIN_FUNC(DoLoadLayout)

	CEditDoc* This = (CEditDoc*)this;

	CString csFileName = a_strFileName;
	if(csFileName.Right(14).CompareNoCase("\\Dialog Stream") == 0)
		csFileName = csFileName.Left(csFileName.GetLength() - 14);

	CValue vFileName = csFileName;
	CValue *lArray[1] = {&vFileName};

	CEventsManager::GetManager().SendEventToGlobalModules(meOnLoadAsExternalDialog, lArray);

	CString csNewFileName = vFileName.GetString();
	BOOL bDeletOle = FALSE;
	COleStorage* pOleStorage;
	if(csFileName.CompareNoCase(csNewFileName) != 0)
	{
		csNewFileName = csNewFileName + "\\Dialog Stream";

		CString csPath = "";
		CString csFile = "";
		GetFilePathAndName(csNewFileName, csPath, csFile);
		pOleStorage = COleStorage::FindStorage(csPath);
		if(!pOleStorage)
		{
			pOleStorage = new COleStorage(NULL);
			bDeletOle = pOleStorage->Open(csPath, 0x10, NULL);
		}

		csFileName = csNewFileName;
	}
	else
		csFileName = a_strFileName;

	ret = This->DoLoadLayout(csFileName);
	if(bDeletOle) delete pOleStorage;

	SET_WRAP_FUNC(DoLoadLayout)

	return ret;
}

void CWrapModule::WrapUnloadAddIns(void)
{
	SET_ORIGIN_FUNC(UnloadAddIns)

	{
		CLoadedAddInDllInfo* pDllContext = CLoadedAddInDllInfo::GetCurrentAddInDllInfo();
		if(pDllContext)
		{
			int s = pDllContext->m_pPtrArray.GetSize();
			for(int i = 0; i < s; i++)
			{
				CAddInDll_SEvent* pEvent = pDllContext->m_pPtrArray.GetAt(0);
				int ss = pEvent->m_SubEvent.m_strArr.GetSize();
				for(int ii = 0; ii < ss; ii++)
				{
					CAddInDll_SEventStr* pEventStr = (CAddInDll_SEventStr*)pEvent->m_SubEvent.m_strArr.GetAt(0);
					delete pEventStr;
					pEvent->m_SubEvent.m_strArr.RemoveAt(0);
				}
				delete pEvent;
				pDllContext->m_pPtrArray.RemoveAt(0);
			}
		}
	}

	CApp7* This = (CApp7*)this;
	//conv.pV = adrUnloadAddIns;
	//(This->*(conv.pUnloadAddIns))();
	//SET_WRAP_FUNC(GetData)
	__asm{
		mov	ecx, [This]
		pop	edi
		pop	esi
		pop	ebx
		mov	esp,ebp
		pop	ebp
		jmp [adrUnloadAddIns]
	}
}

void CWrapModule::WrapGetData(CString& a_Str)
{
	SET_ORIGIN_FUNC(GetData)

	CImageCol* This = (CImageCol*)this;
	conv.pV = adrGetData;
	(This->*(conv.pGetDataImageCol))(a_Str);

	SET_WRAP_FUNC(GetData)

	CBrowse* pBr = This->m_Browse;
	if(pBr)
	{
		CWnd* pParent = pBr->GetParent();
		if(pParent)
		{
			CGetDoc7* pDoc = NULL;
			if(pParent->IsKindOf(RUNTIME_CLASS(CGetDlg)))
			{
				pDoc = ((CGetDlg*)pParent)->m_pDoc;
			}
			else if(pParent->IsKindOf(RUNTIME_CLASS(CBrowseView7)))
			{
				pDoc = ((CBrowseView7*)pParent)->GetDocument();
			}
			CValue vPicNum = a_Str;
			CValue *lArray[1] = {&vPicNum};
			
			//_CallModuleProc(pDoc,"ПиктограммаМногострочнойЧасти","MultiLinePic",1,lArray);
// 			if (CEventsManager::GetManager().IsHandlerExists(pDoc, meOnMultiLinePic))
				CEventsManager::GetManager().SendEvent(pDoc, meOnMultiLinePic, lArray);

			a_Str = vPicNum.Format();
		}
	}
}

int  CWrapModule::WrapLayoutForm(class CFormView * pFormView)
{
	int ret = 0;
	SET_ORIGIN_FUNC(LayoutForm)

	conv.pV = adrLayoutForm;
	ret = (((CGetDoc7*)this)->*(conv.pLayF))(pFormView);

	SET_WRAP_FUNC(LayoutForm)

	//_CallModuleProc(reinterpret_cast<CGetDoc7*>(this),"ПослеСозданияФормы","OnCreateForm",0,NULL);
// 	if (CEventsManager::GetManager().IsHandlerExists(reinterpret_cast<CGetDoc7*>(this), meOnCreateForm))
		CEventsManager::GetManager().SendEvent(reinterpret_cast<CGetDoc7*>(this), meOnCreateForm, NULL);

	return ret;
}

int  CWrapModule::WrapGetHiTrackBound(int iNum)
{
	int ret = 0;
	SET_ORIGIN_FUNC(GetHiTrackBound)

	/*
	UINT uFlag = ((DWORD*)this)[0x27];
	if(uFlag == 0)
	{
		CRect cRect;
		((CBrowse*)this)->GetCellRect(cRect,0,iNum);
		ret = cRect.right+1;
	}
	else
	{
		conv.pV = adrGetHiTrackBound;
		ret = (((CBrowse*)this)->*(conv.pGHTB))(iNum);
	}
	*/
	conv.pV = adrGetHiTrackBound;
	ret = (((CBrowse*)this)->*(conv.pGHTB))(iNum);

	SET_WRAP_FUNC(GetHiTrackBound)

	return ret;
}

int  CWrapModule::WrapGetLoTrackBound(int iNum)
{
	int ret = 0;
	SET_ORIGIN_FUNC(GetLoTrackBound)

	/*
	UINT uFlag = ((DWORD*)this)[0x27];
	if(uFlag == 0)
	{
		CRect cRect;
		((CBrowse*)this)->GetCellRect(cRect,0,iNum);
		ret = cRect.right+1;
	}
	else
	{
		conv.pV = adrGetLoTrackBound;
		ret = (((CBrowse*)this)->*(conv.pGLTB))(iNum);
	}
	*/
	conv.pV = adrGetLoTrackBound;
	ret = (((CBrowse*)this)->*(conv.pGLTB))(iNum);

	SET_WRAP_FUNC(GetLoTrackBound)

	return ret;
}

struct STableParams::paramdefs STableParams::ParamNames[] =
{
	{"ЦентрироватьТекущуюСтроку", "CenterCurrentRow", tpCenterBrowse},
	{"НаПервуюСтрокуПриНовой", "TopOnAddRow", tpTopOnAddRow},
	{NULL, NULL, tpLastParam}
};

struct STableParams* STableParams::GetParams(CBrowse* pBrowse)
{

	STableParams* params = NULL;
	CString csBase = "";

//CTableColumn(0x50)->CColumn(0x40)->CCmdTarget(0x20)->CObject(0x4)->
//CGetColumn(0x48)->CColumn(0x40)->CCmdTarget(0x20)->CObject(0x4)->

//CTableSkipper(0x1c)->CSkipper(0x14)->CObject(0x4)->
//CObjectSkipper(0x20)->CSkipper(0x14)->CObject(0x4)->

	CString csParamColName = "FormEx_ПараметрыТаблицы";
	CValueTable* pTable = GetTableFromBrowse(pBrowse);
	if(pTable)
	{
		int iParamCol = pTable->GetColumnIdx(csParamColName);
		if(iParamCol >= 0)
		{
			CVTColumn * pVTColumn = pTable->GetColumn(iParamCol);
			if(pVTColumn)
				csBase = pVTColumn->GetTitle();
		}
	}
	else if(!strcmp(pBrowse->m_pSkipper->GetRuntimeClass()->m_lpszClassName,"CObjectSkipper"))
	{
		CView * pParent = (CView*)pBrowse->GetParent();
		if(pParent)
		{
			CGetDoc7* pGetDoc7 = NULL;
			if(pParent->IsKindOf(RUNTIME_CLASS(CGetDlg)))
			{
				pGetDoc7 = ((CGetDlg*)pParent)->m_pDoc;
			}
			else if(pParent->IsKindOf(RUNTIME_CLASS(CBrowseView7)))
			{
				pGetDoc7 = ((CBrowseView7*)pParent)->GetDocument();
			}
			if(pGetDoc7)
			{
				int count = pBrowse->GetColumnNum();
				CString csBuf = "";

				for(int col = 0; col < count; col++)
				{
					CColumn &Column = pBrowse->GetColumnN(col);
					CGetField* pGetField = pGetDoc7->GetField(Column.m_ID);
					if(pGetField)
						if(pGetField->m_Set)
						{
							if(csParamColName.CompareNoCase(pGetField->m_Set->m_CodeName) == 0)
							{
								csBase = pGetField->m_strCtrlTitle;
								col = count;
							}
						}
				}
			}
		}
	}

	if(!csBase.IsEmpty())
	{
		params = new STableParams;

		params->m_iCenterBrowse = -1;
		params->m_bTopOnAddRow = TRUE;

		CString csBaseUP = csBase;
		csBaseUP.MakeUpper();

		for (int i = 0; i<tpLastParam; i++)
		{
			CString csParamName = ParamNames[i].szRusName;
			csParamName.MakeUpper();
			int pos = csBaseUP.Find(csParamName);
			if(pos < 0)
			{
				csParamName = ParamNames[i].szEngName;
				csParamName.MakeUpper();
				pos = csBaseUP.Find(csParamName);
			}
			if(pos >= 0)
			{
				pos += csParamName.GetLength() + 1;
				CString csParamValue = "";
				int len = csBase.GetLength();
				char ch = '\0';
				while((pos < len) && (ch != ';'))
				{
					ch = csBase.GetAt(pos++);
					if(ch != ';') csParamValue += ch;
				}
				switch (ParamNames[i].ParamID)
				{
					case tpCenterBrowse:
						{
							params->m_iCenterBrowse = atoi(csParamValue);
							break;
						};
					case tpTopOnAddRow:
						{
							params->m_bTopOnAddRow = (0 != atoi(csParamValue));
							break;
						};
					case tpLastParam:
						{
							break;
						};
				};
			}
		}
	}

	return params;
}

void CWrapModule::Wrapcenter(void)
{
	SET_ORIGIN_FUNC(center)

	CBrowse* This = (CBrowse*)this;

	UINT uiCenterFlag = CInitFormEx::Get().m_uiCenterBrowse;


	STableParams* pTableParams = STableParams::GetParams(This);
	if(pTableParams && pTableParams->m_iCenterBrowse >= 0)
		uiCenterFlag = pTableParams->m_iCenterBrowse;

	if(uiCenterFlag == 1)
		This->center();
	else if(uiCenterFlag == 0L) // bootom
	{
		This->m_SelRow = This->m_FixRow + This->m_numRow - 1;
		This->RefreshAll();
	}
	else if(uiCenterFlag == 2) // up
	{
		This->m_SelRow = 0;
		This->RefreshAll();
	}

	SET_WRAP_FUNC(center)
}

/*
void CWrapModule::Wraptop(void)
{
	SET_ORIGIN_FUNC(top)

	CBrowse* This = (CBrowse*)this;

	This->top();

	SET_WRAP_FUNC(top)
}

void CWrapModule::Wraprefresh(void)
{
	SET_ORIGIN_FUNC(refresh)

	CBrowse* This = (CBrowse*)this;

	This->refresh();

	SET_WRAP_FUNC(refresh)
}

void CWrapModule::WrapRefreshAll(void)
{
	SET_ORIGIN_FUNC(RefreshAll)

	CBrowse* This = (CBrowse*)this;

	This->RefreshAll();


	SET_WRAP_FUNC(RefreshAll)
}

int CWrapModule::WrapNewRow(int iNum)
{
	SET_ORIGIN_FUNC(NewRow)

	CValueTable* This = (CValueTable*)this;

	CBrowse* pBrowse = GetBrowseFromTable(This);
	CString csBuf = "";

	if(pBrowse)
	{
		//This->m_bEnableRefresh = FALSE;

		CTableSkipper* pTableSkipper = (CTableSkipper*)pBrowse->m_pSkipper;
		CBLContext* pContext = pTableSkipper->m_pTableContext;
		//((DWORD*)((DWORD*)pTableSkipper)[0])[0x0D]
		csBuf.Format("NewRow (in) %i %i %i", pTableSkipper->m_dwCurrentRow, pTableSkipper->Ok(), This->GetRowCount());
		//pBkEndUI->DoMessageLine(csBuf);

		//MessageBox("1");
	}

	//int ret = This->NewRow(iNum);
	conv.pV = adrNewRow;
	int ret = (This->*(conv.pNewRow))(iNum);

	if(pBrowse)
	{
		CTableSkipper* pTableSkipper = (CTableSkipper*)pBrowse->m_pSkipper;
		pTableSkipper->m_dwCurrentRow = ret;
		pTableSkipper->m_dba = ret;
		pTableSkipper->godba(ret);

		CBLContext* pContext = pTableSkipper->m_pTableContext;
		//((DWORD*)pContext)[0x16] = ret;

		csBuf.Format("NewRow (out) %i %i %i", pTableSkipper->m_dwCurrentRow, pTableSkipper->Ok(), This->GetRowCount());
		//pBkEndUI->DoMessageLine(csBuf);

		//MessageBox("2");


		//This->m_bEnableRefresh = TRUE;
	}

	SET_WRAP_FUNC(NewRow)

	return ret;
}
*/

int CWrapModule::WrapAssignContext(class CBLContext * pCont)
{
	SET_ORIGIN_FUNC(AssignContext)

	CValue* This = (CValue*)this;

	int ret = This->AssignContext(pCont);

	SET_WRAP_FUNC(AssignContext)

	return ret;
}

class CWnd * CWrapModule::WrapCreateControl(class CGetField * pGetField,unsigned int id,class CRect const & rect,class CWnd * pParent,unsigned long style,unsigned long styleex)
{
	CControlID* set = pGetField->m_Set;
	CWnd * ret = NULL;
	SET_ORIGIN_FUNC(CreateControl)

	DWORD dwStyle = 0;
	if(set)
	{
		//dwStyle = set->m_DependParam;
		dwStyle = set->GetDependParam();
		if(bSetDrawWrap)
		{
			if((set->m_CtrlType == 0x0B) && ((dwStyle & 0x02000000) == 0))
			{
				style |= LBS_HASSTRINGS|LBS_OWNERDRAWFIXED;
			}
			else if(set->m_CtrlType == 0x0E)
			{
				style |= CBS_HASSTRINGS|CBS_OWNERDRAWFIXED;
			}
		}
	}

	ret = ((CGetDoc7*)this)->CreateControl(pGetField,id,rect,pParent,style,styleex);

	if(bSetDrawWrap)
	{
		if((ret != NULL) && (set != NULL) && (set->m_CtrlType == 0x0B) && ((dwStyle & 0x02000000) == 0))
		{
			CFormExListBox* pLB;
			pLB = new CFormExListBox;
			if(pLB)
			{
				pLB->SubclassWindow(ret->GetSafeHwnd());
				pLB->SetFont(ret->GetFont());
			}
		}
		else if((ret != NULL) && (set != NULL) && (set->m_CtrlType == 0x0E))// && ((dwStyle & 0x02000000) == 0))
		{
			CFormExComboBox* pCB;
			pCB = new CFormExComboBox;
			if(pCB)
			{
				pCB->SubclassWindow(ret->GetSafeHwnd());
				pCB->SetFont(ret->GetFont());
			}
		}

		if((ret != NULL) && (set != NULL))
		{
			if(set->m_CtrlType == 0x05)
			{
				CFont cFont;
				cFont.CreateFontIndirect(&(set->m_Font));
				HFONT hFont = (HFONT)cFont.Detach();
				ret->SetFont(CFont::FromHandle(hFont));
				ret->RedrawWindow();
			}
		}
	}

	SET_WRAP_FUNC(CreateControl)

	return ret;
}

void CWrapModule::WrapProcessSecondOpen(CValue* val)
{
	SET_ORIGIN_FUNC(ProcessSecondOpen)

	CGetDoc7* This = (CGetDoc7*)this;
	This->ProcessSecondOpen(val);

// 	CGroupContext *pCont = This->GetGroupContext();
// 	if(pCont)
// 	{
// 		CBLContext *pCont0;
// 		for(int i = 0; i<pCont->GetSize(); i++)
// 		{
// 			pCont0 = pCont->GetContext(i);
// 			if(!strcmp(pCont0->GetRuntimeClass()->m_lpszClassName,"CDocContext"))
// 				((CDocContext*)pCont0)->SetEnableNewLine(1);
// 		}
// 	}
	SetEnableNewLine(This);

	SET_WRAP_FUNC(ProcessSecondOpen)

}

void WrapDX_Text(class CGetExchange * pGet,int iID,class CValue & cVal)
{
	SET_ORIGIN_FUNC(DX_Text)

	DX_Text(pGet,iID,cVal);

	if(bSetDrawWrap)
	{
		if(pGet)
		{
			CGetCtrl* pCtrl = pGet->PrepareControl(iID);
			if(pCtrl)
			{
				CWnd* pWnd = pCtrl->GetDlgItem();
				if(pWnd)
				{
					CGetDoc7* pDoc = (CGetDoc7*)pCtrl->m_pGetDoc;
					CGetFieldsArray* pGetFieldsArray = NULL;
					CGetField* pGetField = NULL;
					CControlID* pControlID = NULL;
					int num = pDoc->GetCtrlN(pCtrl);
					if(num >= 0)
					{
						pGetFieldsArray = &(pDoc->m_cGetFieldsArray1);//(CGetFieldsArray*)(&(((CGetDoc77*)pDoc)->m_Array));
						if((pGetFieldsArray != NULL) && (pGetFieldsArray->GetSize() > num))
						{
							pGetField = pGetFieldsArray->GetAt(num);
							if(pGetField)
							{
								pControlID = pGetField->GetCtrlInfo();
								if(pControlID)
								{
									UINT CtrlType = pControlID->GetCtrlType();
									switch(CtrlType)
									{
									case 1://STATIC (Текст)
										{
											pWnd->Invalidate();
											break;
										}
									case 2://1CEDIT (Поле ввода)
										{
											break;
										}
									case 3://BUTTON (Кнопка)
										{
											break;
										}
									case 4://1CGROUPBOX (Рамка группы)
										{
											break;
										}
									case 5://1CEDIT (Колонка многострочной части редактируемая)
										{
											break;
										}
									case 8://SysTreeView32 (Дерево групп)
										{
											break;
										}
									case 9://STATIC (Колонка многострочной части с пикторгаммой или просто текстовая)
										{
											break;
										}
									case 10://PICTURE (Картинка)
										{
											break;
										}
									case 11://LISTBOX (Список)
										{
											break;
										}
									case 12://CHECKBOX (Флажок)
										{
											//pWnd->InvalidateRect(NULL);
											break;
										}
									case 13://RADIO (Переключатель)
										{
											break;
										}
									case 14://COMBOBOX (Поле со списком)
										{
											break;
										}
									case 15://TABLE (Таблица)
										{
											break;
										}
									default: 
										{
										}
									};
								}
							}
						}
					}
				}
			}
		}
	}

	SET_WRAP_FUNC(DX_Text)
}

int CWrapModule::WrapIsAccess(unsigned int uiID_1,long lID_2,unsigned int uiID_3)
{
	SET_ORIGIN_FUNC(IsAccess)

	CValue v1 = uiID_1; // ид типа проверяемого объекта
	CValue v2 = lID_2; // ид вида объекта, для которого проверяется право (номер таблицы в базе)
	CValue v3 = uiID_3; // вид проверяемого права
	CValue vRes = 1;
	CValue vFSO = 1;

	CValue *lArray[5] = {&v1, &v2, &v3, &vRes,  &vFSO};

	CEventsManager::GetManager().SendEventToGlobalModules(meOnTestAccess, lArray);
	//CRightsContainer

	int ret = vRes.GetNumeric();

	if((UINT)vFSO.GetNumeric() == 1L)
	{
		CRightsContainer* This = (CRightsContainer*)this;
		ret = This->IsAccess(uiID_1,lID_2,uiID_3);
	}

	SET_WRAP_FUNC(IsAccess)

	return ret;
}

void WriteTarceLog(CBLModule7* This, CString stPoint)
{
	if(CService::iTraceLevel == 1000)
	{
		CBLContext* pCont = GetContextFromModule(This);
		CValue vCont;
		vCont.AssignContext(pCont);

		int iLineNum = This->GetExecutedLineNum();
		CString stSourceLine = "";
		This->GetSourceLine(iLineNum, stSourceLine);

		CValue vSrcLineNum = iLineNum;
		CValue vProcName = This->GetFullName();
		CValue vObjectID = This->m_nID;
		CValue vObjectName = This->GetFullName();

		CValue vSource = stSourceLine;

		CValue *lArray[6] = {&vCont, &vProcName, &vSrcLineNum, &vSource, &vObjectID, &vObjectName};
		
		// предопределенные исключаем из трейсинга
		CService::iTraceLevel = 0;
		CEventsManager::GetManager().SendEventToGlobalModules(meTraceLog, lArray);
		CService::iTraceLevel = 1000;
	}
	else if(CService::iTraceLevel > 0)
	{
		CString stTraceFileName = CService::stTraceFileMask;
		if(stTraceFileName.IsEmpty())
			stTraceFileName = CService::stBase1CPath + "\\SYSLOG\\Трассировка.txt";

		int iLineNum = -1;
		if(stPoint.CompareNoCase("OnNextLine") == 0)
			iLineNum = This->GetExecutedLineNum();

		CString stFullDebug = "";
		CString stDebug = "";

		stFullDebug.Format("(%s)", stPoint);

		SYSTEMTIME st;
		::GetLocalTime(&st);
		CString stTime = "";

		stTime.Format("%02d.%02d.%04d %02d:%02d:%02d.%03d", 
			st.wDay,                      
			st.wMonth, 
			st.wYear,
			st.wHour, 
			st.wMinute, 
			st.wSecond,
			st.wMilliseconds );

		CBLModule7* pModule = This;
		CBLModule7* pModuleExec = (CBLModule7*)pModule->GetCurrentModule();
		if(pModuleExec) pModule = pModuleExec;
		stDebug.Format("[%s][%08x][%s][%d]", stTime, pModule->m_nID, pModule->GetFullName(), iLineNum);
		stFullDebug += stDebug;

		if(CService::iTraceLevel > 1)
		{
			CString stSourceLine = "";
			if(iLineNum > 0) pModule->GetSourceLine(iLineNum, stSourceLine);

			CBLProcInfo ProcInfo;
			BOOL bHasProcInfo = FALSE;
			CString stProcName = "";
			int num = 0;
			int iCallStackDepth = This->GetCallStackDepth()-1;
			if(iCallStackDepth >= 0)
			{
				if(This->GetCallLevelProcInfo(iCallStackDepth, ProcInfo, num))
				{
					stProcName = ProcInfo.GetName();
					bHasProcInfo = TRUE;
				}
			}
			stDebug.Format("[%s] %s", stProcName, stSourceLine);
			stFullDebug += stDebug;

			if(CService::iTraceLevel > 2)
			{
				if((stPoint.CompareNoCase("OnEnterProc") == 0) && bHasProcInfo)
				{
					stDebug.Format("\r\n\tАргументы:");
					stFullDebug += stDebug;
					int iNParams = ProcInfo.GetNParams();
					for(int n = 0; n < iNParams; n++)
					{
						CBLVarInfo VarInfo;
						ProcInfo.GetVarDescr(n, VarInfo);
						CValue ValRes;
						CValue *masVal[1] = {0};
						This->EvalExpr(VarInfo.GetName(),ValRes, masVal);            
						stDebug.Format("\r\n\t\t%s: %s", VarInfo.GetName(), ValRes.Format());
						stFullDebug += stDebug;
					}
					CService::nLastProc = ProcInfo.GetProcPos();
				}
				int iRetValNum = -1;
				int iSize = This->pIntInfo->pCompiledModule->ProcArray.GetSize();
				int f = ProcInfo.GetProcPos();
				if(f == -1) f = 0;
				if(f < iSize)
				{
					CCompileProcInfo* pProcInfo = This->pIntInfo->pCompiledModule->ProcArray.GetAt(f);
					if(pProcInfo)
					if(pProcInfo->Type == 2) // это функция
					{
						CString stRetValName = "";
						stRetValName.Format("00%sVal", pProcInfo->pName);
						int iVarListSize = pProcInfo->VarList.GetSize();
						for(int ff = 0; ff < iVarListSize; ff++)
						{
							CBLModuleProcVarDescr* pVarDescr = pProcInfo->VarList.GetAt(ff);
							if(pVarDescr)
							if(stRetValName.CompareNoCase(pVarDescr->Name) == 0)
							{
								iRetValNum = ff;
								break;
							}
						}
					}
				}
				if(iRetValNum >= 0)
					CService::vLastRetValue = This->pIntInfo->pExecutedModule->pValues[iRetValNum];

				if((stPoint.CompareNoCase("OnExitProc") == 0) && (CService::nLastProc >= 0))
				{
					// берем процедуру, из которой вышли
					CCompileProcInfo* pProcInfo = This->pIntInfo->pCompiledModule->ProcArray.GetAt(CService::nLastProc);
					CService::nLastProc = -1;
					DWORD dwStackLevel = This->pIntInfo->pExecutedModule->m_DWordArray1.GetSize();
					if(dwStackLevel > 0)
						CService::nLastProc = This->pIntInfo->pExecutedModule->m_DWordArray1.GetAt(dwStackLevel-1);

					if(pProcInfo)
					if(pProcInfo->Type == 2) // это функция
					{
						CValue ValRes;
						CValue *masVal[1] = {0};
						ValRes = CService::vLastRetValue;            
						stDebug.Format("\r\n\tВозвращаемое значение из %s: %s", pProcInfo->pName, ValRes.Format());
						stFullDebug += stDebug;
					}
				}
				if(!CService::stTraceVars.IsEmpty())
				{
					stDebug.Format("\r\n\tОтслеживаемые переменные:");
					stFullDebug += stDebug;

					int nTokenPos = 0;
					CString strToken = "";
					while (AfxExtractSubString(strToken,CService::stTraceVars,nTokenPos,','))
					{
						BOOL bHasValue = FALSE;
						CValue ValRes;
						CValue *masVal[1] = {0};

						int iSize = This->pIntInfo->pCompiledModule->ProcArray.GetSize();
						int f = ProcInfo.GetProcPos();
						if(f == -1) f = 0;
						if(f < iSize)
						{
							CCompileProcInfo* pProcInfo = This->pIntInfo->pCompiledModule->ProcArray.GetAt(f);
							int iVarListSize = pProcInfo->VarList.GetSize();
							for(int ff = 0; ff < iVarListSize; ff++)
							{
								CBLModuleProcVarDescr* pVarDescr = pProcInfo->VarList.GetAt(ff);
								if(strToken.CompareNoCase(pVarDescr->Name) == 0)
								{
									bHasValue = TRUE;
									break;
								}
								//Msg("%s",pVarDescr->Name);
							}
						}
						if(bHasValue)
						{
							This->EvalExpr(strToken,ValRes, masVal);            
						}
						else if(This->FindStaticVar(strToken) >= 0)
						{
							This->EvalExpr(strToken,ValRes, masVal);            
							bHasValue = TRUE;
						}
						else
						{
							// ищем в глобальном модуле
							int iNStaticVar = pGlobalModuleFormEx->FindStaticVar(strToken);
							if(iNStaticVar >= 0)
							{
								pGlobalModuleFormEx->GetStaticVarValue(iNStaticVar, ValRes, FALSE);
								bHasValue = TRUE;
								strToken += "(глобальная)";
								CBLVarInfo VarInfo;
								pGlobalModuleFormEx->GetStaticVarDescr(iNStaticVar, VarInfo);
								if(!VarInfo.IsExported())
								strToken += "(не экспортная)";
							}
						}
						if(bHasValue)
						{
							CBLContext* pCont = GetContextFromModule(This);
							CValue vCont;
							vCont.AssignContext(pCont);

							CValue vVarName = strToken;
							CValue vVarValue = ValRes;
							CValue vVarPresent = ValRes.Format();

							CValue *lArray[4] = {&vCont, &vVarName, &vVarValue, &vVarPresent};
							
							// предопределенные исключаем из трейсинга

							int iOldTraceLevel = CService::iTraceLevel;
							CService::iTraceLevel = 0;
							CEventsManager::GetManager().SendEventToGlobalModules(meOnValueTraceLogPresent, lArray);
							CService::iTraceLevel = iOldTraceLevel;

							stDebug.Format("\r\n\t\t%s: %s", strToken, vVarPresent.Format());
						}
						else
							stDebug.Format("\r\n\t\t%s - недоступна", strToken);
						stFullDebug += stDebug;
						nTokenPos++;
					}
				}
			}
		}

		CLogFile fileDebug;
		fileDebug.Open(stTraceFileName);
		fileDebug << stFullDebug << CRLF;
		fileDebug.Close();

	}
}

int CWrapModule::WrapOnNextLine(void)
{
	SET_ORIGIN_FUNC(OnNextLine)

	CBLModule7* This = (CBLModule7*)this;

	WriteTarceLog(This, "OnNextLine");

	conv.pV = adrOnNextLine;
	int ret = (This->*(conv.pOnNextLine))();

	SET_WRAP_FUNC(OnNextLine)

	return ret;
}

int CWrapModule::WrapOnStartExecution(void)
{
	SET_ORIGIN_FUNC(OnStartExecution)

	CBLModule7* This = (CBLModule7*)this;

	//WriteTarceLog(This, "OnStartExecution");

	conv.pV = adrOnStartExecution;
	int ret = (This->*(conv.pOnStartExecution))();

	SET_WRAP_FUNC(OnStartExecution)

	return ret;
}

void CWrapModule::WrapOnStopExecution(void)
{
	SET_ORIGIN_FUNC(OnStopExecution)

	CBLModule7* This = (CBLModule7*)this;

	//WriteTarceLog(This, "OnStopExecution");

	conv.pV = adrOnStopExecution;
	int ret = (This->*(conv.pOnStopExecution))();

	SET_WRAP_FUNC(OnStopExecution)
}

void CWrapModule::WrapOnEnterProc(int iProc)
{
	SET_ORIGIN_FUNC(OnEnterProc)

	CBLModule7* This = (CBLModule7*)this;

	WriteTarceLog(This, "OnEnterProc");

	conv.pV = adrOnEnterProc;
	(This->*(conv.pOnEnterProc))(iProc);

	SET_WRAP_FUNC(OnEnterProc)
}

void CWrapModule::WrapOnExitProc(int iProc)
{
	SET_ORIGIN_FUNC(OnExitProc)

	CBLModule7* This = (CBLModule7*)this;

	WriteTarceLog(This, "OnExitProc");

	conv.pV = adrOnExitProc;
	(This->*(conv.pOnExitProc))(iProc);

	SET_WRAP_FUNC(OnExitProc)
}


BOOL CWrapModule::OnShowControlBar(class CControlBar *pControlBar, int bVisible)
{
	BOOL bDoShow = TRUE;

	if(pControlBar->IsKindOf(RUNTIME_CLASS(CDockableWindow)))
	{
		CDockableWindow* pDockableWindow = (CDockableWindow*)pControlBar;
		int idMessageHandler = -1;
		if(pDockableWindow->m_pMMHandler == pMainMessageHandler)
			idMessageHandler = 0;
		else
			idMessageHandler = (DWORD)pDockableWindow->m_pMMHandler;
		CValue vID = idMessageHandler;
		CValue vVisible = bVisible;
		CValue vFSO = 1;
		CValue *lArray[3] = {&vID, &vVisible, &vFSO};
		
		CEventsManager::GetManager().SendEventToGlobalModules(meOnShowControlBar, lArray);

		if(0L == (UINT)vFSO.GetNumeric()) bDoShow = FALSE;
	}

	return bDoShow;
}

void CWrapModule::WrapShowControlBar(class CControlBar *pControlBar, int bVisible, int bInitPos)
{
	SET_ORIGIN_FUNC(ShowControlBar)

	if(OnShowControlBar(pControlBar, bVisible))
	{
		SECMDIFrameWnd* This = (SECMDIFrameWnd*)this;
		This->ShowControlBar(pControlBar, bVisible, bInitPos);
	}

	SET_WRAP_FUNC(ShowControlBar)

	return;
}

void CWrapModule::WrapOnHide(void)
{
	SET_ORIGIN_FUNC(OnHide)

	SECControlBar* This = (SECControlBar*)this;

	if(OnShowControlBar(This, 0))
		This->OnHide();

	SET_WRAP_FUNC(OnHide)

	return;
}

/*
class CDocument * CWrapModule::WrapTemplate7OpenDocumentFileEx(char const * pCaption,long lParam,int iParam)
{
	SET_ORIGIN_FUNC(Template7OpenDocumentFileEx)

	CTemplate7* This = (CTemplate7*)this;
	CDocument *pDocument = This->OpenDocumentFileEx(pCaption, lParam, iParam);

	//buf.Format("pDocument = %x", pDocument);
	//pBkEndUI->DoMessageLine(buf);

	SET_WRAP_FUNC(Template7OpenDocumentFileEx)

	return pDocument;
}
*/


class CGetDoc7 * WrapActivateDocForm(
		long lRealTypeID,
		class CObjID ObjIDToOpen,
		long lMetaDataID_CurrentJournal,
		unsigned int uiParam2,
		class CObjID ObjIDToCopy,
		long lRealTypeID_Current,
		int iIsInputCausedBy,
		long lRealTypeID_CausedBy,
		int iOpenMode,
		int iParam7,
		int iParam8,
		int iParam9,
		class CValue * pValue1,
		class CValue * pValue2)
{
	SET_ORIGIN_FUNC(ActivateDocForm)

	CValue v1 = lRealTypeID; //идВидаОткрываемогоДокумента
	CValue v2 = ObjIDToOpen.ObjID; //идОткрываемогоОбъекта
	CValue v3 = lMetaDataID_CurrentJournal;
	CValue v4 = uiParam2;
	CValue v5 = ObjIDToCopy.ObjID; //идКопируемогоОбъекта
	CValue v6 = lRealTypeID_Current; //идВидаТекущегоВЖурнале
	CValue v7 = iIsInputCausedBy; // флаг ввода на основании
	CValue v8 = lRealTypeID_CausedBy; // идВидаДокуменатОснования
	CValue v9 = iOpenMode; // флРежимПросмотра
	CValue v10 = iParam7;
	CValue v11 = iParam8;
	CValue v12 = iParam9;
	CValue v13;
	CValue v14; // ПараметрФормы

	CValue vFSO = 1;

	if(pValue1) v13 = *pValue1;
	if(pValue2) v14 = *pValue2;

	//,class CValue * pValue1,class CValue * pValue2;
	CValue *lArray[15] = {&vFSO, &v1, &v2, &v3, &v4, &v5, &v6, &v7, &v8, &v9, &v10, &v11, &v12, &v13, &v14};

	CEventsManager::GetManager().SendEventToGlobalModules(meOnActivateDocForm, lArray);

	class CGetDoc7 *ret = NULL;

	if(long(vFSO.GetNumeric()) != 0L)
	{
		lRealTypeID = v1.GetNumeric();
		//ObjIDToOpen.ObjID = v2;
		//lMetaDataID_CurrentJournal = v3.GetNumeric();
		//uiParam2 = v4.GetNumeric();
		//ObjIDToCopy.ObjID = v5;
		//lRealTypeID_Current = v6.GetNumeric();
		//iIsInputCausedBy = v7.GetNumeric();
		//lRealTypeID_CausedBy = v8.GetNumeric();
		iOpenMode = v9.GetNumeric();
		//iParam7 = v10.GetNumeric();
		//iParam8 = v11.GetNumeric();
		//iParam9 = v12.GetNumeric();

		ret = ActivateDocForm(
					lRealTypeID,
					ObjIDToOpen,
					lMetaDataID_CurrentJournal,
					uiParam2,
					ObjIDToCopy,
					lRealTypeID_Current,
					iIsInputCausedBy,
					lRealTypeID_CausedBy,
					iOpenMode,
					iParam7,
					iParam8,
					iParam9,
					pValue1,
					pValue2);
	}

	SET_WRAP_FUNC(ActivateDocForm)

	return ret;
}


void CWrapModule::CheckListBoxDrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	((CFormExCheckListBox*)this)->MyDrawItem(lpDrawItemStruct);
}

BOOL CWrapModule::CheckListBoxOnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	return ((CFormExCheckListBox*)this)->MyOnChildNotify(message, wParam, lParam, pResult);
}

void CFormExCheckListBox::MyDrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	ASSERT((GetStyle() & (LBS_OWNERDRAWFIXED | LBS_HASSTRINGS)) ==
		(LBS_OWNERDRAWFIXED | LBS_HASSTRINGS));

	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	if (((LONG)(lpDrawItemStruct->itemID) >= 0) &&
		(lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)))
	{
		int cyItem = GetItemHeight(lpDrawItemStruct->itemID);

		if (m_cyText == 0)
			VERIFY(cyItem >= CalcMinimumItemHeight());

		CString strText;
		GetText(lpDrawItemStruct->itemID, strText);

		COLORREF newTextColor = GetSysColor(COLOR_WINDOWTEXT);
		COLORREF newBkColor = GetSysColor(COLOR_WINDOW);

		COLORREF oldTextColor = pDC->SetTextColor(newTextColor);
		COLORREF oldBkColor = pDC->SetBkColor(newBkColor);

		COLORREF crBkColor = ::GetSysColor(COLOR_WINDOW);
		COLORREF crBkColorSel = ::GetSysColor(COLOR_ACTIVECAPTION);
		COLORREF crTextColor = ::GetSysColor(COLOR_WINDOWTEXT);
		COLORREF crTextColorSel = RGB(0xFF,0xFF,0xFF);
		DWORD fontSetS = 0;
		DWORD fontSet = 0;

		CString st_buf = strText;
		st_buf.MakeUpper();
		char ** endptr = NULL;
		const char * ptr = NULL;
					
		int iBuf = st_buf.Find("FONTSET_S[",0);
		if(iBuf >= 0)
		{
			iBuf += 10;
			if(st_buf.Mid(iBuf, 4) != "NONE")
				fontSetS = (DWORD)atol(st_buf.Mid(iBuf));
		}
		iBuf = st_buf.Find("FONTSET[",0);
		if(iBuf >= 0)
		{
			iBuf += 8;
			if(st_buf.Mid(iBuf, 4) != "NONE")
				fontSet = (DWORD)atol(st_buf.Mid(iBuf));
		}
		iBuf = st_buf.Find("FONT_S[",0);
		if(iBuf >= 0)
		{
			iBuf  += 7;
			if(st_buf.Mid(iBuf , 4) != "NONE")
			{
				ptr = st_buf.Mid(iBuf);
				endptr = (char**)&ptr;
				crTextColorSel = strtol(ptr,endptr,0);
			}
		}
		iBuf = st_buf.Find("FONT[",0);
		if(iBuf >= 0)
		{
			iBuf += 5;
			if(st_buf.Mid(iBuf, 4) != "NONE")
			{
				ptr = st_buf.Mid(iBuf);
				endptr = (char**)&ptr;
				crTextColor = strtol(ptr,endptr,0);
			}
		}
		iBuf = st_buf.Find("BRUSH_S[",0);
		if(iBuf >= 0)
		{
			iBuf += 8;
			if(st_buf.Mid(iBuf, 4) != "NONE")
			{
				ptr = st_buf.Mid(iBuf);
				endptr = (char**)&ptr;
				crBkColorSel = strtol(ptr,endptr,0);
			}
		}
		iBuf = st_buf.Find("BRUSH[",0);
		if(iBuf >= 0)
		{
			iBuf += 6;
			if(st_buf.Mid(iBuf, 4) != "NONE")
			{
				ptr = st_buf.Mid(iBuf);
				endptr = (char**)&ptr;
				crBkColor = strtol(ptr,endptr,0);
			}
		}

		CImageList cImageList;
		cImageList.Create(13, 16, ILC_COLOR32|ILC_MASK, 2, 0);

		iBuf = st_buf.Find("IMAGE[",0);
		if(iBuf >= 0)
		{
			iBuf += 6;
			int iBufEnd = st_buf.Find("]",iBuf);
			if(iBufEnd > iBuf)
			{
				CString strAlias = strText.Mid(iBuf, iBufEnd - iBuf);
				CGalleryHolder * pGalleryHolder = CGalleryHolder::GetGallery();
				if(pGalleryHolder)
				{
					ULONG picID = pGalleryHolder->FindByAlias(strAlias);
					if(picID)
					{
// 						CPictureHolder7 * pic;
// 						pic = new CPictureHolder7(pGalleryHolder->GetPicture(picID));
						// был баг - объект не удалялся !
						sh_ptr<CPictureHolder7> pPictureHolder7 = sh_ptr<CPictureHolder7>(new CPictureHolder7(pGalleryHolder->GetPicture(picID)));

						CBitmap bitmap;
						BOOL bResult = FALSE;
						CDC dcMem;

						if (dcMem.CreateCompatibleDC(pDC))
						{
							CSize hmSize = pPictureHolder7->GetSize();

							CBitmap bmMem;

							if (bmMem.CreateCompatibleBitmap(pDC, hmSize.cx, 16))
							{
								CBitmap* pOldBM = dcMem.SelectObject(&bmMem);

								dcMem.FillSolidRect(0, 0, hmSize.cx, 16, RGB(0x00,0x80,0x80));
								RECT rect1;
								RECT rect2;
								rect1.top = rect1.left = 0;
								rect1.right = hmSize.cx;
								if(hmSize.cy<16) rect1.bottom = hmSize.cy;
								else rect1.bottom = 16;
								
								pPictureHolder7->Render(dcMem, rect1, 0, &rect2);

								bResult = bitmap.Attach(bmMem.Detach());

								dcMem.SelectObject(pOldBM);
							}
						}

						if(bResult)
						{
							cImageList.Add(&bitmap, RGB(0x00,0x80,0x80));
						}
					}
				}
			}
		}

		if(cImageList.GetImageCount() == 0)
		{
			HBITMAP hBitmap;
			hBitmap = ::LoadBitmap(hDllInstance,MAKEINTRESOURCE(IDB_CHECKS));
			cImageList.Add(CBitmap::FromHandle(hBitmap), RGB(0x00,0x80,0x80));
			::DeleteObject(hBitmap);
		}

		CFont* pOldFont = pDC->SelectObject(GetFont());

		CRect itemRect = lpDrawItemStruct->rcItem;

		if((lpDrawItemStruct->itemState & ODS_SELECTED))
		{
			pDC->FillSolidRect(itemRect, crBkColorSel);
			pDC->SetTextColor(crTextColorSel);
			if(fontSetS)
				pDC->SelectObject(CFont::FromHandle((HFONT)fontSetS));
			else if(fontSet)
				pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
		}
		else
		{
			pDC->FillSolidRect(itemRect, crBkColor);
			pDC->SetTextColor(crTextColor);
			if(fontSet)
				pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
		}

		int nCheck = GetCheck(lpDrawItemStruct->itemID);

		CRect rectCheck = lpDrawItemStruct->rcItem;
		rectCheck.left += 0;
		rectCheck.top += 1 + max(0, (cyItem - 16) / 2);

		cImageList.Draw(pDC, nCheck, rectCheck.TopLeft(), ILD_NORMAL);

		int n = strText.Find("\r");
		if(n>=0) strText = strText.Left(n);

		CRect textRect = itemRect;
		//textRect.DeflateRect(2,0);
		int h = textRect.Height();
		textRect.top = lpDrawItemStruct->rcItem.top + max(0, (cyItem - m_cyText) / 2);
		textRect.bottom = textRect.top + h;
		textRect.left += 13;

		pDC->DrawText(strText, textRect, DT_VCENTER | DT_SINGLELINE | DT_EXPANDTABS);

		pDC->SetTextColor(oldTextColor);
		pDC->SetBkColor(oldBkColor);
		pDC->SelectObject(pOldFont);
	}

	if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0)
	{
		CRect focusRect = lpDrawItemStruct->rcItem;
		focusRect.left += 12;
		pDC->DrawFocusRect(&(focusRect));
	}
}

BOOL CFormExCheckListBox::MyOnChildNotify(UINT message, WPARAM wParam, LPARAM lParam,
	LRESULT* pResult)
{
	switch (message)
	{
	case WM_DRAWITEM:
		ASSERT(pResult == NULL);       // no return value expected
		//PreDrawItem((LPDRAWITEMSTRUCT)lParam);
		MyDrawItem((LPDRAWITEMSTRUCT)lParam);
		break;
	case WM_MEASUREITEM:
		ASSERT(pResult == NULL);       // no return value expected
		PreMeasureItem((LPMEASUREITEMSTRUCT)lParam);
		break;
	case WM_COMPAREITEM:
		ASSERT(pResult != NULL);       // return value expected
		*pResult = PreCompareItem((LPCOMPAREITEMSTRUCT)lParam);
		break;
	case WM_DELETEITEM:
		ASSERT(pResult == NULL);       // no return value expected
		PreDeleteItem((LPDELETEITEMSTRUCT)lParam);
		break;
	default:
		return CListBox::OnChildNotify(message, wParam, lParam, pResult);
	}
	return TRUE;
}

static DWORD dwOrigCheckListBoxDrawItem = 0;
static DWORD dwOrigCheckListBoxOnChildNotify = 0;
static DWORD dwOrigDrawStaticGetMessageMap = 0;
static DWORD pMsgOrigDrawTransCtrl = 0;

void CWrapModule::SetWrapCheckListBoxDrawItem(BOOL bOnOff)
{
	HINSTANCE hSev=GetModuleHandle("seven.dll");
	BYTE* adr1;
	DWORD old;

	if(bOnOff)
	{
		adr1=(BYTE*)GetProcAddress(hSev,"??_7CCheckListBox7@@6B@");
		VirtualProtect(adr1,0xC0,PAGE_EXECUTE_READWRITE,&old);

		PF_CLBDI jmp1 = (PF_CLBDI)CheckListBoxDrawItem;
		DWORD dw = (DWORD)&jmp1;

		dwOrigCheckListBoxDrawItem = ((DWORD*)adr1)[0x30];
		((DWORD*)adr1)[0x30] = *((DWORD*)dw);

		PF_CLBOCN jmp2 = (PF_CLBOCN)CheckListBoxOnChildNotify;
		dw = (DWORD)&jmp2;

		dwOrigCheckListBoxOnChildNotify = ((DWORD*)adr1)[0x2C];
		((DWORD*)adr1)[0x2C] = *((DWORD*)dw);

		//?_GetBaseMessageMap@CDrawStatic@@KGPBUAFX_MSGMAP@@XZ
		//?messageMap@CDrawStatic@@1UAFX_MSGMAP@@B
		adr1=(BYTE*)GetProcAddress(hSev,"?messageMap@CDrawStatic@@1UAFX_MSGMAP@@B");
		VirtualProtect(adr1,4,PAGE_EXECUTE_READWRITE,&old);
		dwOrigDrawStaticGetMessageMap = *(DWORD*)adr1;
		*(DWORD*)adr1 = (DWORD)&CDrawStaticWrap::pubGetMessageMap;

		//?_GetBaseMessageMap@CDrawTrasparentCtrl@@KGPBUAFX_MSGMAP@@XZ
		//?messageMap@CDrawTrasparentCtrl@@1UAFX_MSGMAP@@B
		adr1=(BYTE*)GetProcAddress(hSev,"?messageMap@CDrawTrasparentCtrl@@1UAFX_MSGMAP@@B");
		VirtualProtect(adr1,0x40,PAGE_EXECUTE_READWRITE,&old);

		pMsgOrigDrawTransCtrl = *(DWORD*)adr1;
		*(DWORD*)adr1 = (DWORD)&CDrawTrasparentCtrlWrap::pubGetMessageMap;
		AFX_MSGMAP* pMsg = (AFX_MSGMAP*)adr1;
		AFX_MSGMAP_ENTRY* pEntr = (AFX_MSGMAP_ENTRY*)pMsg->lpEntries;
		AFX_MSGMAP* pMsg2 = (AFX_MSGMAP*)CDrawTrasparentCtrlWrap::pubGetMessageMap();
		AFX_MSGMAP_ENTRY* pEntr2 = (AFX_MSGMAP_ENTRY*)pMsg2->lpEntries;
		VirtualProtect(pEntr2,0x40,PAGE_EXECUTE_READWRITE,&old);
		origOnEnable = pEntr[1].pfn;
		pEntr[1].pfn = pEntr2[1].pfn;
		pEntr2[1].pfn = origOnEnable;
		//*(DWORD*)adr1 = (DWORD)&CDrawTrasparentCtrlWrap::pubGetMessageMap;
	}
	else
	{
		adr1=(BYTE*)GetProcAddress(hSev,"??_7CCheckListBox7@@6B@");
		VirtualProtect(adr1,0xC0,PAGE_EXECUTE_READWRITE,&old);

		((DWORD*)adr1)[0x30] = dwOrigCheckListBoxDrawItem;
		((DWORD*)adr1)[0x2C] = dwOrigCheckListBoxOnChildNotify;

		adr1=(BYTE*)GetProcAddress(hSev,"?messageMap@CDrawStatic@@1UAFX_MSGMAP@@B");
		VirtualProtect(adr1,4,PAGE_EXECUTE_READWRITE,&old);

		*(DWORD*)adr1 = dwOrigDrawStaticGetMessageMap;

		adr1=(BYTE*)GetProcAddress(hSev,"?messageMap@CDrawTrasparentCtrl@@1UAFX_MSGMAP@@B");
		VirtualProtect(adr1,0x40,PAGE_EXECUTE_READWRITE,&old);

		AFX_MSGMAP* pMsg = (AFX_MSGMAP*)adr1;
		AFX_MSGMAP_ENTRY* pEntr = (AFX_MSGMAP_ENTRY*)pMsg->lpEntries;
		AFX_MSGMAP* pMsg2 = (AFX_MSGMAP*)CDrawTrasparentCtrlWrap::pubGetMessageMap();
		AFX_MSGMAP_ENTRY* pEntr2 = (AFX_MSGMAP_ENTRY*)pMsg2->lpEntries;
		VirtualProtect(pEntr2,0x40,PAGE_EXECUTE_READWRITE,&old);
		AFX_PMSG wrapOnEnable = pEntr[1].pfn;
		pEntr[1].pfn = pEntr2[1].pfn;
		pEntr2[1].pfn = origOnEnable;

		*(DWORD*)adr1 = pMsgOrigDrawTransCtrl;
	}
};

void CWrapModule::WrapPaintText(class CSheetGDI &SheetGDI,class CDC *pDC,char const *Str,class CSheetFormat const &Format,struct tagRECT const *lprcSrc,int Flag,struct tagRECT const *lprcTag)
{
	SET_ORIGIN_FUNC(PaintText)

	CSheetView* This = (CSheetView*)this;

	// lprcSrc - область ячейки
	// lprcTag - область, в которую нужно вписать текст

	/*
	CString csBuf = Str;

	if(!SheetGDI.m_bIsPrinterGDI) csBuf = "("+ csBuf + ")";

	This->PaintText(SheetGDI, pDC, csBuf, Format, lprcSrc, Flag, lprcTag);
	*/
	/*
	CString csDebug = "";

	csDebug.Format("%s :: (%i,%i)-(%i,%i) :: (%i,%i)-(%i,%i) :: %i :: %i :: %i",
		Str, lprcSrc->left, lprcSrc->top, lprcSrc->right, lprcSrc->bottom,
		lprcTag->left, lprcTag->top, lprcTag->right, lprcTag->bottom,
		Format.GetFontSize(), Format.GetWrapText(), Format.HasProperties());
	pBkEndUI->DoMessageLine(csDebug);

	CSheetFormat newFormat(Format);
	newFormat.RemoveAllProperties();
	*/

	This->PaintText(SheetGDI, pDC, Str, Format, lprcSrc, Flag, lprcTag);

	/*
	csDebug.Format("%s :: (%i,%i)-(%i,%i) :: (%i,%i)-(%i,%i) :: %i :: %i :: %i",
		Str, lprcSrc->left, lprcSrc->top, lprcSrc->right, lprcSrc->bottom,
		lprcTag->left, lprcTag->top, lprcTag->right, lprcTag->bottom,
		newFormat.GetFontSize(), newFormat.GetWrapText(), newFormat.HasProperties());
	pBkEndUI->DoMessageLine(csDebug);
	*/

	SET_WRAP_FUNC(PaintText)
}

void CWrapModule::RestoreAll()
{
	//SET_ORIGIN_FUNC(SetPaneText)
	//SET_ORIGIN_FUNC(UpdateAllPanes)
	SET_ORIGIN_FUNC(AssignContext)

	SET_ORIGIN_FUNC(OnNextLine)
	SET_ORIGIN_FUNC(OnEnterProc)
	SET_ORIGIN_FUNC(OnExitProc)
	SET_ORIGIN_FUNC(OnStartExecution)
	SET_ORIGIN_FUNC(OnStopExecution)
	SET_ORIGIN_FUNC(IsAccess)
	SET_ORIGIN_FUNC(PaintText)
	SET_ORIGIN_FUNC(OnLButtonDblClk)
	SET_ORIGIN_FUNC(SetIndicators)
	SET_ORIGIN_FUNC(OnMDIActivate)
	SET_ORIGIN_FUNC(PPOnInitDialog)

	SET_ORIGIN_FUNC(ActivateDocForm)
	SET_ORIGIN_FUNC(DX_Text)
	SET_ORIGIN_FUNC(GetHiTrackBound)
	SET_ORIGIN_FUNC(GetLoTrackBound)
	SET_ORIGIN_FUNC(center)
	/*
	SET_ORIGIN_FUNC(refresh)
	SET_ORIGIN_FUNC(top)
	SET_ORIGIN_FUNC(RefreshAll)
	SET_ORIGIN_FUNC(NewRow)
	*/
	SET_ORIGIN_FUNC(UpdateData)
	SET_ORIGIN_FUNC(CreateControl)
	SET_ORIGIN_FUNC(ProcessSecondOpen)
	SET_ORIGIN_FUNC(OnInitialUpdate)
	SET_ORIGIN_FUNC(OnInitDialog)
	SET_ORIGIN_FUNC(LayoutForm)
	SET_ORIGIN_FUNC(OnCloseDocument)
	SET_ORIGIN_FUNC(LoadForm)
	SET_ORIGIN_FUNC(LoadDialog)
	SET_ORIGIN_FUNC(OpenDocumentFileEx)
	SET_ORIGIN_FUNC(DoLoadExternal)
	SET_ORIGIN_FUNC(DoLoadLayout)
	SET_ORIGIN_FUNC(GetData)
	SET_ORIGIN_FUNC(OnPrint)
	SET_ORIGIN_FUNC(OnPreparePrinting)
	
	SET_ORIGIN_FUNC(ReadHistory)
	SET_ORIGIN_FUNC(WriteHistory)
	SET_ORIGIN_FUNC(SheetDocSaveAs)

	
	CLockHandler::Destroy();

//	SET_ORIGIN_FUNC(AssignSource)
	SET_ORIGIN_FUNC(UnloadAddIns)

	SET_ORIGIN_FUNC(CreateFromFile)
	SET_ORIGIN_FUNC(WriteMessage)
	SET_ORIGIN_FUNC(ShowControlBar)
	SET_ORIGIN_FUNC(OnHide)
	SET_ORIGIN_FUNC(WriteStatusLine)
	SET_ORIGIN_FUNC(WriteStatusLineUINT)

	SET_ORIGIN_FUNC(CGetDoc7_Constructor)
};

CWrapModule::CWrapModule()
{

	pGlobalModuleFormEx = (CBLModule7*)GetGlobalModule();

	DWORD old;
	HINSTANCE hBr32	= GetModuleHandle("br32.dll");
	HINSTANCE hBl	= GetModuleHandle("blang.dll");
	HINSTANCE hBas	= GetModuleHandle("basic.dll");
	HINSTANCE hFrame= GetModuleHandle("frame.dll");
	HINSTANCE hSev	= GetModuleHandle("seven.dll");
	HINSTANCE hBk	= GetModuleHandle("bkend.dll");
	HINSTANCE hEd	= GetModuleHandle("editr.dll");
	HINSTANCE hMox	= GetModuleHandle("moxel.dll");
	HINSTANCE hTxtedt = GetModuleHandle("txtedt.dll");

//?CtlColor@CDrawTrasparentCtrl@@IAEPAUHBRUSH__@@PAVCDC@@I@Z
	adrCtlColorTrans = (BYTE*)GetProcAddress(hSev,"?CtlColor@CDrawTrasparentCtrl@@IAEPAUHBRUSH__@@PAVCDC@@I@Z");
	VirtualProtect(adrCtlColorTrans,6,PAGE_EXECUTE_READWRITE,&old);

//?CtlColor@CDrawStatic@@IAEPAUHBRUSH__@@PAVCDC@@I@Z
	adrCtlColor = (BYTE*)GetProcAddress(hSev,"?CtlColor@CDrawStatic@@IAEPAUHBRUSH__@@PAVCDC@@I@Z");
	VirtualProtect(adrCtlColor,6,PAGE_EXECUTE_READWRITE,&old);

	INSTALL_WRAP(hFrame, "?SetIndicators@SECStatusBar@@QAEHPBIH@Z", SetIndicators, PF_SI)
	//INSTALL_WRAP(hFrame, "?UpdateAllPanes@SECStatusBar@@IAEXHH@Z", UpdateAllPanes, PF_UAP)
	//INSTALL_WRAP(hFrame, "?SetPaneText@SECStatusBar@@QAEHHPBDH@Z", SetPaneText, PF_SPT)
	INSTALL_WRAP(hFrame, "?OnMDIActivate@CChildFrame7@@IAEXHPAVCWnd@@0@Z", OnMDIActivate, PF_ONMDIA)

	INSTALL_WRAP(hFrame, "?OnInitDialog@COlePropertyPageSite@@MAEHXZ", PPOnInitDialog, PF_PPONINITDLG)
	INSTALL_WRAP(hFrame, "?CreateFromFile@CPictureHolder7@@QAEHPBD@Z", CreateFromFile, PF_CreateFromFile)
	
	INSTALL_WRAP(hFrame, "?OnLButtonDblClk@SECControlBar@@IAEXIVCPoint@@@Z", OnLButtonDblClk, PF_OLBDC)

	INSTALL_WRAP(hFrame, "?ShowControlBar@SECMDIFrameWnd@@QAEXPAVCControlBar@@HH@Z", ShowControlBar, PF_SHOWCONTROLBAR)
	INSTALL_WRAP(hFrame, "?OnHide@SECControlBar@@IAEXXZ", OnHide, PF_ONHIDE)

	//INSTALL_WRAP(hFrame, "?OpenDocumentFileEx@CTemplate7@@QAEPAVCDocument@@PBDJH@Z", Template7OpenDocumentFileEx, PF_Template7OpenDocumentFileEx)

	INSTALL_WRAP(hBk, "?DX_Text@@YAXPAVCGetExchange@@HAAVCValue@@@Z", DX_Text, PF_DX_T)
	
//	INSTALL_WRAP(hBl, "?AssignSource@CBLModule@@QAEXPBD@Z", AssignSource, PF_ASSIGNSOURCE)

	INSTALL_WRAP(hBr32, "?GetHiTrackBound@CBrowse@@IAEHH@Z", GetHiTrackBound, PF_GHTB)
	INSTALL_WRAP(hBr32, "?GetLoTrackBound@CBrowse@@IAEHH@Z", GetLoTrackBound, PF_GLTB)
	INSTALL_WRAP(hBr32, "?center@CBrowse@@QAEXXZ", center, PF_CENTER)

	/*
	INSTALL_WRAP(hBr32, "?refresh@CBrowse@@IAEXXZ", refresh, PF_REFRESH)
	INSTALL_WRAP(hBr32, "?top@CBrowse@@QAEXXZ", top, PF_TOP)
	INSTALL_WRAP(hBr32, "?RefreshAll@CBrowse@@QAEXXZ", RefreshAll, PF_REFRESHALL)
	INSTALL_WRAP(hBk, "?NewRow@CValueTable@@UAEHH@Z", NewRow, PF_NEWROW)
	*/
	//INSTALL_WRAP(hBr32, "?UpdateData@CGetDoc@@UAEHHI@Z", UpdateData, PF_ONUPDATA)

	INSTALL_WRAP(hBas, "?UpdateData@CGetDoc7@@UAEHHI@Z", UpdateData, PF_ONUPDATA)
	INSTALL_WRAP(hBas, "?CreateControl@CGetDoc7@@QAEPAVCWnd@@PAVCGetField@@IABVCRect@@PAV2@KK@Z", CreateControl, PF_GDCC)
	INSTALL_WRAP(hBas, "?ProcessSecondOpen@CGetDoc7@@QAEXPAVCValue@@@Z", ProcessSecondOpen, PF_PSO)
	INSTALL_WRAP(hBas, "?OnInitialUpdate@CBrowseView7@@MAEXXZ", OnInitialUpdate, PF_ONINITUP)
	INSTALL_WRAP(hBas, "?OnInitDialog@CGetDlg@@MAEHXZ", OnInitDialog, PF_ONINITDLG)
	INSTALL_WRAP(hBas, "?LayoutForm@CGetDoc7@@UAEHPAVCFormView@@@Z", LayoutForm, PF_LayF)
	INSTALL_WRAP(hBas, "?OnCloseDocument@CGetDoc7@@UAEXXZ", OnCloseDocument, PF_ONCD)
	INSTALL_WRAP(hBas, "?LoadForm@CGetDoc7@@IAEHJPBD@Z", LoadForm, PF_LOADFORM)
	INSTALL_WRAP(hBas, "?LoadDialog@CGetDoc7@@IAEHJPBD@Z", LoadDialog, PF_LOADDIALOG)
	INSTALL_WRAP(hBas, "?OpenDocumentFileEx@CGetDlg@@SAXIPBDJPAVCValue@@IIII@Z", OpenDocumentFileEx, void*)
	INSTALL_WRAP(hEd, "?DoLoadExternal@CEditDoc@@IAEHPBD@Z", DoLoadExternal, PF_DOLOADEX)
	INSTALL_WRAP(hEd, "?DoLoadLayout@CEditDoc@@IAEHPBD@Z", DoLoadLayout, PF_DOLOADLAYOUT)
	INSTALL_WRAP(hSev, "?GetData@CImageCol@@UAEXAAVCString@@@Z", GetData, PF_GETDATAIMAGECOL)
	INSTALL_WRAP(hMox, "?OnPrint@CSheetView@@MAEXPAVCDC@@PAUCPrintInfo@@@Z", OnPrint, PF_ONPRINT)
	INSTALL_WRAP(hMox, "?OnPreparePrinting@CSheetView@@MAEHPAUCPrintInfo@@@Z", OnPreparePrinting, PF_ONPREPAREPRINTING)
	INSTALL_WRAP(hMox, "?PaintText@CSheetView@@IAEXAAVCSheetGDI@@PAVCDC@@PBDABVCSheetFormat@@PBUtagRECT@@H4@Z", PaintText, PF_PT)
	INSTALL_WRAP(hMox, "?SaveAs@CSheetDoc@@QAEHPBDW4CSheetSaveAsType@@@Z", SheetDocSaveAs, PF_SHEETDOCSAVEAS)
	//INSTALL_WRAP(hMox, "?DoSave@CSheetDoc@@MAEHPBDH@Z", SheetDocDoSave, PF_SHEETDOCDOSAVE)

	INSTALL_WRAP(hBas, "?Read@CRepHistory@@QAEHXZ", ReadHistory, PF_READHISTORY)
	INSTALL_WRAP(hBas, "?Write@CRepHistory@@QAEHXZ", WriteHistory, PF_WRITEHISTORY)

	INSTALL_WRAP(hBas, "?ActivateDocForm@@YAPAVCGetDoc7@@JVCObjID@@JI0JHJHHHHPAVCValue@@1@Z", ActivateDocForm, PF_ActivateDocForm)
	
	INSTALL_WRAP(hTxtedt, "?WriteMessage@CMainMessageHandler@@IAEXPBDAAVCMessageInfo@@H@Z", WriteMessage, PF_WriteMessage)

	INSTALL_WRAP(hSev, "?OnNextLine@CBLModule7@@UAEHXZ", OnNextLine, PF_ONNEXTLINE)
	INSTALL_WRAP(hSev, "?OnStartExecution@CBLModule7@@UAEHXZ", OnStartExecution, PF_ONSTARTEXECUTION)
	INSTALL_WRAP(hSev, "?OnStopExecution@CBLModule7@@UAEXXZ", OnStopExecution, PF_ONSTOPEXECUTION)
	INSTALL_WRAP(hSev, "?OnEnterProc@CBLModule7@@UAEXH@Z", OnEnterProc, PF_ONENTERPROC)
	INSTALL_WRAP(hSev, "?OnExitProc@CBLModule7@@UAEXH@Z", OnExitProc, PF_ONEXITPROC)
	INSTALL_WRAP(hSev, "?IsAccess@CRightsContainer@@QBEHIJI@Z", IsAccess, PF_ISACCESS)

	//INSTALL_WRAP(hBas, "?OnCmdMsg@CTabFrame@@UAEHIHPAXPAUAFX_CMDHANDLERINFO@@@Z", OnCmdMsg, PF_OnCmdMsg)

	pBkEndUI->DoMessageLine("%%GetMainMessageHandler%%");
	
	{ 
		DWORD old;
		DWORD* adr;
		adr = (DWORD*)GetProcAddress(hTxtedt, "?IsError@CMainMessageHandler@@SAHW4MessageMarker@@@Z");
		VirtualProtect(adr, 6, PAGE_EXECUTE_READWRITE, &old);
		jmpIsError = (DWORD)CWrapModule::IsError;
		adrIsError = adr;
		adrIsError[0] = 0x25FF9090;
		adrIsError[1] = (DWORD)&jmpIsError;
	}
	
	CLockHandler::Init();

	INSTALL_WRAP(hSev, "?UnloadAddIns@CApp7@@QAEXXZ", UnloadAddIns, PF_UNLOADADDINS)

	INSTALL_WRAP_v2(hBk, "?AssignContext@CValue@@QAEHPAVCBLContext@@@Z", AssignContext)

	INSTALL_WRAP(hSev, "?WriteStatusLine@@YAXPBD@Z", WriteStatusLine, PF_WriteStatusLine)
	INSTALL_WRAP(hSev, "?WriteStatusLine@@YAXI@Z", WriteStatusLineUINT, PF_WriteStatusLineUINT)

	INSTALL_WRAP(hBas, "??0CGetDoc7@@IAE@XZ", CGetDoc7_Constructor, PF_CGETDOC7)

//?DrawItem@CCheckListBox@@UAEXPAUtagDRAWITEMSTRUCT@@@Z
//??_7CCheckListBox7@@6B@
	//SetWrapCheckListBoxDrawItem(TRUE);
	//SetWrapCheckListBoxDrawItem(bSetDrawWrap);
}

BEGIN_MESSAGE_MAP(CDrawStaticWrap, CStatic)
	ON_WM_PAINT()
END_MESSAGE_MAP()

   // Map "Static Styles" to "Text Styles"
#define MAP_STYLE(src, dest) if(dwStyle & (src)) dwText |= (dest)
#define NMAP_STYLE(src, dest) if(!(dwStyle & (src))) dwText |= (dest)

void CDrawStaticWrap::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	
	// Where to draw text
	CRect client_rect;
	GetClientRect(client_rect);
	
	// Get the caption
	CString szText;
	GetWindowText(szText);
	
	// Get the font
	CFont *pFont, *pOldFont;
	pFont = GetFont();
	pOldFont = dc.SelectObject(pFont);
	
	DWORD dwStyle = GetStyle(), dwText = DT_EXPANDTABS; //0;
	
	MAP_STYLE(	SS_RIGHT,			DT_RIGHT					);
	MAP_STYLE(	SS_CENTER,			DT_CENTER					);
	MAP_STYLE(	SS_CENTERIMAGE,		DT_VCENTER | DT_SINGLELINE	);
	MAP_STYLE(	SS_NOPREFIX,		DT_NOPREFIX					);
	MAP_STYLE(	SS_WORDELLIPSIS,	DT_WORD_ELLIPSIS			);
	MAP_STYLE(	SS_ENDELLIPSIS,		DT_END_ELLIPSIS				);
	MAP_STYLE(	SS_PATHELLIPSIS,	DT_PATH_ELLIPSIS			);
	
	NMAP_STYLE(	SS_LEFTNOWORDWRAP |
				SS_CENTERIMAGE |
				SS_WORDELLIPSIS |
				SS_ENDELLIPSIS |
				SS_PATHELLIPSIS,	DT_WORDBREAK);
	
	conv.pV = adrCtlColor;
	HBRUSH hBrush = (((CDrawStatic*)this)->*(conv.pCC))(&dc, GetDlgCtrlID());

	CBrush* pBrush = CBrush::FromHandle(hBrush);
	dc.FillRect(client_rect,pBrush);
	// Set transparent background
	//if(((CDrawStatic*)this)->IsTransparent())
		dc.SetBkMode(TRANSPARENT);
	
	// Draw the text
	if(dwStyle & WS_DISABLED)
	{
		COLORREF crOld = dc.SetTextColor(RGB(0xFF,0xFF,0xFF));
		dc.DrawText(szText, client_rect, dwText);
		dc.SetTextColor(RGB(0x80,0x80,0x80));
		client_rect.left--;
		client_rect.top--;
		client_rect.right--;
		client_rect.bottom--;
		dc.DrawText(szText, client_rect, dwText);
		dc.SetTextColor(crOld);
	}
	else
	{
		dc.DrawText(szText, client_rect, dwText);
	}
	
	dc.SelectObject(pOldFont);
}

BEGIN_MESSAGE_MAP(CDrawTrasparentCtrlWrap, CButton)
	ON_WM_PAINT()
	ON_WM_ENABLE()
	ON_WM_ERASEBKGND()
	ON_WM_SETFOCUS()
	ON_WM_KILLFOCUS()
END_MESSAGE_MAP()

void CDrawTrasparentCtrlWrap::OnPaint()
{
	DWORD dwStyle = GetStyle(), dwText = 0;
	CPaintDC dc(this); // device context for painting
	CRect rect;
	GetClientRect(rect);
	DRAWITEMSTRUCT DIS;
	DIS.hDC = dc.m_hDC;
	DIS.rcItem = rect;
	
	MAP_STYLE(	WS_DISABLED,			ODS_DISABLED);
	if(GetFocus() == this) dwText |= ODS_FOCUS;
	DIS.itemState = dwText;

	CFont *pFont, *pOldFont;
	pFont = GetFont();
	pOldFont = dc.SelectObject(pFont);
	Draw(&DIS);
	dc.SelectObject(pOldFont);
}
//-------------------------------------------------------------------
//
COLORREF m_crText = ::GetSysColor(COLOR_WINDOWTEXT);
COLORREF m_crWindow = ::GetSysColor(COLOR_WINDOW);
COLORREF m_crFace = ::GetSysColor(COLOR_3DFACE);

void CDrawTrasparentCtrlWrap::Draw(LPDRAWITEMSTRUCT lpDIS) 
{
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	CRect rectItem(lpDIS->rcItem);

  	UINT nState = lpDIS->itemState;
	UINT nStyle = GetStyle();
	BOOL bDisabled = BOOL(nState & ODS_DISABLED);

	// Determine the rect for the check mark.
	CRect rectCheck;
	int nHeight = 13;
	int nAdjust = (rectItem.Height() - nHeight) >> 1;
	if (nStyle & BS_LEFTTEXT)
		rectCheck.SetRect(rectItem.right - nHeight, rectItem.top + nAdjust, 
								rectItem.right, rectItem.top + nHeight + nAdjust);
	else
		rectCheck.SetRect(rectItem.left, rectItem.top + nAdjust, 
								rectItem.left + nHeight, rectItem.top + nHeight + nAdjust);

	pDC->SetBkMode(TRANSPARENT);

	conv.pV = adrCtlColorTrans;
	HBRUSH hBrush = (((CDrawTrasparentCtrl*)this)->*(conv.pCC_TC))(pDC, GetDlgCtrlID());
	HWND parent = GetParent()->GetSafeHwnd();
    if (hBrush == NULL)
        hBrush = (HBRUSH)::DefWindowProc(parent, WM_CTLCOLORSTATIC,
					(WPARAM)pDC->m_hDC, (LPARAM)GetSafeHwnd() );

	CBrush* pBrush = CBrush::FromHandle(hBrush);
	pDC->FillRect(rectItem,pBrush);

	// Determine the rect for the text.
	if (nStyle & BS_LEFTTEXT)
		rectItem.left = lpDIS->rcItem.left + 2;
	else
		rectItem.left += nHeight + 5; //5;
	//rectItem.top++;

	CString sText;
	GetWindowText(sText);

	CSize size = pDC->GetTextExtent(sText);
  	rectItem.right = rectItem.left + size.cx;// + (nStyle & BS_LEFTTEXT ? 2 : -5);
	rectItem.top = (rectItem.Height() - size.cy) >> 1;
	rectItem.bottom = rectItem.top + size.cy;

	if(rectItem.right > lpDIS->rcItem.right) rectItem.right = lpDIS->rcItem.right;
	// Draw the text.
	if (bDisabled)
	{
		CRect client_rect = rectItem;
		COLORREF crOld = pDC->SetTextColor(RGB(0xFF,0xFF,0xFF));
		client_rect.left++;
		client_rect.right++;
		pDC->DrawText(sText, client_rect, DT_LEFT);
		pDC->SetTextColor(RGB(0x80,0x80,0x80));
		client_rect.left--;
		client_rect.top--;
		client_rect.right--;
		client_rect.bottom--;
		pDC->DrawText(sText, client_rect, DT_LEFT | DT_EXPANDTABS);
		pDC->SetTextColor(crOld);
	}
	else
		pDC->DrawText(sText, rectItem, DT_LEFT | DT_EXPANDTABS);

	// Draw the focus rect.
	if((nStyle & BS_AUTORADIOBUTTON) == BS_AUTORADIOBUTTON)
	{
//		rectItem.InflateRect(2, 1, 0, 1);
//		if(rectItem.top < 0) rectItem.top = 0;
		if (nState & ODS_FOCUS)
			pDC->DrawFocusRect(rectItem); 

		DrawRadioMark(pDC, rectCheck, nStyle, nState);
	}
	else
	{
//		rectItem.InflateRect(2, 1, 0, 2);
		rectItem.InflateRect(1, 0, 0, 0);
		if (nState & ODS_FOCUS)
			pDC->DrawFocusRect(rectItem); 

		DrawCheckMark(pDC, rectCheck, nStyle, nState);
	}

}	// DrawItem

//-------------------------------------------------------------------
//
void CDrawTrasparentCtrlWrap::DrawCheckMark(CDC *pDC, CRect rect, UINT nStyle, UINT nState)
{
	DWORD flags = DFCS_BUTTONCHECK;
	if (nStyle & BS_FLAT)
		flags |= DFCS_FLAT;
	if (GetCheck())
		flags |= DFCS_CHECKED;
	if(nState & ODS_DISABLED)
		flags |= DFCS_INACTIVE;
	pDC->DrawFrameControl(rect, DFC_BUTTON, flags);
}

void CDrawTrasparentCtrlWrap::DrawRadioMark(CDC *pDC, CRect rect, UINT nStyle, UINT nState)
{
	DWORD flags = DFCS_BUTTONRADIO;
	if (nStyle & BS_FLAT)
		flags |= DFCS_FLAT;
	if (GetCheck())
		flags |= DFCS_CHECKED;
	if(nState & ODS_DISABLED)
		flags |= DFCS_INACTIVE;
	pDC->DrawFrameControl(rect, DFC_BUTTON, flags);
}

void CDrawTrasparentCtrlWrap::OnEnable(BOOL bEnable)
{
//	OnEnable(bEnable);
	conv.pV_M = origOnEnable;
	(((CDrawTrasparentCtrl*)this)->*(conv.pOnEn))(bEnable);
	CWnd* pParent = GetParent();
	if(pParent)
	{
		CRect rect;
		GetWindowRect(rect);
		pParent->ScreenToClient(rect);
		pParent->InvalidateRect(rect);
	}
//	Invalidate();
}

BOOL CDrawTrasparentCtrlWrap::OnEraseBkgnd(CDC* pDC)
{
	return CButton::OnEraseBkgnd(pDC);
}

void CDrawTrasparentCtrlWrap::OnSetFocus(CWnd* pPre)
{
	CWnd* pParent = GetParent();
	if(pParent)
	{
		CRect rect;
		GetWindowRect(rect);
		pParent->ScreenToClient(rect);
		pParent->InvalidateRect(rect);
	}
	CWnd::OnSetFocus(pPre);
}

void CDrawTrasparentCtrlWrap::OnKillFocus(CWnd* pNew)
{
	CWnd* pParent = GetParent();
	if(pParent)
	{
		CRect rect;
		GetWindowRect(rect);
		pParent->ScreenToClient(rect);
		pParent->InvalidateRect(rect);
	}
	CWnd::OnKillFocus(pNew);
}

//////////////////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CFormExListBox, CListBox)
	//{{AFX_MSG_MAP(CFormExListBox)
	ON_WM_PAINT()
	ON_WM_NCDESTROY()
    ON_MESSAGE(WM_SETFONT, OnSetFont)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CFormExListBox::OnPaint()
{
	CListBox::OnPaint();
}

void CFormExListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CRect itemRect = lpDrawItemStruct->rcItem;
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	pDC->SetBkMode(TRANSPARENT);

	CString str;
	GetText(lpDrawItemStruct->itemID, str);

	COLORREF crOldText = pDC->GetTextColor();
	COLORREF crBkColor = ::GetSysColor(COLOR_WINDOW);
	COLORREF crBkColorSel = ::GetSysColor(COLOR_ACTIVECAPTION);
	COLORREF crTextColor = ::GetSysColor(COLOR_WINDOWTEXT);
	COLORREF crTextColorSel = RGB(0xFF,0xFF,0xFF);
	DWORD fontSetS = 0;
	DWORD fontSet = 0;

	CString st_buf = str;
	st_buf.MakeUpper();
	char ** endptr = NULL;
	const char * ptr = NULL;
				
	int iBuf = st_buf.Find("FONTSET_S[",0);
	if(iBuf >= 0)
	{
		iBuf += 10;
		if(st_buf.Mid(iBuf, 4) != "NONE")
			fontSetS = (DWORD)atol(st_buf.Mid(iBuf));
	}
	iBuf = st_buf.Find("FONTSET[",0);
	if(iBuf >= 0)
	{
		iBuf += 8;
		if(st_buf.Mid(iBuf, 4) != "NONE")
			fontSet = (DWORD)atol(st_buf.Mid(iBuf));
	}
	iBuf = st_buf.Find("FONT_S[",0);
	if(iBuf >= 0)
	{
		iBuf  += 7;
		if(st_buf.Mid(iBuf , 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crTextColorSel = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("FONT[",0);
	if(iBuf >= 0)
	{
		iBuf += 5;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crTextColor = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("BRUSH_S[",0);
	if(iBuf >= 0)
	{
		iBuf += 8;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crBkColorSel = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("BRUSH[",0);
	if(iBuf >= 0)
	{
		iBuf += 6;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crBkColor = strtol(ptr,endptr,0);
		}
	}

	CFont* pOldFont = pDC->SelectObject(GetFont());

	if((lpDrawItemStruct->itemState & ODS_SELECTED))
	{
		pDC->FillSolidRect(itemRect, crBkColorSel);
		pDC->SetTextColor(crTextColorSel);
		if(fontSetS)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSetS));
		else if(fontSet)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
	}
	else
	{
		pDC->FillSolidRect(itemRect, crBkColor);
		pDC->SetTextColor(crTextColor);
		if(fontSet)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
	}

	int n = str.Find("\r");
	if(n>=0) str = str.Left(n);
	CRect textRect = itemRect;
	textRect.DeflateRect(2,0,0,0);
	pDC->DrawText(str, textRect, DT_VCENTER | DT_SINGLELINE | DT_EXPANDTABS);

	if ((lpDrawItemStruct->itemState & ODS_FOCUS) != 0)
		pDC->DrawFocusRect(itemRect);


	pDC->SetTextColor(crOldText);
	pDC->SelectObject(pOldFont);
}

void CFormExListBox::OnNcDestroy(void)
{
	CListBox::OnNcDestroy();
	delete this;
}

LRESULT CFormExListBox::OnSetFont(WPARAM wParam, LPARAM lParam)
{
    LRESULT lresult = CListBox::Default();

	CDC* pDC = GetDC();
	TEXTMETRIC tm;
	CFont* pFont = GetFont();
	CFont* pOldFont = pDC->SelectObject(pFont);	
	pDC->GetTextMetrics(&tm);
	int nItemHeight = tm.tmHeight; // + tm.tmExternalLeading + tm.tmInternalLeading;
	pDC->SelectObject(pOldFont);
	SetItemHeight(-1, nItemHeight);
    return lresult;
}

//////////////////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CFormExComboBox, CComboBox)
	//{{AFX_MSG_MAP(CFormExComboBox)
	//ON_WM_PAINT()
	ON_WM_NCDESTROY()
	ON_MESSAGE(WM_SETFONT, OnSetFont)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/*
void CFormExComboBox::OnPaint()
{
	CComboBox::OnPaint();
}
*/

void CFormExComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CRect itemRect = lpDrawItemStruct->rcItem;
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	pDC->SetBkMode(TRANSPARENT);

	CString str;
	GetLBText(lpDrawItemStruct->itemID, str);

	COLORREF crOldText = pDC->GetTextColor();
	COLORREF crBkColor = ::GetSysColor(COLOR_WINDOW);
	COLORREF crBkColorSel = ::GetSysColor(COLOR_ACTIVECAPTION);
	COLORREF crTextColor = ::GetSysColor(COLOR_WINDOWTEXT);
	COLORREF crTextColorSel = RGB(0xFF,0xFF,0xFF);
	DWORD fontSetS = 0;
	DWORD fontSet = 0;

	CString st_buf = str;
	st_buf.MakeUpper();
	char ** endptr = NULL;
	const char * ptr = NULL;
				
	int iBuf = st_buf.Find("FONTSET_S[",0);
	if(iBuf >= 0)
	{
		iBuf += 10;
		if(st_buf.Mid(iBuf, 4) != "NONE")
			fontSetS = (DWORD)atol(st_buf.Mid(iBuf));
	}
	iBuf = st_buf.Find("FONTSET[",0);
	if(iBuf >= 0)
	{
		iBuf += 8;
		if(st_buf.Mid(iBuf, 4) != "NONE")
			fontSet = (DWORD)atol(st_buf.Mid(iBuf));
	}
	iBuf = st_buf.Find("FONT_S[",0);
	if(iBuf >= 0)
	{
		iBuf  += 7;
		if(st_buf.Mid(iBuf , 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crTextColorSel = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("FONT[",0);
	if(iBuf >= 0)
	{
		iBuf += 5;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crTextColor = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("BRUSH_S[",0);
	if(iBuf >= 0)
	{
		iBuf += 8;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crBkColorSel = strtol(ptr,endptr,0);
		}
	}
	iBuf = st_buf.Find("BRUSH[",0);
	if(iBuf >= 0)
	{
		iBuf += 6;
		if(st_buf.Mid(iBuf, 4) != "NONE")
		{
			ptr = st_buf.Mid(iBuf);
			endptr = (char**)&ptr;
			crBkColor = strtol(ptr,endptr,0);
		}
	}

	CFont* pOldFont = pDC->SelectObject(GetFont());

	if((lpDrawItemStruct->itemState & ODS_SELECTED))
	{
		pDC->FillSolidRect(itemRect, crBkColorSel);
		pDC->SetTextColor(crTextColorSel);
		if(fontSetS)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSetS));
		else if(fontSet)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
	}
	else
	{
		pDC->FillSolidRect(itemRect, crBkColor);
		pDC->SetTextColor(crTextColor);
		if(fontSet)
			pDC->SelectObject(CFont::FromHandle((HFONT)fontSet));
	}

	int n = str.Find("\r");
	if(n>=0) str = str.Left(n);
	CRect textRect = itemRect;
	textRect.DeflateRect(1,1,1,1);
	pDC->DrawText(str, textRect, DT_VCENTER | DT_SINGLELINE | DT_EXPANDTABS);

	if ((lpDrawItemStruct->itemState & ODS_FOCUS) != 0)
		pDC->DrawFocusRect(itemRect);

	pDC->SetTextColor(crOldText);
	pDC->SelectObject(pOldFont);
}

void CFormExComboBox::OnNcDestroy(void)
{
	CComboBox::OnNcDestroy();
	delete this;
}

LRESULT CFormExComboBox::OnSetFont(WPARAM wParam, LPARAM lParam)
{
    LRESULT lresult = CComboBox::Default();

	CDC* pDC = GetDC();
	TEXTMETRIC tm;
	CFont* pFont = GetFont();
	CFont* pOldFont = pDC->SelectObject(pFont);	
	pDC->GetTextMetrics(&tm);
	int nItemHeight = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;
	pDC->SelectObject(pOldFont);
	SetItemHeight(-1, nItemHeight);

    return lresult;
}
// 
// //int iCountStream = 0;
// 
// int procGetAllTypedItem(class CString &str,long l1,long l2,enum PageType pt)
// {
// 	if(str.CollateNoCase("ModuleText") == 0)
// 		return 1;
// 
// 	CMetaDataCont *pMD = GetMetaData();
// 	CMetaDataObj* pMDO = pMD->FindObject(l1);
// 	CString str1 = GetModuleFullName(l1, str, 0, pMD);
// 	str1.MakeUpper();
// 
// 	SDocNames *pDocNames = NULL;
// 	pDocNames = new SDocNames; // TODO проверить удаление
// 	pDocNames->id = l1;
// 	pDocNames->strFolder = str;
// 	DocNamesArray.SetAt(str1,pDocNames);
// 
// 	return 1;
// }
// 
// void CInitFormEx::GetNamesOfAllForms()
// {
// 	//iCountStream = 0;
// 	CConfigCont::GetAllTypedItem(procGetAllTypedItem,0,ptDialog,0);
// }

bool GetTableOutputContextFromDocument(CDocument* pDoc, CBLPtr<CTableWrapEx>& pTableOutputContextDest)
{
	if(!IS_KINDOF_RUNTIME_CLASS(pDoc, CSheetDoc))
		return false;

	CSheetDoc* pSheetDoc = static_cast<CSheetDoc*>(pDoc);
	
	pTableOutputContextDest.Create("Table"); //pTableOutputContextDest = static_cast<CTableWrapEx*>(CBLContext::CreateInstance("Table"));
	if(!pTableOutputContextDest)
		return true;

	CTableWrapEx* pTableOutputContext = pTableOutputContextDest;

	pTableOutputContext->m_pSheetDocOut = pSheetDoc;
	pTableOutputContext->dwFlag1 = CTemplate7::GetDocumentID(pSheetDoc);
	DWORD dw = (DWORD)pSheetDoc;
	pTableOutputContext->dwFlag2 = (dw + 0xB0);
	
	((DWORD*)pTableOutputContext)[0x118] = 1;
	((DWORD*)pTableOutputContext)[0x11D] = 1;

	return true;
}

int CWrapModule::WrapCreateFromFile(const char * ccFileName)
{
	CPictureHolder7* This = (CPictureHolder7*)this;
	SET_ORIGIN_FUNC(CreateFromFile)

	//pBkEndUI->DoMessageLine(ccFileName, mmNone);

	int ret = This->CreateFromFile(ccFileName);

	SET_WRAP_FUNC(CreateFromFile)

	return ret;
}
