2009/09/30

CTreeCtrl 의 CheckBox 상태 변경 이벤트 작성하기

#define WM_USER_TREE_CHANGE_CHECK        WM_USER + 100

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TREE, m_ctrlTree);
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
:
ON_NOTIFY(NM_CLICK, IDC_TREE, &CTestDlg::OnNMClickTree)
ON_MESSAGE( WM_USER_TREE_CHANGE_CHECK, &CTestDlg::OnTreeChangeCheck )
:
END_MESSAGE_MAP()

void CTestDlg::OnNMClickTree(NMHDR *pNMHDR, LRESULT *pResult)
{
DWORD pos = ::GetMessagePos();
CPoint point( LOWORD( pos ), HIWORD( pos ) );

m_ctrlTree.ScreenToClient( &point );

UINT nFlags = 0;
HTREEITEM hItem = m_ctrlTree.HitTest( point, &nFlags );

if ( hItem )
{
if ( nFlags & TVHT_ONITEMSTATEICON )
{
PostMessage( WM_USER_TREE_CHANGE_CHECK, (WPARAM)pNMHDR->hwndFrom, (LPARAM)hItem );
}
}

*pResult = 0;
}

LRESULT CTestDlg::OnTreeChangeCheck( WPARAM wParam, LPARAM lParam )
{
HTREEITEM hItem = (HTREEITEM)lParam;

HTREEITEM hParent = m_ctrlTree.GetParentItem( hItem );
if ( hParent )
{
BOOL bCheck = m_ctrlTree.GetCheck( hItem );

m_ctrlTree.SetCheck( hParent, bCheck );
}

return 0;
}

Original Post : http://neodreamer-dev.tistory.com/330

No comments :

Post a Comment