vc++经典技巧总结(2)

2019-03-15 17:13

\}

也可以通过一个Check Button的点击来改变,在其点击响应函数里实现: m_button.EnableWindow(!m_button.IsWindowEnabled()); 其余控件属性的改变都如此。

5.\窗口的分割与停靠: 一、新建一个类CMySplitter,基类为CSplitterWnd 二、重载该类的OnMouseMove函数:

void CMySplitter::OnMouseMove(UINT nFlags, CPoint point) {

\限制切分条的运动范围。 \\

\\\\

\\}

三、 然后就可以跟一般的窗口分割那样去做了,if(point.x<228||point.x>600)这里的范围可以随你去设置了 ^_^,够简单吧。 四、切分窗口

在MaiFram.h建立切分条对象: protected:

CMySplitter m_wndSplitter; //切分窗口对象 //在MaiFram.cpp中实现窗口切分:

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,CCreateContext* pContext) {

\创建拆分器窗口

if (!m_wndSplitter.CreateStatic(this, 1, 2)) \

if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftView),CSize(228,100), pCon

text) ||!m_wndSplitter.CreateView(0,1, RUNTIME_CLASS(CDataEditView), CSize(100, 100), pContext)) \

\\\

\}

6. ①怎样在程序开始的时候让它最大化?

②vc++做出来的exe文件在窗体的右上方是没有最大化和最小化按钮的,怎样实现这一功能?

③如何在显示窗口时,使最大化按钮变灰?

①在App类里的C…App::InitInstance()中把m_pMainWnd->ShowWindow(SW_SHOW)改成m_pMainWnd->ShowWindow(SW_MAXIMIZE);

②在CreateWidnow时用WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX 风格. ③ 第一种方法:

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) {

if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE;

// TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs // disable the maxmini box cs.style &= ~WS_MAXIMIZEBOX; return TRUE; }

第二种方法:

CMenu *pMenu=AfxGetApp()->m_pMainWnd->GetSystemMenu(FALSE); int x=pMenu->GetMenuItemCount( ); UINT pID=pMenu->GetMenuItemID(x-1); pMenu->EnableMenuItem(pID, MF_DISABLED);

第三种方法:

ModifyStyle(WS_MAXIMIZEBOX, 0); 这个函数也可以是最大化按钮失效! 并且可以在程序中动态的改变窗口的风格

7. 更改属性页标题

void CProSheet::SetPageTitle(int nPage, int nImage, CString strTitle) {

TC_ITEM item;

//item.mask = TCIF_TEXT|TCIF_IMAGE; //设置图标+文字 item.mask = TCIF_IMAGE; //只设置图标 item.iImage = nImage;

// item.pszText = strTitle.GetBuffer(0); //设置文字 GetTabControl ()->SetItem (nPage, &item);

//要设置文字时就将上面2行有注释符的代码前的注释符去掉 }

8. 创建动态菜单

void CMainFrame::OnSelectState(NMTOOLBAR* pnmtb, LRESULT *plr) {

\

\\

\开始\\结束\\

\ \

\\//\\}

9.关于打印

1.要打印哪个视就

((CMainFrame*)AfxGetMainWnd())->m_wndSplitter.SetActivePane(...) //要打印的那个视对应的Pane

2.有一个单文档工程,文档窗口被切分:左视图由CTreeView 的派生类管理,右视图由CListView 的派生类CMyListView(其为风格为LVS_REPORT)管理,我想为右视图添加打印和打印预览,我在MyListView.cpp中添加了

ON_COMMAND(ID_FILE_PRINT,CListView::OnFilePrint)

ON_COMMAND(ID_FILE_PRINT_PREVIEW,CListView::OnFilePrintPreview)还有 BOOL CMyListView::OnPreparePrinting(CPrintInfo* pInfo) {

// TODO: call DoPreparePrinting to invoke the Print dialog box

// return CListView::OnPreparePrinting(pInfo); pInfo->SetMaxPage(2);

BOOL bret=DoPreparePrinting(pInfo); pInfo->m_nNumPreviewPages=2; return bret; }

3. 下面是从MSDN中摘出来的一段,是用来改变消息路由的。用了这段代码之后,CView中的消息(菜单,控件,子窗口)将先被CMyShape类来处理。不知道你要的是不是这样的效果。

// This example illustrates extending the framework's standard command // route from the view to objects managed by the view. This example // is from an object-oriented drawing application, similar to the // DRAWCLI sample application, which draws and edits \

BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) {

// Extend the framework's command route from the view to // the application-specific CMyShape that is currently selected

// in the view. m_pActiveShape is NULL if no shape object // is currently selected in the view. if ((m_pActiveShape != NULL)

&& m_pActiveShape->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE;

// If the object(s) in the extended command route don't handle // the command, then let the base class OnCmdMsg handle it. return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); }

// The command handler for ID_SHAPE_COLOR (menu command to change // the color of the currently selected shape) was added to

// the message map of CMyShape (note, not CMyView) using ClassWizard.

// The menu item will be automatically enabled or disabled, depending // on whether a CMyShape is currently selected in the view, that is, // depending on whether CMyView::m_pActiveView is NULL. It is not

// necessary to implement an ON_UPDATE_COMMAND_UI handler to enable // or disable the menu item.

BEGIN_MESSAGE_MAP(CMyShape, CCmdTarget) //{{AFX_MSG_MAP(CMyShape)

ON_COMMAND(ID_SHAPE_COLOR, OnShapeColor) //}}AFX_MSG_MAP END_MESSAGE_MAP()

如果你只是想调用OnFilePrint( )函数,可以试一试下面的代码,就和调用其它类中的函数一样。

CMDIFrameWnd *pFrame =

(CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;


vc++经典技巧总结(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《电动力学》知识点归纳及典型试题分析

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: