⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test2view.cpp

📁 根据《VC++6.0 用户界面制作技术与应用实例》写的一些代码
💻 CPP
字号:
// test2View.cpp : implementation of the CTest2View class
//

#include "stdafx.h"
#include "test2.h"

#include "test2Doc.h"
#include "ModelessDlg.h"
#include "test2View.h"
#include "Dlg.h"
#include "resource.h"
#include "StatusDlg.h"
#include "math.h"


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

/////////////////////////////////////////////////////////////////////////////
// CTest2View

IMPLEMENT_DYNCREATE(CTest2View, CView)

BEGIN_MESSAGE_MAP(CTest2View, CView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CTest2View)
	ON_UPDATE_COMMAND_UI(IDR_TEST, OnUpdateTest)
	ON_COMMAND(IDR_TEST, OnTest)
	ON_COMMAND(ID_EDIT_TEST, OnEditTest)
	ON_WM_KEYUP()
	ON_COMMAND(IDR_HAHA, OnHaha)
	ON_COMMAND(IDR_RECTANGLE, OnRectangle)
	ON_COMMAND(IDR_THREED, OnThreed)
	ON_COMMAND(IDR_TRIANGLE, OnTriangle)
	ON_WM_MOUSEMOVE()
	ON_COMMAND(IDR_MODELLESS, OnModelless)
	ON_COMMAND(IDR_PROPERTYSET, OnPropertyset)
	ON_COMMAND(IDC_CIRCLE, OnCircle)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_COMPUTE, OnCompute)
	ON_COMMAND(IDR_SPLITTERWND, OnSplitterwnd)
	//}}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)
//	ON_COMMAND(WM_TESTMES ,OnTestMes)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest2View construction/destruction
void CTest2View::OnTestMes(UINT wParam ,LONG lParam)
{
	//AfxMessageBox("Victory!!!!");
	CDC* pDC = GetDC();
	CRect * rect ;
	GetClientRect(rect);

	CBrush *pNewBrush = new CBrush ;
	pNewBrush->CreateSolidBrush(wParam);
	CBrush *pOldBrush = pDC->SelectObject(pNewBrush);
	pDC->Rectangle(rect);
	pDC->SelectObject(pOldBrush);
	delete pNewBrush;
}

CTest2View::CTest2View()
{
	// TODO: add construction code here
    m_dlg = new CModelessDlg((CWnd*)this);
	dlg = new CStatusDlg;
	m_dlg2 = new CDlg ;
}

CTest2View::~CTest2View()
{
	delete m_dlg ;
	delete dlg ;
	delete m_dlg2;
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View drawing

void CTest2View::OnDraw(CDC* pDC)
{
	CTest2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->TextOut(10,30,"Splitter window is created!");
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View printing

BOOL CTest2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTest2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTest2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View diagnostics

#ifdef _DEBUG
void CTest2View::AssertValid() const
{
	CView::AssertValid();
}

void CTest2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CTest2View message handlers

void CTest2View::OnUpdateTest(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(1);
}

void CTest2View::OnTest() 
{
	// TODO: Add your command handler code here
	m_dlg2->DoModal();
}

void CTest2View::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_TEST2_VIEW));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

void CTest2View::OnEditTest() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("This is a test!");
	
}

void CTest2View::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CWnd * pMainWnd = AfxGetMainWnd();
	extern CTest2App theApp ;
	switch(nChar)
	{
	case VK_F1:
		pMainWnd->SetMenu(theApp.m_pMenuOrg);
		break;
	case VK_F2:
		pMainWnd->SetMenu(theApp.m_pMenu1);
		break;
	case VK_F3:
		pMainWnd->SetMenu(theApp.m_pMenu2);
		break;
	}
	CView::OnKeyUp(nChar, nRepCnt, nFlags);
}

void CTest2View::OnHaha() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("this is a test too !");
}

void CTest2View::OnRectangle() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("this is a Rectangle");
}

void CTest2View::OnThreed() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("this is a Threed");
}

