CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    ListView extended styles not showing

    The gridlines are not appearing on my ListView.

    What did I miss?

    Code:
    #include <windows.h>
    #include <commctrl.h>
    
    #include <string>
    #include <iostream>
    using namespace std;
    
    #pragma comment(lib,"User32.lib")
    #pragma comment(lib,"ole32.lib")
    #pragma comment(lib,"comctl32.lib")
    #pragma comment(lib,"Gdi32.lib")
    
    #define ID_LISTVIEW 667
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    static char sClassName[] = "MyClass";
    static HINSTANCE g_hInst = NULL;
    
    /// GLOBALS
    static HWND hListView;
    LVCOLUMN lvc = {0};
    LVITEM   lvi = {0};
    int r;
    
    int CreateListView(HWND hParent)
    {
        hListView=
            CreateWindowEx(0,WC_LISTVIEW,
                         NULL,
                         WS_CHILD | WS_VISIBLE |
                         LVS_REPORT | LVS_EDITLABELS,
                         220,
                         10,
                         500,
                         300,
                         hParent,
                         (HMENU)ID_LISTVIEW,
                         g_hInst,
                         NULL);
    
    
        ListView_SetExtendedListViewStyle(hListView,
                                          LVS_EX_FULLROWSELECT  |
                                          LVS_EX_BORDERSELECT |
                                          LVS_EX_GRIDLINES);
    
    
        lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;
        lvc.fmt  = LVCFMT_LEFT;
    
    
        /* Add columns to the list-view (first column contains check box). */
    
    
        lvc.iSubItem = 0;
        lvc.cx       = 100;
        lvc.pszText  = TEXT("Name");
        ListView_InsertColumn(hListView, 1, &lvc);
    
    
        lvc.iSubItem = 1;
        lvc.cx       = 70;
        lvc.pszText  = TEXT("Episodes");
        ListView_InsertColumn(hListView, 2, &lvc);
    
    
        lvc.iSubItem = 2;
        lvc.cx       = 150;
        lvc.pszText  = TEXT("Any Good?");
        ListView_InsertColumn(hListView, 3, &lvc);
    
    
        /* Add some rows. item=rows */
        for(int i=0; i<93; i++)
        {
            lvi.iItem = i;
            ListView_InsertItem(hListView, &lvi);
            ListView_SetItemText(hListView, i, 0, TEXT("Friends"));
            ListView_SetItemText(hListView, i, 1, TEXT("500"));
            ListView_SetItemText(hListView, i, 2, TEXT("Alright"));
        }
    
    
        return 0;
    }
    
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
    {
        switch(Message)
        {
        case WM_CREATE:
    
    
                  /// ///// LISTVIEW ////////////////
            r=CreateListView(hwnd);
            if(r)
            {
                return 0;
            }
    
    
            return 0;
    
    
        case WM_CLOSE:
            DestroyWindow(hwnd);
            return 0;
    
    
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        }
        return DefWindowProc(hwnd,Message,wParam,lParam);
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,int nCmdShow)
    {
        WNDCLASSEX WndClass;
        HWND hwnd;
        MSG Msg;
    
    
        g_hInst = hInstance;
    
    
        WndClass.cbSize    = sizeof(WNDCLASSEX);
        WndClass.style     = NULL;
        WndClass.lpfnWndProc  = WndProc;
        WndClass.cbClsExtra  = 0;
        WndClass.cbWndExtra  = 0;
        WndClass.hInstance   = hInstance;
        WndClass.hIcon     = LoadIcon(NULL,IDI_APPLICATION);
        WndClass.hCursor    = LoadCursor(NULL,IDC_ARROW);
        WndClass.hbrBackground =(HBRUSH)(COLOR_WINDOW+1);
        WndClass.lpszMenuName = NULL;
        WndClass.lpszClassName = sClassName;
        WndClass.hIconSm    = LoadIcon(NULL,IDI_APPLICATION);
    
    
        if(!RegisterClassEx(&WndClass))
        {
            MessageBox(0,"Error Registering Class!","Error!",MB_ICONSTOP | MB_OK);
            return 0;
        }
    
    
        hwnd = CreateWindowEx(WS_EX_STATICEDGE,
                              sClassName,
                              "Tutorial",
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT,CW_USEDEFAULT,
                              820,440,
                              NULL,NULL,hInstance,NULL);
    
    
        if(hwnd == NULL)
        {
            MessageBox(0,"Error Creating Window!","Error!",MB_ICONSTOP | MB_OK);
            return 0;
        }
    
    
        ShowWindow(hwnd,nCmdShow);
        UpdateWindow(hwnd);
    
    
        while(GetMessage(&Msg,NULL,0,0))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    
    
        return Msg.wParam;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView extended styles not showing

    Quote Originally Posted by MasterDucky View Post
    The gridlines are not appearing on my ListView.
    And other extended styles? Do bothe LVS_EX_BORDERSELECT and LVS_EX_GRIDLINES "work"?
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: ListView extended styles not showing

    LVS_EX_FULLROWSELECT and LVS_EX_BORDERSELECT is working.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView extended styles not showing

    Quote Originally Posted by MasterDucky View Post
    LVS_EX_FULLROWSELECT and LVS_EX_BORDERSELECT is working.
    Then, perhaps, your current themes do show the gridlines very bad? Try another theme or, better the classic style!
    Victor Nijegorodov

  5. #5
    Join Date
    Dec 2007
    Location
    France
    Posts
    329

    Re: ListView extended styles not showing

    You're right Victor, my theme was the problem!

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ListView extended styles not showing

    Quote Originally Posted by MasterDucky View Post
    You're right Victor, my theme was the problem!
    Well, you are not the first!
    And it is the reason I always use the old good classic style!
    Victor Nijegorodov

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ListView extended styles not showing

    Quote Originally Posted by VictorN View Post
    Well, you are not the first!
    And it is the reason I always use the old good classic style!
    My problem is always that I have no style.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured