Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// ListDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ListDemo.h"
#include "ListDemoDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CListDemoDlg dialog




CListDemoDlg::CListDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListDemoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CListDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, mylist);
}

BEGIN_MESSAGE_MAP(CListDemoDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CListDemoDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CListDemoDlg message handlers

BOOL CListDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

LVCOLUMN lvColumn;
int nCol;



lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 100;
lvColumn.pszText = _T("Product Name");
mylist.InsertColumn(0, &lvColumn);

lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 100;
lvColumn.pszText = _T("Volume");
mylist.InsertColumn(1, &lvColumn);

lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 100;
lvColumn.pszText = _T("Capital");
mylist.InsertColumn(2, &lvColumn);

lvColumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
lvColumn.fmt = LVCFMT_LEFT;
lvColumn.cx = 100;
lvColumn.pszText = _T("Rating");
mylist.InsertColumn(3, &lvColumn);

mylist.SetExtendedStyle(LVS_EX_FULLROWSELECT);


return TRUE; // return TRUE unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CListDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CListDemoDlg::OnQueryDragIcon()
{
return static_cast<hcursor>(m_hIcon);
}


void CListDemoDlg::OnBnClickedButton1()
{
CString ProductName = _T("xyz");
CString Volume = _T("1000");
CString Capital = _T("23");
CString Rating = _T("2");

LVITEM lvItem;
int nItem=0;

lvItem.mask = LVIF_TEXT;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = CT2W(((LPCTSTR)ProductName));
nItem = mylist.InsertItem(&lvItem);
for(int i=0;i<10;i++)
{
nItem = mylist.InsertItem(&lvItem);
mylist.SetItemText(nItem, 0, CT2W(((LPCTSTR)ProductName)));
mylist.SetItemText(nItem, 1, CT2W(((LPCTSTR)Volume)));
mylist.SetItemText(nItem, 2, CT2W(((LPCTSTR)Capital)));
mylist.SetItemText(nItem, 3, CT2W(((LPCTSTR)Rating)));
}
UpdateData(FALSE);
}
Posted
Updated 25-Jun-13 23:49pm
v2
Comments
[no name] 26-Jun-13 6:00am    
This is just a code dump, not a question or any kind of a description of a problem.
Nawabpasha 26-Jun-13 6:49am    
while double clicking the button control i am not able go the code, where is is placed
Maximilien 26-Jun-13 9:54am    
Are you asking about placing a breakpoint when the button is clicked ? or asking about how to call a callback when the button is clicked ?

1 solution

HCURSOR CListDemoDlg::OnQueryDragIcon()
{
return static_cast(m_hIcon);
}


void CListDemoDlg::OnBnClickedButton1()
{
CString ProductName = _T("xyz");
CString Volume = _T("1000");
CString Capital = _T("23");
CString Rating = _T("2");

LVITEM lvItem;
int nItem=0;

lvItem.mask = LVIF_TEXT;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = CT2W(((LPCTSTR)ProductName));
nItem = mylist.InsertItem(&lvItem);
for(int i=0;i<10;i++)
{
nItem = mylist.InsertItem(&lvItem);
mylist.SetItemText(nItem, 0, CT2W(((LPCTSTR)ProductName)));
mylist.SetItemText(nItem, 1, CT2W(((LPCTSTR)Volume)));
mylist.SetItemText(nItem, 2, CT2W(((LPCTSTR)Capital)));
mylist.SetItemText(nItem, 3, CT2W(((LPCTSTR)Rating)));
}
UpdateData(FALSE);
}
 
Share this answer
 
Comments
Richard MacCutchan 28-Oct-13 8:16am    
Do not post additional information as a Solution, it will just get your question ignored. Use the Improve question link and add it there. You also need to give a proper description of what your are trying to do, and what errors you are getti ng.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900