希望高手帮我具体讲解ListView的用法,希望有实例。资料也行,用C语言实现。急用,谢谢。

解决方案 »

  1.   

    查 MSDN 或者 google 就行http://msdn.microsoft.com/en-us/library/bb774736(v=vs.85).aspx
      

  2.   

    代码可能有些宏定义需要自己补,或者自己 google 一个完整例子
    // 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);
    }// InitListViewColumns: Adds columns to a list-view control.
    // hWndListView:        Handle to the list-view control. 
    // Returns TRUE if successful, and FALSE otherwise. 
    BOOL InitListViewColumns(HWND hWndListView) 

        WCHAR szText[256];     // Temporary buffer.
        LVCOLUMN lvc;
        int iCol;    // Initialize the LVCOLUMN structure.
        // The mask specifies that the format, width, text,
        // and subitem members of the structure are valid.
        lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;    // Add the columns.
        for (iCol = 0; iCol < C_COLUMNS; iCol++)
        {
            lvc.iSubItem = iCol;
            lvc.pszText = szText;
            lvc.cx = 100;               // Width of column in pixels.        if ( iCol < 2 )
                lvc.fmt = LVCFMT_LEFT;  // Left-aligned column.
            else
                lvc.fmt = LVCFMT_RIGHT; // Right-aligned column.        // Load the names of the column headings from the string resources.
            LoadString(g_hInst,
                       IDS_FIRSTCOLUMN + iCol,
                       szText,
                       sizeof(szText)/sizeof(szText[0]));        // Insert the columns into the list view.
            if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1)
                return FALSE;
        }
        
        return TRUE;
    } // InsertListViewItems: Inserts items into a list view. 
    // hWndListView:        Handle to the list-view control.
    // cItems:              Number of items to insert.
    // Returns TRUE if successful, and FALSE otherwise.
    BOOL InsertListViewItems(HWND hWndListView, int cItems)
    {
        LVITEM lvI;    // Initialize LVITEM members that are common to all items.
        lvI.pszText   = LPSTR_TEXTCALLBACK; // Sends an LVN_GETDISPINFO message.
        lvI.mask      = LVIF_TEXT | LVIF_IMAGE |LVIF_STATE;
        lvI.stateMask = 0;
        lvI.iSubItem  = 0;
        lvI.state     = 0;    // Initialize LVITEM members that are different for each item.
        for (int index = 0; index < cItems; index++)
        {
            lvI.iItem  = index;
            lvI.iImage = index;
        
            // Insert items into the list.
            if (ListView_InsertItem(hWndListView, &lvI) == -1)
                return FALSE;
        }    return TRUE;
    }
      

  3.   

    谁能给个C语言的实例啊,我没有搜到C语言的,只有C++或者C#什么的
      

  4.   

    其实按以上的三个步骤就行了也可以看看代码Using ListView control under Win32 API