본문 바로가기
VisualStudio.C++.C#/코딩팁,함수활용,단편

MFC. Tree Control with Columns.

by i.got.it 2020. 11. 17.

 

 

개요 

- CTreeCtrl 과 CListCtrl 특성이 모두 있는 컨트롤.

- 코드 프로젝트에서 유사한것들  5~6개 있는 것 중에서 도입 구현 작업시 가장 간결해 보여서 선택함. 

- 다른 소스코드들은 다들 VC++6.0 에서 작업된 오래된것인데 이 소스는 Visual C++2005에서 작업된 소스 배포중. 2019 변환 하여 작업시 디버깅 량이 적을것으로 여겨짐. 

- 컨트롤의 코아부분이 소스로 배포되므로 64비트 컴파일 가능. 

 

 

 

 

 

Known Issues

These issues were reported so far:

  • There is a problem with tooltips for now, so TVS_NOTOOLTIPS style is enabled for child tree control. Do not disable this style, or invalid tip will be displayed.
  • In the demo, when you check/uncheck some options that result in style modifications, control appearance may become incorrect. For example, vertical lines may become missing and so on. This is the problem in this demo, but this won't be a real problem in your project, because you usually won't change control's style on fly.
  • Under Windows Vista, vertical lines are drawn non-uniformly. That is not a very serious problem. 
    • 소스코드 수정하여 해결함. 아래 버그픽스부분.
  • Horizontal scroll bar is sometimes placed incorrectly when resizing control.

 

 

다운로드

- 사용법 설명도 같이 있음. 

 

Tree Control with Columns

Tree control with columns that can be easily used in MFC application

www.codeproject.com

 

컨트롤 코아 파일 있는것만 여기에 첨부해둠. 

CColumnTreeCtrl_src.zip
0.01MB

 

컨트롤 핵심 클래스 2개 

- 아래 처럼 2개의 클래스가 정의되어있고, CTreeCtrl 를 베이스 클래스로 하고 있고, 또 하나는 CStatic 을 베이스클래스로 하고 있다. 

// 파일 : ColumnTreeCtrl.h 에서 아래 2개의 클래스가 핵심임.

class CCustomTreeChildCtrl : public CTreeCtrl
{
	friend class CColumnTreeCtrl;

	DECLARE_DYNAMIC(CCustomTreeChildCtrl)

public:
....

};

class CColumnTreeCtrl : public CStatic
{
public:
	DECLARE_DYNCREATE(CColumnTreeCtrl)

..};

 

 

코드 적용방법. - 대화상자에 적용하는 경우.

 

Follow these simple steps to add CColumnTreeCtrl to your MFC dialog:

  1. Copy ColumnTreeCtrl.h and ColumnTreeCtrl.cpp file to your project folder. If you place these files to another place, you may encounter some problems with linking to resources, so don't do that.
  2. Copy TREEBTNS.bmp file to your res folder. This bitmap will be used to draw buttons of tree control in owner-drawn mode.
  3. Add TREEBTNS.bmp to project resources, set its name to IDB_TREEBTNS.
  4. Add Static control to your dialog.
  5. Change its id to, for example IDC_COLUMNTREE.
  6. Right-click the static and choose "Add variable..." in context menu.
  7. In the "Variable name" field, type "m_columnTree"
  8. In the header file of your dialog, Add "#include "ColumnTreeCtrl.h"" line;
  9. In the header file of your dialog, replace "CStatic m_columnTree;" to "CColumnTreeCtrl m_columnTree;";

 

구현예.

위 설명의 9까지 완료한 상태에서 (최종 멤버변수 m_columnTree 까지 생성),  대화상자 실행하면 아래 붉은 박스 처럼 보임. 즉, 비어 있는 컨트롤 영역이 백색으로 보이는 상태. 이후 멤버변수 m_columnTree 이용하여 트리 아이템 추가 컬럼 추가 등의 작업 진행한다. 

 

 

 

버그픽스 

- 버그내용 : 아래 실행샷보면 헤더 부분대비  그 아래 부분의 수직선들이 1픽셀 왼쪽으로 가있다. 

 

- 코드 수정 : 첫 컬럼인 경우에만 1픽셀  늘리는것으로 처리해두면 정상적으로 표현된다. 

 

