Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8182726
  • 博文数量: 1227
  • 博客积分: 10026
  • 博客等级: 上将
  • 技术积分: 20273
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-16 12:40
文章分类

全部博文(1227)

文章存档

2010年(1)

2008年(1226)

我的朋友

分类: C/C++

2008-03-10 19:48:10

当我们使用Windows资源管理器(Exporlor)时, 看到左边的视图能够显示所选目标的相关信息,比较好用。
本例是一个简单的Web视图界面示例,不过左边不是一个Web视图,而是一个FormView。界面如下图所示:


图一 程序运行画面

本例是最简单的SDI工程,在View中创建了两个View:
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类,增加了几个有效函数。
阅读(1568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~