Share via


목록 뷰 컨트롤을 만드는 방법

이 항목에서는 목록 뷰 컨트롤을 만드는 방법을 보여 줍니다. 목록 뷰 컨트롤을 만들려면 CreateWindow 또는 CreateWindowEx 함수를 사용하고 WC_LISTVIEW 창 클래스를 지정합니다.

대화 상자 템플릿의 일부로 목록 뷰 컨트롤을 만들 수도 있습니다. 클래스 이름으로 WC_LISTVIEW를 지정해야 합니다. 목록 뷰 컨트롤을 대화 상자 템플릿의 일부로 사용하려면 대화 상자의 인스턴스를 만들기 전에 InitCommonControls 또는 InitCommonControlsEx를 호출해야 합니다.

알아야 하는 작업

기술

필수 구성 요소

  • C/C++
  • Windows 사용자 인터페이스 프로그래밍

지침

먼저 InitCommonControlsEx 함수를 호출하고 제공되는 INITCOMMONCONTROLSEX 구조체에서 ICC_LISTVIEW_CLASSES 비트를 지정하여 창 클래스를 등록합니다. 이렇게 하면 공용 컨트롤 DLL이 로드됩니다. 그런 다음 CreateWindow 또는 CreateWindowEx 함수를 사용하고 WC_LISTVIEW 창 클래스를 지정합니다.

참고

기본적으로 목록 뷰 컨트롤은 아이콘 제목 글꼴을 사용합니다. 그러나 WM_SETFONT 메시지를 사용하여 텍스트에 사용할 글꼴을 지정할 수 있습니다. 항목을 삽입하기 전에 이 메시지를 보내야 합니다. 컨트롤은 간격과 레이아웃을 결정하기 위해 WM_SETFONT 메시지에 지정된 글꼴 크기를 사용합니다. 각 항목의 글꼴을 사용자 지정할 수도 있습니다. 자세한 내용은 사용자 지정 그리기를 참조하세요.

 

다음 C++ 코드 예는 보고서 뷰에서 목록 뷰 컨트롤을 만듭니다.

// CreateListView: Creates a list-view control in report view.
// Returns the handle to the new control
// TO DO:  The calling procedure should determine whether the handle is NULL, in case 
// of an error in creation.
//
// HINST hInst: The global handle to the applicadtion instance.
// HWND  hWndParent: The handle to the control's parent window. 
//
HWND CreateListView (HWND hwndParent) 
{
    INITCOMMONCONTROLSEX icex;           // Structure for control initialization.
    icex.dwICC = ICC_LISTVIEW_CLASSES;
    InitCommonControlsEx(&icex);

    RECT rcClient;                       // The parent window's client area.

    GetClientRect (hwndParent, &rcClient); 

    // Create the list-view window in report view with label editing enabled.
    HWND hWndListView = CreateWindow(WC_LISTVIEW, 
                                     L"",
                                     WS_CHILD | LVS_REPORT | LVS_EDITLABELS,
                                     0, 0,
                                     rcClient.right - rcClient.left,
                                     rcClient.bottom - rcClient.top,
                                     hwndParent,
                                     (HMENU)IDM_CODE_SAMPLES,
                                     g_hInst,
                                     NULL); 

    return (hWndListView);
}

일반적으로 목록 뷰 애플리케이션을 사용하면 사용자가 한 보기에서 다른 보기로 변경할 수 있습니다.

다음 C++ 코드 예는 목록 뷰의 창 스타일을 변경하여 보기를 변경합니다.

// SetView: Sets a list-view's window style to change the view.
// hWndListView: A handle to the list-view control. 
// dwView:       A value specifying the new view style.
//
VOID SetView(HWND hWndListView, DWORD dwView) 
{ 
    // Retrieve the current window style. 
    DWORD dwStyle = GetWindowLong(hWndListView, GWL_STYLE); 
    
    // Set the window style only if the view bits changed.
    if ((dwStyle & LVS_TYPEMASK) != dwView) 
    {
        SetWindowLong(hWndListView,
                      GWL_STYLE,
                      (dwStyle & ~LVS_TYPEMASK) | dwView);
    }               // Logical OR'ing of dwView with the result of 
}                   // a bitwise AND between dwStyle and 
                    // the Unary complenent of LVS_TYPEMASK.

목록 뷰 컨트롤 참조

목록 뷰 컨트롤 정보

목록 뷰 컨트롤 사용