mfc摘录

1.右键响应函数,弹出消息框响应:

AfxMessageBox("right mouse key!");

2.右键响应函数,在鼠标点击处显示文本:

void CEx3_3View::OnRButtonDown(UINT nFlags, CPoint point)
{
    // TODO: Add your message handler code here and/or call default
    CClientDC dc(this);
    dc.TextOut(point.x,point.y,"helllo");
    CView::OnRButtonDown(nFlags, point);
}

3.在文档类中定义变量recno和stuname,在视图类ondraw函数中实现输出:

void CEx3_3View::OnDraw(CDC* pDC)
{
    CEx3_3Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    CString stuinfo;
    stuinfo.Format("%d::%s",pDoc->recno,pDoc->stuname);
    pDC->TextOut(250,250,stuinfo);
}

4.当按向下箭头键时,能使recno加1,按向下键时,能使recno-1,并在视图上显示出来:

void CEx3_3View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: Add your message handler code here and/or call default
    CEx3_3Doc* pDoc=GetDocument();
    if(nChar==VK_UP){
        pDoc->recno++;
        Invalidate();
    }
    else if(nChar==VK_DOWN){
        pDoc->recno--;
        Invalidate();
    }
    CView::OnKeyDown(nChar, nRepCnt, nFlags);
}


5.保存文档对象的内容到一个磁盘文件中,也能从磁盘文件中取出内容到文档对象:

void CEx3_3Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		ar<<recno<<stuname;
	}
	else
	{
		// TODO: add loading code here
		ar>>recno>>stuname;
	}
}

5.如何创建工具栏窗口?

工具栏的创建使用了从CWnd类继承的创建函数Create()或者CreateEx(),创建窗口成功,将返回TRUE,否则返回FALSE。


6.如何加载工具栏按钮?

m_wndToolBar.LoadToolBar(IDR_MAINFRAME),加载成功将返回TRUE,否则返回FALSE。


7.如何设置工具栏停靠特性?

m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);


8.如何设置框架窗口的子窗口停靠特性?

EnableDocking(CBRS_ALIGN_ANY);


9.指定工具条停靠在框架窗口的具体位置

DockControlBar(&m_wndToolBar);

10.CWnd::IsWindowVisible()函数返回工具栏窗口是否可见的信息:

m_myToolBar.ShowWindow(m_myToolBar.IsWindowVisible()?SW_HIDE:SW_SHOW);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值