当我们按树控件中的空格键时如何避免复选框?

时间:2014-10-13 15:09:56

标签: visual-c++ mfc

我有一个树形控件,最初我在OnInitDialog中设置了它的样式,如下所示,

BOOL OnInitDialog()
{

  CPropertyPage::OnInitDialog();
//Setting Treecontrol with TVS_CHECKBOXES style

  HWND m_hTreeWnd = ::GetDlgItem(m_hWnd,IDC_TREE);
  DWORD dwStyle =  GetWindowLong(m_hTreeWnd,GWL_STYLE);
  dwStyle |= (TVS_CHECKBOXES);
  SetWindowLongPtr(m_hTreeWnd,GWL_STYLE,dwStyle);//CTreeCtrl m_hTreeWnd;



//Now I had initialized the tree control and I am want only few items of the tree to have 
  //checkboxes,In order to achieve that I did it as follows(Removing checkboxes where not required)

  tvInsertItem.hParent = NULL;
  tvInsertItem.hInsertAfter = TVI_ROOT;
  tvInsertItem.item.mask = TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  tvInsertItem.item.pszText = L"Name"
  hParentItemHandle = m_TreeCtrl.InsertItem(&tvInsertItem);

  //Removal of checkboxes for the above item
  tvItem.hItem = hParentItemHandle;
  tvItem.mask = TVIF_TEXT|TVIF_STATE|TVIF_SELECTEDIMAGE;
  tvItem.stateMask = TVIS_STATEIMAGEMASK;
  tvItem.state = 0;
  tvItem.pszText = szCommonModel;
  m_TreeCtrl.SetItem(&tvItem);


}

一切都很好我移除了复选框,其中不需要任何节点。并且有必要的复选框。

突然间我注意到了这个问题,即在树形控件中选择了一个没有复选框的项目后,现在是 我按"空格键"然后一个复选框将附加到该项目。

我想在按空格键时避开复选框。 为了避免复选框我尝试了这个但是没有用。

BOOL CTreeControlDlg::OnTvnItemChangingTree(UINT i,NMHDR *pNMHDR, LRESULT *pResult)
{
    NMTVITEMCHANGE *pNMTVItemChange = reinterpret_cast<NMTVITEMCHANGE *>(pNMHDR);

    HTREEITEM hTree = pNMTVItemChange->hItem;
    UINT ChangItem = pNMTVItemChange->uStateNew;
    UINT ChangItem1 = pNMTVItemChange->uStateOld;
    UINT ItemState = m_TreeCtrl.GetItemState(hTree, TVIS_STATEIMAGEMASK);
    if(98 == ItemState)//98 is the thing I observed while debugging this is not correct I know.
        return FALSE;


    return TRUE;
}

我有点困惑我们如何获得状态图像掩码TVIS_STATEIMGAEMASK以及我们如何检查该项目是否具有此掩码。

任何人都可以建议我一种方法来实现这一点。

0 个答案:

没有答案