My E-mail 用志趣吸引人;用感情留住人;用技術武裝人;用創新發展人;一切以人為本!

Leo LU

在Dialog中创建子框架(MFC)

1.所需对象:CScrollView view;    CFrameWnd childfram;    CDialog dlg;        子框架菜单ID  ID_CHILDFRAM
2.
对话框中创建框架指针: 
                
OnCreate函数中添加载入框架:

virtual BOOL LoadFrame( UINT nIDResource, DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, CWnd* pParentWnd = NULL, CCreateContext* pContext = NULL );

Parameters

nIDResource

The ID of shared resources associated with the frame window.

dwDefaultStyle

The frame’s style. Include the FWS_ADDTOTITLE style if you want the title bar to automatically display the name of the document represented in the window. 

pParentWnd

A pointer to the frame’s parent.

pContext

A pointer to a CCreateContext structure. This parameter can be NULL.

例如:

    CFrameWnd  *pFrame = new CChildFrame;

    pFrame->LoadFrame(IDR_CHILDFRAME,WS_OVERLAPPEDWINDOW, NULL,NULL);

或是

    CFrameWnd  *pFrame = new CChildFrame;

    CWnd * pparent = this;

    pFrame->LoadFrame(IDR_CHILDFRAME,WS_CHILD, pparent,NULL);

                            //显示框架

             pFrame ->MoveWindow(&rect);

    pFrame ->ShowWindow(SW_SHOW);

往框架中添加view

      在框架的OnCreate中添加如下代码

      CCreateContext context;

      context.m_pNewViewClass = RUNTIME_CLASS(/*ClassView*/);

      context.m_pCurrentFrame = this;

      context.m_pCurrentDoc = /*ClassDoc*/;

      context.m_pLastView = NULL;

      m_bkview = STATIC_DOWNCAST(CBKView,CreateView(&context));//将创建的view类转化为CBKView对象

      if(m_bkview!=NULL)

      {

             SetMenu(NULL);//设置子框架无菜单

             ShowWindow(SW_HIDE);

      }

      //删除子框架系统菜单中的一些子菜单项

      static UINT BadCommands[] = {

             SC_SIZE, SC_MOVE,

                    SC_MINIMIZE, SC_MAXIMIZE, SC_RESTORE,SC_CLOSE,0

      };

      CMenu *pSysMenu = GetSystemMenu(FALSE);

      if(pSysMenu!=NULL)

      for (int i=0; BadCommands[i]; i++) {

             pSysMenu->RemoveMenu(BadCommands[i], MF_BYCOMMAND);

      }

       系统菜单中的ID值:msdn路径 /Platform sdk documentation /user interface services /windows user interface/ user input/keyboard Accelerator / keyboard Accelerator Reference

     

PreCreateWindow中将右上角的系统按钮去掉,代码如下:

cs.style &= ~(WS_MINIMIZEBOX|WS_MAXIMIZEBOX |

             WS_CAPTION |WS_THICKFRAME);                     
 

posted on 2007-08-21 11:59  Leo LU  阅读(722)  评论(1)    收藏  举报

导航