• 我的东软实习项目一:车牌识别之MFC----MyView.cpp


    // MyView.cpp : implementation of the CMyView class
    //
    
    #include "stdafx.h"
    #include "My.h"
    
    #include "MyDoc.h"
    #include "MyView.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView
    
    IMPLEMENT_DYNCREATE(CMyView, CView)
    
    BEGIN_MESSAGE_MAP(CMyView, CView)
    	//{{AFX_MSG_MAP(CMyView)
    	ON_WM_LBUTTONDOWN()
    	ON_WM_RBUTTONDOWN()
    	ON_COMMAND(ID_Menuitem32771, OnMenuitem32771)
    	//}}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()
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView construction/destruction
    
    CMyView::CMyView()//:m(10)
    {
    	// TODO: add construction code here
    
    }
    
    CMyView::~CMyView()
    {
    }
    
    BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
    {
    	// TODO: Modify the Window class or styles here by modifying
    	//  the CREATESTRUCT cs
    
    	return CView::PreCreateWindow(cs);
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView drawing
    
    void CMyView::OnDraw(CDC* pDC)
    {
    	CMyDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    
    
    //在屏幕上显示str字符串
    /*	CString str;
    	str.Format("计数 %d",pDoc->m);//类型转换
    	pDC->TextOut(30,30,str);
    	pDoc->SetModifiedFlag();//改变时提示是否保存
    
    	CStudent stud1("中华",77);
    	stud1.display(pDC,50,60);
    */
    //strTemp触发OnDraw函数,在屏幕上显示输出
    	pDC->TextOut(20,20,strTemp);
    
    	
    	// TODO: add draw code for native data here
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView printing
    
    BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    	// default preparation
    	return DoPreparePrinting(pInfo);
    }
    
    void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    	// TODO: add extra initialization before printing
    }
    
    void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    	// TODO: add cleanup after printing
    }
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView diagnostics
    
    #ifdef _DEBUG
    void CMyView::AssertValid() const
    {
    	CView::AssertValid();
    }
    
    void CMyView::Dump(CDumpContext& dc) const
    {
    	CView::Dump(dc);
    }
    
    CMyDoc* CMyView::GetDocument() // non-debug version is inline
    {
    	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
    	return (CMyDoc*)m_pDocument;
    }
    #endif //_DEBUG
    
    /////////////////////////////////////////////////////////////////////////////
    // CMyView message handlers
    
    void CMyView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    	// TODO: Add your message handler code here and/or call default
    //点击左键递增	
    /*	CMyDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	pDoc->m+=1;
    	//str.Format("%d",m);
    	this->Invalidate();
    	
    	CView::OnLButtonDown(nFlags, point);
    */
    
    
    
    //点击左键与数据库连接
    /*  CStudentRecordSet rs;
    	rs.Open();
    	rs.AddNew();
    	rs.m_ID="0004";
    	rs.m_Name="华";
    	rs.m_Score=103;
        rs.Update();
    	rs.Close();
    */
    
    
    //点左键修改值
    /*	CStudentRecordSet rs;
    	rs.m_strFilter="ID='0001'";//字符串过滤,找到ID为0001的数据
    	rs.Open();
    	rs.Edit();//修改
    	rs.m_Name="夏天"//Name修改为夏天
    	rs.Update();
    	rs.Close();
    */
    //有多个相同的需要修改 用循环
    	CStudentRecordSet rs;
    	rs.m_strFilter="Score=88";
    	rs.Open();
    
    	while(!rs.IsEOF())
    	{
    		rs.Edit();
    		rs.m_Name="蓝天";
    		rs.Update();
    		rs.MoveNext();		
    		
    	}
    	rs.Close();
    
    //查找并显示
    /*	int y=20;
    	CStudentRecordSet rs;
    	CString strTemp;
    	CClientDC dc(this);
    	rs.m_strFilter="Score=88";
    	rs.Open();
    	while(!rs.IsEOF())
    	{
    		strTemp.Format("ID:%s  Name:%s  Score:%d",rs.m_ID,rs.m_Name,rs.m_Score);
    		rs.MoveNext();
    		dc.TextOut(300,y,strTemp);
    		y+=30;
    	}
    	rs.Close();
    */
    
    //删除1 用数据库删除(效率更高)
    /*	CDatabase db;
    	CStudentRecordSet rs(&db);
    	CString strSql="delete from studenttable";
    	rs.Open();
    	db.ExecuteSQL(strSql);
    */
    //删除2 一个一个删除
    /*	CStudentRecordSet rs;
    	rs.Open();
    	while(!rs.IsEOF())
    	{
    		rs.Delete();
            rs.MoveNext();
    	}
    	rs.Close();
    */	
    }
    
    void CMyView::OnRButtonDown(UINT nFlags, CPoint point) 
    {
    	// TODO: Add your message handler code here and/or call default
    //点击右键递减
    /*	CMyDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	pDoc->m-=1;
    	//str.Format("%d",m);
    	this->Invalidate();//刷新
    */
    
    	CStudentRecordSet rs;
    	rs.Open();
    	int y=20;
    	CString str;
    	CClientDC dc(this);
    	while(!rs.IsEOF())//如果不是文件尾,继续向下输出
    	{
    		str.Format("ID:%s  Name:%s  Score:%d",rs.m_ID,rs.m_Name,rs.m_Score);
    		rs.MoveNext();//向下移动一位
    		dc.TextOut(20,y,str);
    		y+=30;
    	}
    	rs.Close();
    
    	CView::OnRButtonDown(nFlags, point);
    }
    
    
    void CMyView::OnMenuitem32771() 
    {
    	// TODO: Add your command handler code here
    /*//弹出对话框
    	MessageBox("success");
    */
    //1.直接绑定值类型,触发ondraw
    	Cmydialog2 md;
    
    	if(md.DoModal()==IDOK)//domodal的返回值只有IDOK和IDCANCEL
    	{
    		strTemp=md.m_strName+" "+md.m_strID+" "+md.m_strScore;//用临时变量承载三个属性,再用strTemp触发OnDraw函数
    		Invalidate();
    	}
    
    	
    }
    

  • 相关阅读:
    SQL键值约束、索引使用
    C#字符串的四舍五入
    VB中字符串操作函数
    C#文本选中及ContextMenuStrip菜单使用
    C#关于new的用法
    C#有关日期的使用方法
    break,continue的区别
    在Lua中使用数字的时候有个坑
    关于自动寻径和图、邻接表的学习和启发
    关于在Cocos2dx引擎中手动绑定C++到Lua
  • 原文地址:https://www.cnblogs.com/IT-hexiang/p/4084633.html
Copyright © 2020-2023  润新知