MFC 参考代码....

            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);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值