void CColumnTreeCtrl::UpdateColumns()
{
	m_cxTotal = 0;

	HDITEM hditem;
	hditem.mask = HDI_WIDTH;
	int nCnt = m_Header.GetItemCount();
	
	ASSERT(nCnt<=MAX_COLUMN_COUNT);
	
    // 소스 원본것은 헤더대비 1픽셀 더 작게 표현되는 버그 해결위하여 원본 수정함. 
	int my_firstcolumn_width = 0;  // 추가됨 

	// get column widths from the header control
	for (int i=0; i<nCnt; i++)
	{
		if (m_Header.GetItem(i, &hditem))
		{
			my_firstcolumn_width = hditem.cxy; 

			if (i == 0) my_firstcolumn_width += 1; 

			m_cxTotal += m_arrColWidths[i] = my_firstcolumn_width; 
			if (i == 0)
				m_Tree.m_nFirstColumnWidth = my_firstcolumn_width;

/* 소스원본	이것대신 위 코드사용하면 수직선 줄 맞게 정상화됨.
            m_cxTotal += m_arrColWidths[i] = hditem.cxy;
			if (i==0)
				m_Tree.m_nFirstColumnWidth = hditem.cxy;
*/
		}
	}
	m_bHeaderChangesBlocked = TRUE;
	RepositionControls();
}

 

 

사용법 상세 

컬럼 추가/삭제 

// Inserts new column
int 
CColumnTreeCtrl::InsertColumn(
    int nCol,             // zero-based column index
    LPCTSTR lpszColumnHeading,     // column heading
    int nFormat=0,             // column formatting (as in CListViewCtrl)
    int nWidth=-1,             // column width
    int nSubItem=-1            // not used
    );

// Removes existing column
BOOL 
CColumnTreeCtrl::DeleteColumn(
    int nCol            // zero-based column index
    );
    
    
    
// Example

// insert two columns
m_columnTree.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 180);
m_columnTree.InsertColumn(1, _T("Type"), LVCFMT_LEFT, 80);

// remove last column
m_columnTree.DeleteColumn(1);

 

아이템 추가/삭제 

HTREEITEM hParent; // parent item

// add an item
HTREEITEM hItem = m_columnTree.GetTreeCtrl().InsertItem
			( _T("3.5\" Floppy (A:)"), hParent );

// remove 
m_columnTree.GetTreeCtrl().DeleteItem(hItem);

 

아이템 텍스트 get/set


// gets item text
CString 
CColumnTreeCtrl::GetItemText(
    HTREEITEM hItem,     // item handle
    int nSubItem        // zero-based subitem index
    ); 
// sets item text
void 
CColumnTreeCtrl::SetItemText(
    HTREEITEM hItem,     // item handle
    int nSubItem,         // zero-based subitem index
    LPCTSTR lpszText    // pointer to text buffer
    );
    
//Example
// set text for the first and the second subitems
m_columnTree.SetItemText(hRoot, 1, _T("Removable"));
m_columnTree.SetItemText(hRoot, 2, _T("FAT12"));

 

추가 상세 활용법은 https://www.codeproject.com/Articles/23692/Tree-Control-with-Columns  에서 확인. 

 

 

 

 

 

연관 

 

- 본 컨트롤의 베이스 클래스는 CTreeCtrl. 

 

MFC. CTreeCtrl. Tree Control . 트리 컨트롤 사용법.

개요. VC++ 에서 Tree Control사용법 정리. 기본 활용법. 1. 도구상자에서 Tree Control 을 대화상자에 배치하고 Tree Control 의 속성창에서 ID를 적절한것으로 설정. 2. 클래스 위저드 실행하여 멤버 변수추

igotit.tistory.com

 

 

 

MFC. CHeaderCtrl.

from : MS Provides the functionality of the Windows common header control. Syntax class CHeaderCtrl : public CWnd Members Public Constructors Public Methods A header control is a window that is usua..

igotit.tistory.com

 

 

- 트리 + 리스트 기능 컨트롤 모음. 

 

MFC. Tree List Control

개요 VC++ 에서 기본 제공되는 컨트롤인 CTreeCtrl, CListCtrl 의 특징이 모두 구비된 컨트롤. 입수처. A Tree List Control A Tree List Control www.codeproject.com  tree & list 다른 컨트롤들 CTreeGridCtr..

igotit.tistory.com

 

 

 

- 32비트 DLL 무료, 64비트 빌드가능한 소스는 유료.

 

MFC. DAPFOR. MFC Grid. 트리 리스트 컨트롤.

개요 -트리 와 리스트 동시 구현된 MFC컨트롤. -무료버전 DLL 은 32비트만 지원됨. 64비트에서 활용하려면 유료 소스제공되는것을 구매하여 64비트로 컴파일 해야함. 소스 가격 800달러 수준. Main featu

igotit.tistory.com

 

 

 

 

 

 


첫 등록 : 2020.11.17

최종 수정 : 

단축 주소 : https://igotit.tistory.com/2709

 


 

 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5