Search This Blog

Tuesday, September 22, 2009

Creating SDI application with List View



// MainFrm.h

CSplitterWnd m_splitwnd;



//MainFrm.pp
//Override OnCreateClient using properties in classview
//CLeftView and CRightView are the class should be derived from any of view class
//like CTreeView, CListView, CFormView
// Here CRightView derived from CListView

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// Add following Code
if(!m_splitwnd.CreateStatic(this,1,2))
return FALSE;

if(!m_splitwnd.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,200),pContext) ||
!m_splitwnd.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(100,200),pContext) )
{
m_splitwnd.DestroyWindow();
return FALSE;
}
// End


return CFrameWndEx::OnCreateClient(lpcs, pContext);
}



// RightView.cpp : implementation file
//in CRightView Class add WM_CREATE message

int CRightView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;

GetListCtrl().DeleteAllItems();

CListCtrl &mylist =this->GetListCtrl();

ModifyStyle(NULL, LVS_REPORT , 0);
mylist.SetExtendedStyle( mylist.GetExtendedStyle() |LVS_EX_CHECKBOXES| LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_TWOCLICKACTIVATE | LVS_EX_SUBITEMIMAGES );

mylist.InsertColumn(0, _T("S.No"),LVCFMT_LEFT| LVCF_TEXT);
mylist.InsertColumn(1, _T("Name"), LVCFMT_LEFT| LVCF_TEXT);
mylist.InsertColumn(2, _T("Country"), LVCFMT_LEFT| LVCF_TEXT);
mylist.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
mylist.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
mylist.SetColumnWidth(2, 100);

/*
mylist.InsertItem( 0, _T(""));
mylist.SetItemText( 0, 0, _T("1") );
mylist.SetItemText( 0, 1, _T("John") );
mylist.SetItemText( 0, 2, _T("India") );
*/


return 0;
}

No comments: