opensvmview.cpp

来自「OpenSVM was developped under Visual C++ 」· C++ 代码 · 共 198 行

CPP
198
字号
// OpenSVMView.cpp : implementation of the COpenSVMView class
//

#include "stdafx.h"
#include "OpenSVM.h"

#include "OpenSVMDoc.h"
#include "OpenSVMView.h"


//user's include 
#include "NormalDlg.h"
#include "ModelManageDlg.h"



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

/////////////////////////////////////////////////////////////////////////////
// COpenSVMView

//IMPLEMENT_DYNCREATE(COpenSVMView, CView)
IMPLEMENT_DYNCREATE(COpenSVMView, CScrollView)
//BEGIN_MESSAGE_MAP(COpenSVMView, CView)
BEGIN_MESSAGE_MAP(COpenSVMView, CScrollView)
	//{{AFX_MSG_MAP(COpenSVMView)
	ON_COMMAND(IDD_TRAIN_NORMAL, OnTrainNormal)
	ON_COMMAND(IDD_PREDICT, OnPredict)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenSVMView construction/destruction

COpenSVMView::COpenSVMView()
{
	// TODO: add construction code here

}

COpenSVMView::~COpenSVMView()
{
}

BOOL COpenSVMView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// COpenSVMView drawing

void COpenSVMView::OnDraw(CDC* pDC)
{
	COpenSVMDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	UpdateData(true);
	CString filename = pDoc->GetPathName();	
	CFileException fe;
	CString TextLine;

	// TODO: add draw code for native data here
	if(filename.GetLength() == 0)
	{
		DrawLogo();
	}	
	else 
	{
		CFile *datafile = pDoc->GetFile(filename,CFile::modeRead,&fe);
		CArchive loadArchive(datafile,CArchive::load);
		SetViewSize(datafile,loadArchive);

		for(UINT i =0;i<nr_fileLine;i++)
		{
			loadArchive.ReadString(TextLine);
			pDC->TextOut(0,i*20,TextLine);
		}

		loadArchive.Close();
		datafile->Close();
	}
//	OnUpdate()
}

/////////////////////////////////////////////////////////////////////////////
// COpenSVMView diagnostics

#ifdef _DEBUG
void COpenSVMView::AssertValid() const
{
	CScrollView::AssertValid();
}

void COpenSVMView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

COpenSVMDoc* COpenSVMView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COpenSVMDoc)));
	return (COpenSVMDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// COpenSVMView message handlers


void COpenSVMView::DrawLogo()
{
	
	CDC  dcMemory;
	dcMemory.CreateCompatibleDC(NULL);
	
	CBitmap logo,*oldBmp;
	logo.LoadBitmap(IDB_LOGO);
	oldBmp = dcMemory.SelectObject(&logo);

	BITMAP bm;
	logo.GetBitmap(&bm);
	int bmWidth = bm.bmWidth;
	int bmHeight = bm.bmHeight;
	
	CRect   rectClient;   
    GetClientRect(rectClient);
	int viewWidth  = rectClient.Width();
	int viewHeight = rectClient.Height();

	int beginX=(viewWidth-bmWidth)/2;
	int beginY=(viewHeight-bmHeight)/2;

	GetDC()->BitBlt(beginX-20,beginY-50,bmWidth,bmHeight,&dcMemory,0,0,SRCCOPY);
	dcMemory.SelectObject(oldBmp);

	GetDC()->TextOut(0,0,"Version: 1.0.1 Beta");
}


void COpenSVMView::OnTrainNormal() 
{
	// TODO: Add your command handler code here
	CNormalDlg normal;
	normal.DoModal();
	
}

void COpenSVMView::OnPredict() 
{
	// TODO: Add your command handler code here
	CModelManageDlg ModelManage;
	ModelManage.DoModal();
}

void COpenSVMView::SetViewSize(CFile *fp,CArchive &ar)
{

	char c;
	UINT nr_line = 1,nr_col = 0,max_col=1;
	for (UINT i = 0;i<(fp->GetLength());i++)
	{
		ar >> c;
		nr_col++;
		if (c == '\n') 
		{
			nr_line++;
			if (nr_col > max_col)
			{
				max_col = nr_col;
			}
			nr_col = 0;
		}	
	}
	
	CSize totalsize;
	totalsize.cx=max_col*5;
	totalsize.cy=nr_line*20;
	SetScrollSizes(MM_TEXT,totalsize);
	
	fp->SeekToBegin();

	nr_fileLine = nr_line;
}

void COpenSVMView::OnInitialUpdate() 
{
	CScrollView::OnInitialUpdate();
	// TODO: Add your specialized code here and/or call the base class
	SetScrollSizes(MM_TEXT,CSize(1,1));
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?