• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            振動理論

            我的C++實現之路

            VC++窗口分割與通信實例

            1.使用MFC建立一個SDI(基類為View),工程名為SplitWndDemo;

            2.在 CMainFrame中增加變量

            public:
               CSplitterWnd m_wndSplitter;

            3.增加左右視圖類,CLeftTreeView:public: CTreeView,如下:

            #include <afxcview.h>
            /////////////////////////////////////////////////////////////////////////////
            // CLeftTreeView view
            #include "TestDlg.h"
            class CLeftTreeView : public CTreeView

            #include "TestDlg.h"
            /////////////////////////////////////////////////////////////////////////////
            // CRightView view

            CRightView : public CView如下:

            class CRightView : public CView

            4.重載CMainFrame的OnCreateClient()函數

            BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
            {
             // TODO: Add your specialized code here and/or call the base class
             // create splitter window
             if (!m_wndSplitter.CreateStatic(this, 1, 2))
              return FALSE;

             if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftTreeView),CSize(200, 100), pContext) ||
              !m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(100, 100), pContext))
             {
              m_wndSplitter.DestroyWindow();
              return FALSE;
             }
             //set the target for mapped messages
            // ((CFormLeft*)m_wndSplitter.GetPane(0,0))->SetTarget(m_wndSplitter.GetPane(0,1));

             return TRUE;
            }

            5.插入一個對話框,假如一個CEdit控件,控件名為IDC_EDIT1,類名為CTestDlg;

            6.在CLeftTreeView中增加函數

            HTREEITEM FindItem(long lItemData);

            HTREEITEM CLeftTreeView::FindItem(long lItemData)
            {
             // the tree object
             CTreeCtrl   &tTree = this->GetTreeCtrl ();
             // the current item
                HTREEITEM    tiItem= tTree.GetNextItem(TVGN_ROOT,TVGN_ROOT);
             long      lCurrentData;
             
                while (tiItem)
             {
              tTree.Expand(tiItem,TVE_EXPAND);
              
              lCurrentData = (long)tTree.GetItemData(tiItem);
              
              if( lCurrentData == lItemData )
               return tiItem;
              tiItem= tTree.GetNextItem(tiItem,TVGN_NEXTVISIBLE);
             }
             
             return NULL;
             
            }

            7.在CLeftTreeView::OnInitialUpdate() 函數中添加代碼:

            void CLeftTreeView::OnInitialUpdate()
            {
             CTreeCtrl   &tTree = this->GetTreeCtrl ();
             
             // variables to compute new items
             long  lItemTitle;
             CString  sItemTitle;
             char  cItemTitle[10];
             int   iItemSize;
             int   iCptr;
             
             // item created
             HTREEITEM tiTestNode;
             HTREEITEM tiParentNode;
             
             CTreeView::OnInitialUpdate();
             
             // update the tree style
                tTree.ModifyStyle ( 0, TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT);
             
               
             // Add items to the tree
             for(lItemTitle=1; lItemTitle<=999; lItemTitle+=2)
             {
              ltoa(lItemTitle,cItemTitle,10);
              sItemTitle = "";
              iItemSize= strlen(cItemTitle);
              
              sItemTitle=sItemTitle+cItemTitle[0];
              
              for(iCptr=1; iCptr<iItemSize; iCptr++)
              {
               sItemTitle=sItemTitle+"."+cItemTitle[iCptr];
              }
              // insert the node
              tiParentNode = FindItem((long)(lItemTitle/10));
              //for the first level nodes
              if((long)(lItemTitle/10)==0)
              {
               tiTestNode = tTree.InsertItem(sItemTitle);
               tTree.SetItemData(tiTestNode,lItemTitle);
              }
              //for the other nodes
              if( tiParentNode )
              {
               tiTestNode = tTree.InsertItem(sItemTitle, tiParentNode);
               tTree.SetItemData(tiTestNode,lItemTitle);
              }
             }
            }

            8.增加消息響應函數:使用ClassWizard增加消息響應函數CLeftTreeView::OnSelchanged()

            void CLeftTreeView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
            {
             NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
             // TODO: Add your control notification handler code here
             TVITEM item = pNMTreeView->itemNew;
             CString strCurSelItemText = this->GetTreeCtrl().GetItemText(item.hItem); 
             CMainFrame * pMainFrm = (CMainFrame*)AfxGetMainWnd();
             CRightView * pRightView = (CRightView *)pMainFrm->m_wndSplitter.GetPane(0,1);
             if(pRightView->m_TestDlg.GetSafeHwnd())
             {
              pRightView->m_TestDlg.SetDlgItemText(IDC_EDIT1,strCurSelItemText);
             }
             *pResult = 0;
            }

            9.在CRightView增加變量CTestDlg m_TestDlg;

            在 CRightView::OnInitialUpdate() 中添加代碼:

            void CRightView::OnInitialUpdate()
            {
             CView::OnInitialUpdate();
             // TODO: Add your specialized code here and/or call the base class 
             if(!m_TestDlg.GetSafeHwnd()) //第一次初始化m_Tab 控件和page頁的建立
             {
              m_TestDlg.Create(IDD_TestDlg,this);
              m_TestDlg.ShowWindow(SW_SHOW);
             } 
             
            }
            10.在vCRightView::OnSize()中添加代碼:

            oid CRightView::OnSize(UINT nType, int cx, int cy)
            {
             CView::OnSize(nType, cx, cy);
             // 讓窗體覆蓋在上面。 
             if(m_TestDlg.GetSafeHwnd())
             {
              CRect rect;
              GetClientRect(rect);
              m_TestDlg.MoveWindow(rect);
              m_TestDlg.ShowWindow(SW_SHOW);
             }
             // TODO: Add your message handler code here
            }

            11.編譯運行!

            posted on 2007-05-24 08:19 唯月釋懷 閱讀(4174) 評論(6)  編輯 收藏 引用

            Feedback

            # re: VC++窗口分割與通信實例 2007-10-06 10:13 aa

            LeftTreeView.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall CLeftTreeView::IsSelected(class CObject const *)const " (?IsSelected@CLeftTreeView@@UBEHPBVCObject@@@Z)
            Release/SplitWndDemo.exe : fatal error LNK1120: 1 unresolved externals
            Error executing link.exe.

            怎么回事?  回復  更多評論   

            # re: VC++窗口分割與通信實例 2007-10-06 10:26 aa

            找到原因了是我加錯了這個響應IsSelected  回復  更多評論   

            # re: VC++窗口分割與通信實例[未登錄] 2007-11-27 00:16 th

            你好,CTestDlg應該顯示在 VCRightView里面,但我的為什么顯示在CMainFrame的坐標(0。0)位置?請指點。  回復  更多評論   

            # re: VC++窗口分割與通信實例[未登錄] 2007-11-27 11:40 th

            找到原因了 我的CTestDlg對話框屬性設置問題。  回復  更多評論   

            # re: VC++窗口分割與通信實例 2009-02-24 23:50 LOVE VC++

            謝謝你,很感謝  回復  更多評論   

            # re: VC++窗口分割與通信實例 2011-08-30 10:48 mirror

            怎么我的老是出錯啊?我用的是VS2008  回復  更多評論   


            My Links

            Blog Stats

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章檔案

            My sohu blog

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            夜夜亚洲天天久久| 成人久久久观看免费毛片| 久久人搡人人玩人妻精品首页| 久久精品亚洲精品国产欧美| 久久婷婷色综合一区二区| 久久精品国产99久久久古代| 精品久久久久久久久中文字幕| 精品久久人人做人人爽综合| 久久精品卫校国产小美女| 成人久久久观看免费毛片| 亚洲第一永久AV网站久久精品男人的天堂AV| 国产成人综合久久精品红| 久久国产精品99精品国产987| 人妻少妇精品久久| 国产成人久久精品区一区二区| 久久综合精品国产一区二区三区 | 日韩av无码久久精品免费| 国产69精品久久久久99| 久久婷婷五月综合97色| 久久综合久久综合亚洲| www亚洲欲色成人久久精品| 久久av无码专区亚洲av桃花岛| 中文成人无码精品久久久不卡| 99久久精品无码一区二区毛片 | 国产精品久久新婚兰兰| 久久精品国产亚洲av瑜伽| 国产精品99久久精品| 久久亚洲私人国产精品vA | 精品无码久久久久久尤物| 亚洲伊人久久综合影院| 9191精品国产免费久久| 久久福利青草精品资源站| 潮喷大喷水系列无码久久精品| 亚洲国产精品无码久久久蜜芽| 一本色道久久综合| 久久精品无码一区二区WWW| 伊人久久大香线蕉AV一区二区| 2019久久久高清456| 久久精品国产清自在天天线| 久久婷婷五月综合成人D啪| 久久青青色综合|