// vegaView.cpp : implementation of the CVegaView class
//
#include "stdafx.h"
#include "vega.h"
#include "vegaDoc.h"
#include "vegaView.h"
#include "vg.h"
#include "vgwin.h"
#include "vgutil.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVegaView
IMPLEMENT_DYNCREATE(CVegaView, CView)
BEGIN_MESSAGE_MAP(CVegaView, CView)
//{{AFX_MSG_MAP(CVegaView)
ON_WM_SIZE()
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVegaView construction/destruction
CVegaView::CVegaView()
{ EnableAutomation();
// TODO: add construction code here
vegaInitted=FALSE;
vegaDefined=FALSE;
vegaConfiged=FALSE;
isRunning=FALSE;
m_pVegaThread=NULL;
}
CVegaView::~CVegaView()
{stopVega();
}
BOOL CVegaView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style|=WS_OVERLAPPED|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_VISIBLE;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CVegaView drawing
void CVegaView::OnDraw(CDC* pDC)
{
CVegaDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CVegaView printing
BOOL CVegaView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CVegaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CVegaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CVegaView diagnostics
#ifdef _DEBUG
void CVegaView::AssertValid() const
{
CView::AssertValid();
}
void CVegaView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CVegaDoc* CVegaView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVegaDoc)));
return (CVegaDoc*)m_pDocument;
}
#endif //_DEBUG
UINT runvegaProc(LPVOID pParam)
{CVegaView *hParent=(CVegaView *)pParam;
vgInitWinSys(AfxGetInstanceHandle(),hParent->GetSafeHwnd());
hParent->setVegaInitted(true);
vgDefineSys("eggfly.adf");
hParent->setVegaDefined(true);
hParent->postDefined();
vgConfigSys();
hParent->setVegaConfiged(TRUE);
while(hParent->getVegaRunning())
{ vgSyncFrame();
vgFrame();
}
hParent->setVegaInitted(FALSE);
vgExit(0);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CVegaView message handlers
void CVegaView::runVega()
{ isRunning=TRUE;
if(m_pVegaThread==NULL)
{m_pVegaThread=AfxBeginThread(runvegaProc,this,THREAD_PRIORITY_NORMAL,0,0,NULL);
}
while(!getVegaDefined())
{Sleep(10);
}
win=vgGetWin(0);
if(win==NULL)
{exit(-1);
}
}
void CVegaView::stopVega()
{ if(!vegaInitted)
return;
isRunning=FALSE;
vgDrawEnabled(1);
while(vegaInitted)
Sleep(10);
}
void CVegaView::postDefined(void)
{vgWindow *win=vgGetWin(0);
vgWinSize(win,0,m_cx,0,m_cy);
vgProp(win,VGWIN_WINBORDER,0);
vgExitKey(-1);
}
void CVegaView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
m_cx=cx;
m_cy=cy;
if(!getVegaInitted())
return;
vgWinSize(win,0,cx,0,cy);
// TODO: Add your message handler code here
}
BOOL CVegaView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
int CVegaView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_pMainFrame=(CMainFrame *)GetParentFrame();
runVega();
return 0;
}