2008年(884)
分类: C/C++
2008-08-06 09:54:53
int CXindowView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; /* 创建左右两个视图 */ m_pForm = (CXindowForm *) okCreateView(RUNTIME_CLASS(CXindowForm), 1001); m_pList = (CXindowList *) okCreateView(RUNTIME_CLASS(CXindowList), 1002); m_pForm->m_pParent = this; return 0; }当窗口宽度<400时,会隐藏左边的CXindowForm视图:
void CXindowView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); int nFormWidth = 200; /* 如果窗口宽度<400, 就隐藏左视图 */ if(cx>400) { if(m_pForm->GetSafeHwnd()) m_pForm->ShowWindow(SW_SHOW); if(m_pForm->GetSafeHwnd()) m_pForm->MoveWindow(0,0,nFormWidth,cy); if(m_pList->GetSafeHwnd()) m_pList->ShowWindow(SW_SHOW); if(m_pList->GetSafeHwnd()) m_pList->MoveWindow(nFormWidth,0,cx-nFormWidth,cy); } else { if(m_pForm->GetSafeHwnd()) m_pForm->ShowWindow(SW_HIDE); if(m_pList->GetSafeHwnd()) m_pList->ShowWindow(SW_SHOW); if(m_pList->GetSafeHwnd()) m_pList->MoveWindow(0,0,cx,cy); } }其中左边的的CXindowForm视图中有个CXLabel控件“增加”,点击会产生WM_NOFITY消息,这样就能够响应了。
void CXindowForm::OnInitialUpdate() { CFormView::OnInitialUpdate(); /* 相当于CListCtrl::SetItemData(), 用于区别是哪个CXLabel */ m_add.SetCommand(1); } BOOL CXindowForm::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { LPNMHDR pnmh = (LPNMHDR) lParam; if(pnmh->code==NM_LINKCLICK) { CXLabel* pLabel = (CXLabel *)GetDlgItem(pnmh->idFrom); CString str; /* GetCommand() */ str.Format("d",pLabel->GetCommand()); AfxMessageBox(str); if(m_pParent->GetSafeHwnd()) { CListCtrl& listCtrl = ((CXindowView*)m_pParent)->m_pList->GetListCtrl(); int nCount = listCtrl.GetItemCount(); int nItem = listCtrl.InsertItem(nCount, "2003-8-15"); listCtrl.SetItemText(nItem, 1, "192.168.3.1"); listCtrl.SetItemText(nItem, 2, ""); listCtrl.SetItemText(nItem, 3, "编程"); } } return CFormView::OnNotify(wParam, lParam, pResult); }注:CXLabel控件来自CLabel类,增加了几个有效函数。 下载本文示例代码