一个显示树状目录的组合框类

发表于:2007-07-01来源:作者:点击数: 标签:
让组合框具有树状目录的显示功能,这个类比较有用的。 void CTreeCombo::DisplayTree() { CRect rect(0,0,200,200); CalculateDroppedRect (rect); m_Tree.InitDisplay (); m_Tree.SetWindowPos (wndNoTopMost, rect.left, rect.top, rect.Width (), rect.He




让组合框具有树状目录的显示功能,这个类比较有用的。
void CTreeCombo::DisplayTree()
{
CRect rect(0,0,200,200);

CalculateDroppedRect (&rect);

m_Tree.InitDisplay ();

m_Tree.SetWindowPos (&wndNoTopMost, rect.left, rect.top,
         rect.Width (), rect.Height (), SWP_SHOWWINDOW );

m_BeginPath = m_Tree.GetCurrentTreePath ();

SetDroppedState (TRUE);
}

BOOL CTreeCombo::CreateTree ()
{
CWnd* pParent = GetParent ();
if (!pParent && pParent->GetSafeHwnd ())
{
return FALSE;
}

CRect treeRect (0,0, m_ComboWidth, m_ComboHeight);

//can@#t have a control Id with WS_POPUP style
  if (! m_Tree.CreateEx ( 0,
          WC_TREEVIEW, NULL,
  WS_POPUP | WS_BORDER | TVS_SINGLEEXPAND | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS,
treeRect, pParent, 0, NULL))
{
return FALSE;
}


return TRUE;
}

BOOL CTreeCombo::CreateEdit ()
{
if (!m_DropDownButton.GetSafeHwnd ())
{
return FALSE;
}

CRect clientRect;
GetClientRect (&clientRect);

CRect btnRect;
m_DropDownButton.GetWindowRect (&btnRect);
ScreenToClient (&btnRect);

CRect editRect;
editRect.left = clientRect.left;
editRect.top = clientRect.top;
editRect.bottom = clientRect.bottom;
editRect.right = btnRect.left;


BOOL bCreate = m_Edit.Create (WS_CHILD | WS_TABSTOP | ES_LEFT | WS_VISIBLE | ES_WANTRETURN, editRect, this, IDC_COMBOTREE_EDIT);

if (bCreate)
{
CWnd* pParent = GetParent ();
CFont* pFont = pParent->GetFont ();
m_Edit.SetFont (pFont);
}

return bCreate;
}

原文转自:http://www.ltesting.net