void CTest2View::OnTriangle() 
{
	// TODO: Add your command handler code here
	AfxMessageBox("this is a Triangle");
}

void CTest2View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CStatusBar* pStatusBar = (CStatusBar*)AfxGetApp()->m_pMainWnd->
		GetDescendantWindow(ID_VIEW_STATUS_BAR);
	if(pStatusBar)
	{
		char tubf[40];
		sprintf(tubf , "%3d,%3d",point.x,point.y);
		pStatusBar->SetPaneText(1,tubf);
	}
	CView::OnMouseMove(nFlags, point);
}

void CTest2View::OnModelless() 
{
	// TODO: Add your command handler code here
	if(m_dlg->GetSafeHwnd()==0)
	{   
		m_dlg->Create(IDD_DIALOG_MODELESS);   
		m_dlg->ShowWindow(SW_SHOW);
		//m_dlg->Create();
	}
}

void CTest2View::OnProperties()
{
	// TODO: The property sheet attached to your project
	// via this function is not hooked up to any message
	// handler.  In order to actually use the property sheet,
	// you will need to associate this function with a control
	// in your project such as a menu item or tool bar button.

	CStatusDlg propSheet;

	propSheet.DoModal();

	// This is where you would retrieve information from the property
	// sheet if propSheet.DoModal() returned IDOK.  We aren't doing
	// anything for simplicity.
}

void CTest2View::OnPropertyset() 
{
	// TODO: Add your command handler code here
	dlg->SetTitle("PropertySet");
	dlg->DoModal();
}

void CTest2View::OnCircle() 
{
	// TODO: Add your command handler code here
	double x = dlg->m_Page1.m_dOriginX ;
	int y = dlg->m_Page3.m_bCenter;
}

void CTest2View::OnButton1() 
{
	// TODO: Add your control notification handler code here
	//AfxMessageBox("mydialogbar is created!!!");
	UpdateData();

	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO1);
	int cursel = pComboBox->GetCurSel();
	char tubf[80];
	int ret = pComboBox->GetLBText(cursel , tubf);

	ASSERT(ret != CB_ERR);

	switch(tubf[0])
	{
	case '+':
		m_dlg2->m_result = m_dlg2->m_x1+m_dlg2->m_x2;
		break;
	case '-':
		m_dlg2->m_result = m_dlg2->m_x1-m_dlg2->m_x2;
		break;
	case '*':
		m_dlg2->m_result = m_dlg2->m_x1*m_dlg2->m_x2;
		break;
	case '/':
		if(fabs(m_dlg2->m_x2)>1e-16)
			m_dlg2->m_result = m_dlg2->m_x1+m_dlg2->m_x2;
		else
			AfxMessageBox("Can't compute!!!!!!");
		break;
	default:
		break;
	}

	sprintf(tubf , "%f",m_dlg2->m_result);
	SetDlgItemText(IDC_EDIT_RESULT,tubf);
}

void CTest2View::OnCompute() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO1);
	int cursel = pComboBox->GetCurSel();
	char tubf[80];
	int ret = pComboBox->GetLBText(cursel , tubf);

	ASSERT(ret != CB_ERR);

	switch(tubf[0])
	{
	case '+':
		m_dlg2->m_result = m_dlg2->m_x1+m_dlg2->m_x2;
		break;
	case '-':
		m_dlg2->m_result = m_dlg2->m_x1-m_dlg2->m_x2;
		break;
	case '*':
		m_dlg2->m_result = m_dlg2->m_x1*m_dlg2->m_x2;
		break;
	case '/':
		if(fabs(m_dlg2->m_x2)>1e-16)
			m_dlg2->m_result = m_dlg2->m_x1+m_dlg2->m_x2;
		else
			AfxMessageBox("Can't compute!!!!!!");
		break;
	default:
		break;
	}

	sprintf(tubf , "%f",m_dlg2->m_result);
	SetDlgItemText(IDC_EDIT_RESULT,tubf);
}

void CTest2View::OnSplitterwnd() 
{
	// TODO: Add your command handler code here
	
}

⌨️ 快捷键说明

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