Tree-View Control 을 이용해서 item 의 check 입력을 받거나 상태를 보여주는 경우가 있습니다. 간단하게 Ctrl 처럼 이용할 수 있는 편의성 때문에 자주 사용하게 되는데 속성중에 체크박스를 아이템 앞에 표시하고 사용하기 위해서 TVS_CHECKBOXES 속성을 지정해야 합니다.

TVS_CHECKBOXES 가 지정된 상태에서 Dialog 의 초기화 루틴(MFC에서 OnInitDialog, CTreeCtrl)에서 이 Item 을 아무리 check 되도록 설정하더라도 실제 보여질때는 여전히 uncheck 상태로 보이게 됩니다.

실제로 Tree-View Control 의 초기화 시점에 check를 설정을 할 수 없습니다.
MSDN에 다음과 같이 나와있습니다.

"If you want to use this style, you must set the TVS_CHECKBOXES style with SetWindowLong after you create the treeview control, and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues."

즉, Tree-View Control 을 사용하기 위해서는 사용전에 아래와 같이 TVS_CHECKBOXES 속성을 해제하고 다시 설정하는 작업이 선행되어야 합니다.

// Win32 API ----------------------------------------------------------------------------------------------------

DWORD dwStyle = ::GetWindowLong( hTree, GWL_STYLE );
::SetWindowLong( hTree, GWL_STYLE, dwStyle ^ TVS_CHECKBOXES );
::SetWindowLong( hTree, GWL_STYLE, dwStyle | TVS_CHECKBOXES );

// MFC ---------------------------------------------------------------------------------------------------------

m_Tree.ModifyStyle( TVS_CHECKBOXES, 0 );
m_Tree.ModifyStyle( 0, TVS_CHECKBOXES );

'Technical Report' 카테고리의 다른 글

winapi - 한글 영문 전환  (0) 2011.07.14
DEBUG 용 CONSOLE WINDOW 띄우기  (0) 2011.05.17
배치파일  (0) 2009.07.30
Visual Studio C/C++ Compiler Option  (0) 2009.07.20
console 에서 wprintf 함수로 한글 출력  (0) 2009.07.20