Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
// 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(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(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 26-Jun-13 0:44am
Edited 26-Jun-13 0:49am
v2
Comments
ThePhantomUpvoter at 26-Jun-13 6:00am
   
This is just a code dump, not a question or any kind of a description of a problem.
Nawabpasha at 26-Jun-13 6:49am
   
while double clicking the button control i am not able go the code, where is is placed
Maximilien at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
}
  Permalink  
Comments
Richard MacCutchan at 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)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 28 Oct 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100