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

MFC. CListCtrl. 리스트 컨트롤.

by i.got.it 2020. 9. 24.

 

 

 

InsertColumn 

int InsertColumn(
    int nCol,
    const LVCOLUMN* pColumn);

int InsertColumn(
    int nCol,
    LPCTSTR lpszColumnHeading,
    int nFormat = LVCFMT_LEFT,
    int nWidth = -1,
    int nSubItem = -1);

 

 

 

InsertItem 

int InsertItem(const LVITEM* pItem);

int InsertItem(
    int nItem,
    LPCTSTR lpszItem);

int InsertItem(
    int nItem,
    LPCTSTR lpszItem,
    int nImage);

int InsertItem(
    UINT nMask,
    int nItem,
    LPCTSTR lpszItem,
    UINT nState,
    UINT nStateMask,
    int nImage,
    LPARAM lParam);

 

InsertItem example. 

 CString strText;
        int nColumnCount = m_myListCtrl.GetHeaderCtrl()->GetItemCount();

        // Insert 10 items in the list view control.
        for (int i = 0; i < 10; i++)
        {
            strText.Format(TEXT("item %d"), i);

            // Insert the item, select every other item.
            m_myListCtrl.InsertItem(LVIF_TEXT | LVIF_STATE, i, strText,
                (i % 2) == 0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0);

            // Initialize the text of the subitems.
            for (int j = 1; j < nColumnCount; j++)
            {
                strText.Format(TEXT("sub-item %d %d"), i, j);
                m_myListCtrl.SetItemText(i, j, strText);
            }
        }

 

 

 

 

 

CListCtrl supports callback items 

- 이미지, 아이템이름 문자열 등을 컨트롤단에 저장하지 않고, 응용앱(컨트롤을 활용하는 측)에 있는것을 사용하게 하는것. 

By default, the list view control is responsible for storing an item's icon and text attributes. However, in addition to these item types, class CListCtrl supports "callback items." A "callback item" is a list view item for which the application — rather than the control — stores the text, icon, or both. A callback mask is used to specify which item attributes (text and/or icon) are supplied by the application. If an application uses callback items, it must be able to supply the text and/or icon attributes on demand. Callback items are helpful when your application already maintains some of this information. For more information, see Using CListCtrl: Callback Items and the Callback Mask.

 

 

from : 

 

CListCtrl Class

CListCtrl Class In this article --> Encapsulates the functionality of a "list view control," which displays a collection of items each consisting of an icon (from an image list) and a label. Syntax class CListCtrl : public CWnd Members Public Constructors

docs.microsoft.com

 

CListCtrl 에서 콜백 아이템 설정한 경우 응용앱에서 코드 추가할 사항. 

 

// CLIstCtrl 에 콜백아이템 설정되면 , 
// 컨트롤측에서 해당 표현요구되는 경우  
// 메시지 LVN_GETDISPINFO 송신하므로 응용앱측에서는 아래처럼 메시지핸들러추가한다. 


BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl)
	//{{AFX_MSG_MAP(CMyListCtrl)
	ON_NOTIFY_REFLECT(LVN_GETDISPINFO, OnGetDispInfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

 

 

 

text 콜백예.  

 

www.codeproject.com/Articles/70/Using-text-callbacks-in-ListView-Controls

 

Using text callbacks in ListView Controls

Shows how to use text callbacks in list controls

www.codeproject.com

방대한 리스트 데이터 있는 경우 메모리 절감위하여 콜백 개념 적용한것. 

응용측은 컨트롤에서 메시지 LVN_GETDISPINFO 송신한것을 메시지 핸들러내에서 처리하면서 응용측 보유한 정보를 를 컨트롤에 설정하는식. 

 

 

 

CListCtrl 아이템 마우스 이벤트 

- NM_CLICK : 리스트컨트롤의 아이템을 왼 마우스 클릭.(클릭의 의미 ; 왼마우스 눌렀다 놓은것) 

- NM_DBCLICK : 왼마우스 더블 클릭

- NM_RCLICK : 우 마우스 클릭.

- NM_RDBCLICK : 우마우스 더블 클릭. 

 

 

코드예. 


/*
리스트 컨트롤 좌클릭시 선택된 아이템 처리.. 
*/
void CCyMetaMainUI_UITDlg::OnNMClickLcCymetaeachart(NMHDR* pNMHDR, LRESULT* pResult)
{
	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);

	int index = pNMItemActivate->iItem; // 클릭한 것의 아이템 인덱스 받음. 

	if (index >= 0 && index < m_LC_CyMetaEaChart.GetItemCount()) 
	{	
		m_ihwnd_EAChartSelected = _ttoi(m_LC_CyMetaEaChart.GetItemText(index,0)); 
		m_cstSymbol_EAChartSelected = m_LC_CyMetaEaChart.GetItemText(index, 1); 

		// 선택한것 표현. 
		SetDlgItemTextW(IDC_STATIC_SELECTED_ITEM, m_cstSymbol_EAChartSelected);
	}

	// TODO: Add your control notification handler code here
	*pResult = 0;
}

 

 

 

 

 

 

 

 

CListCtrl 의 드래그 드롭

 

 

리스트컨트롤의 Header Items 에서의 드래그 드롭 

- 헤더아이템의 순서변경을 드래그 드롭으로 구현가능. 

- 스타일 지정 : HDS_DRAGDROP 

- 드래그 중의  이미지 설정 : CHeaderCtrl::CreateDragImage 

 - - 드래그 시작시점에 이미지 설정한다.

- 연관 이벤트 

  - - HDN_BEGINDRAG : 드래그 시작. 

  - - HDN_ENDDRAG : 드래그 끝.

 

 

리스트컨트롤의 일반 아이템(행)에서의 드래그 드롭. 

- 아이템을 마우스 클릭하여 드래그 시킬때 사용.

- 드래그중의 이미지 설정 : CListCtrl::CreateDragImage

 - - 드래그 시작시점에 이미지 설정한다.

- 연관 이벤트.

 - - LVN_BEGINDRAG : 드래그 시작. 

 

 

드래그 드롭 구현시 위 요소와 함께 드래그 시작한것의 마우스로 이동 중에는  WM_MOUSEMOVE 이벤트 활용, 드롭 판단은 WM_LBUTTONUP 이벤트이용한다. 

또한, 마우스가 활성 윈도우 영역을 벗어난 경우에도  마우스 이벤트 수신 가능하게 하기 위해서 드래그 시작시점에 SetCapture 함수호출하여 마우스 이벤트를 받을 수 있게한다. 

 

 

C++. Win32 API. MFC. SetCapture(), ReleaseCapture()

SetCapture() , ReleaseCapture()는 win32 api , MFC CWnd 멤버함수 모두 제공됨. 기능 : 마우스가 활성 윈도우 영역을 벗어난 경우에도 마우스 이벤트 받을 수 있게 하는것. HWND SetCapture( HWND hWnd ); Sets..

igotit.tistory.com

 

 

드래그 드롭 구현예제. 

www.codeproject.com/Articles/1951/Drag-and-Drop-between-and-within-a-CListCtrl

 

Drag and Drop between and within a CListCtrl

An article showing how to drag and drop items between CListCtrls or reorder items within a CListCtrl

www.codeproject.com

 

 


첫 등록 : 2020.09.24

최종 수정 : 

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

 


 

 

 

 

 

 

 

 

 

 

댓글



 

비트코인




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