mfc摘录

来源:互联网 发布:金山毒霸网络卸载密码 编辑:程序博客网 时间:2024/05/29 09:15

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 herear<<recno<<stuname;}else{// TODO: add loading code herear>>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);





原创粉丝点击