int n = this->v.size();
CString str ;
str.Format("%d",n);
AfxMessageBox(str);
引入头文件和引入库文件
#include "./glut/include/gl/glut.h"
#pragma comment(lib,"./glut/lib/glut.lib")
#pragma comment(lib,"./glut/lib/glut32.lib")
//VC++创建的控制台程序,如果要使用MFC中的CString等类,就需要进行相关如下设置:
右键---项目-》设置-》常规-》MFC的使用改为“在共享DLL中使用MFC”
添加头文件#include <afxwin.h>,并且要放在其它头文件前,否则会出现如下错误
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
//-捕获消息和鼠标中键
void CTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptCurrent = point;
SetCapture(); //2
CView::OnLButtonDown(nFlags, point);
}
void CTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptCurrent= CPoint(0,0);
ReleaseCapture(); //2
CView::OnLButtonUp(nFlags, point);
}
void CTestView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (GetCapture()==this)
{
//Increment the object rotation angles
m_dXPos += (float)((point.x - m_ptCurrent.x)*2.0) ; // 因为glOrtho截取的是两倍的屏幕大小
m_dYPos += (float)((m_ptCurrent.y - point.y )*2.0);
InvalidateRect(NULL,FALSE);
m_ptCurrent=point;
};
CView::OnMouseMove(nFlags, point);
}
//按住中键后移动移动图形
void CTestView::OnMButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
/*
SetCapture函数向属于当前线程的给定窗口设置鼠标捕获。
一旦某一窗口捕获了鼠标,则不管光标是否在该窗口的边界内,所有鼠标输入都直接对着该窗口。
同时只能有一个窗口捕获鼠标。
若鼠标光标正在其他线程创建的窗口之上,则仅当按下了一个鼠标按钮时,系统才将鼠标输入指向给定的窗口。
*/
SetCapture(); //1
m_ptCurrent = point;
CView::OnMButtonDown(nFlags, point);
}
void CTestView::OnMButtonUp(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
//SetCapture 和 ReleaseCapture 必须成对出现
ReleaseCapture(); //1
CView::OnMButtonUp(nFlags, point);
}
BOOL CTestView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
m_dScale += (float)(0.01 *zDelta /120.0);
InvalidateRect(NULL,FALSE);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
BOOL CTestView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_CHAR && pMsg->wParam == VK_RETURN)
{
HWND hwnd1 = pEdit->m_hWnd; //((CEdit*)GetDlgItem(40000))->m_hWnd; //Edit框ID号
if (pMsg->hwnd == hwnd1)
{
CString str ;
pEdit->GetWindowText(str);
AfxMessageBox(str);
}
}
return CZoomView::PreTranslateMessage(pMsg);
}