远飞

导航

c++用CreateWindow画listview

    RECT rcl;  //画listview位置

    CWindow myWindow;

    HWND hWndParent = m_hWnd;//本窗口句柄

    HINSTANCE  HInstance = GetModuleHandle(0);//当前exe实例

    myWindow.Attach(hWndParent);

    myWindow.GetClientRect(&rcl);可以将下面的数字变成rcl对应的x,y,宽,高   

    hWndListViewB =CreateWindow(WC_LISTVIEW,"",WS_CHILD|LVS_REPORT|LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP| LVS_SHOWSELALWAYS|WS_VISIBLE,

                      30,100,180,150,       

//listview的位置及宽、高。可以替换为RECT rcl对应的x,y,宽,高                

       hWndParent,//listview所在窗口句柄

       NULL,HInstance,NULL); 

 

    if(hWndListViewB == NULL) 

    { 

       //return NULL; 

    }      

  //ShowWindow(SW_SHOWNORMAL);//hWndListView,这个用了LISTVEIW不显示,改成上面加WS_VISIBLE就好了

    //UpdateWindow();   // hWndListView

   //以下为设置listview显示方式

    CListCtrl* pListCtrlB= (CListCtrl*)FromHandle(hWndListViewB); //由句柄得到对话框的对象指针

    CListView* pCListView= (CListView*)FromHandle(hWndListViewB);

    CListCtrl& BeginList = pCListView->GetListCtrl();

    long lStyle;

    lStyle=GetWindowLong(BeginList.m_hWnd,GWL_STYLE);

    lStyle &=~LVS_TYPEMASK;

    lStyle |=LVS_REPORT;

    SetWindowLong(BeginList.m_hWnd,GWL_STYLE,lStyle);

 

    DWORD  styleex =pListCtrlB->GetExtendedStyle();

    styleex |= LVS_EX_FULLROWSELECT; //选中某行使整行高亮(只适用于报表风格的listctrl)

    styleex |= LVS_EX_GRIDLINES; //网格线(只适用与报表风格的listctrl)

    styleex |=LVS_SORTASCENDING;

    pListCtrlB->SetExtendedStyle(styleex); //设置扩展风格

    pListCtrlB->SetBkColor(RGB(200, 200, 200));

    pListCtrlB->SetTextBkColor(RGB(200, 200, 200));

    pListCtrlB->SetTextColor(RGB(10, 10, 80));

 

    // listview插入列

    TRY

    {

       pListCtrlB->InsertColumn(0, _T("管理员ID"), LVCFMT_LEFT, 90);

       pListCtrlB->InsertColumn(1, _T("管理员名称"), LVCFMT_LEFT, 90);

 

      

    }

    CATCH (CMemoryException, e)

    {

      

    }

    END_CATCH

posted on 2013-04-19 09:42    阅读(1406)  评论(0)    收藏  举报