• <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>

            振動(dòng)理論

            我的C++實(shí)現(xiàn)之路

            VC++窗口分割與通信實(shí)例

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

            2.在 CMainFrame中增加變量

            public:
               CSplitterWnd m_wndSplitter;

            3.增加左右視圖類(lèi),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()函數(shù)

            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.插入一個(gè)對(duì)話框,假如一個(gè)CEdit控件,控件名為IDC_EDIT1,類(lèi)名為CTestDlg;

            6.在CLeftTreeView中增加函數(shù)

            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() 函數(shù)中添加代碼:

            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.增加消息響應(yīng)函數(shù):使用ClassWizard增加消息響應(yīng)函數(shù)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頁(yè)的建立
             {
              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.編譯運(yùn)行!

            posted on 2007-05-24 08:19 唯月釋?xiě)?/a> 閱讀(4185) 評(píng)論(6)  編輯 收藏 引用

            Feedback

            # re: VC++窗口分割與通信實(shí)例 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.

            怎么回事?  回復(fù)  更多評(píng)論   

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

            找到原因了是我加錯(cuò)了這個(gè)響應(yīng)IsSelected  回復(fù)  更多評(píng)論   

            # re: VC++窗口分割與通信實(shí)例[未登錄](méi) 2007-11-27 00:16 th

            你好,CTestDlg應(yīng)該顯示在 VCRightView里面,但我的為什么顯示在CMainFrame的坐標(biāo)(0。0)位置?請(qǐng)指點(diǎn)。  回復(fù)  更多評(píng)論   

            # re: VC++窗口分割與通信實(shí)例[未登錄](méi) 2007-11-27 11:40 th

            找到原因了 我的CTestDlg對(duì)話框?qū)傩栽O(shè)置問(wèn)題。  回復(fù)  更多評(píng)論   

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

            謝謝你,很感謝  回復(fù)  更多評(píng)論   

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

            怎么我的老是出錯(cuò)啊?我用的是VS2008  回復(fù)  更多評(píng)論   



            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            My Links

            Blog Stats

            常用鏈接

            留言簿(5)

            隨筆檔案

            文章檔案

            My sohu blog

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            精品熟女少妇a∨免费久久| 久久久无码精品午夜| 久久精品蜜芽亚洲国产AV| 精品国产一区二区三区久久| 97久久精品午夜一区二区| 久久综合狠狠综合久久97色| 亚洲精品无码成人片久久| 99久久国产综合精品五月天喷水| 欧美日韩精品久久久久| 久久精品成人免费国产片小草| 亚洲欧洲日产国码无码久久99| 99久久精品久久久久久清纯| 亚洲精品国产字幕久久不卡| 久久99精品国产麻豆婷婷| 久久精品国产99久久久| 青青草原综合久久大伊人| 久久久久亚洲?V成人无码| 国产精品久久波多野结衣| 亚洲中文精品久久久久久不卡| 欧美日韩精品久久久免费观看| 国产人久久人人人人爽| 性色欲网站人妻丰满中文久久不卡| 91精品国产高清久久久久久91| 色偷偷偷久久伊人大杳蕉| 久久精品国产日本波多野结衣| 亚洲综合久久夜AV | 久久久久亚洲AV无码去区首| 久久青草国产精品一区| 久久精品这里热有精品| 久久er国产精品免费观看2| 久久棈精品久久久久久噜噜| 亚洲欧美日韩中文久久| 无码专区久久综合久中文字幕 | 国产午夜免费高清久久影院 | 亚洲色大成网站www久久九| 一本色综合久久| 99久久伊人精品综合观看| 色综合久久久久综合99| 国产婷婷成人久久Av免费高清| 亚洲中文久久精品无码ww16| 国内精品久久久久影院优|