MFC 列表控件修改实例(源码下载)

1、本程序基于前期我的博客文章《MFC下拉菜单打钩图标存取实例(源码下载)》
2、程序功能选中列表控件某一项,修改这一项的按钮由禁止变为可用,双击这个按钮弹出对话框可对这一项的记录数据进行修改,点击确定保存修改数据。
3、首先在主界面添加一个修改参数按钮。在这里插入图片描述
4、在myDlg.h 文件
class CMyDlg : public CDialog中添加代码

public:
void UpdateButton(void);
protected:
virtual LRESULT DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam);

5、选中列表控件,右击选择“事件…”,在弹出的事件句柄中选择“LVN_ITEMCHANGED”,如下图所示。
在这里插入图片描述

void CMyDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	POSITION pos = m_ctrlType.GetFirstSelectedItemPosition();
	if(pos != NULL)
	{
		int nItem = m_ctrlType.GetNextSelectedItem(pos);
		if(m_nTypeIndex != nItem)
		{
			m_nTypeIndex = nItem;
		}
	}
	else
		m_nTypeIndex = -1;	
	*pResult = 0;
}

6、在myDlg.cpp 文件中添加代码

LRESULT CMyDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	static int nTypeIndex = -2;
	if(::IsWindow(m_ctrlType.m_hWnd))
	{
		if(m_nTypeIndex != nTypeIndex)
		{
			nTypeIndex = m_nTypeIndex;
			UpdateButton();
		}
	}
	return CDialog::DefWindowProc(message, wParam, lParam);
}

void CMyDlg::UpdateButton()
{
	GetDlgItem(IDC_BUTTON3)->EnableWindow(m_nTypeIndex > -1);
}

7、在myDlg.cpp 文件中参数按钮中添加代码

void CMyDlg::OnButton3() 
{
	CTypeParaDlg dlg;
	dlg.m_pPara = &theApp.m_allPara[m_nTypeIndex];

	if(dlg.DoModal() == IDOK)
	{

    	LV_ITEM item;
		item.mask = LVIF_TEXT|LVIF_IMAGE;
		item.iItem = m_nTypeIndex;
		item.iSubItem = 0;
		item.pszText = theApp.m_allPara[m_nTypeIndex].m_strTypeName;
		item.iImage = 0;
		m_ctrlType.SetItem(&item);
		item.iSubItem = 1;
		item.pszText = theApp.m_allPara[m_nTypeIndex].m_strBrand;
		m_ctrlType.SetItem(&item);
		item.iSubItem = 2;
		item.pszText = theApp.m_allPara[m_nTypeIndex].m_strRemark;
		m_ctrlType.SetItem(&item);
	}	
}

运行程序
在这里插入图片描述
源码下载

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-04 20:40:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-04 20:40:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-04 20:40:02       82 阅读
  4. Python语言-面向对象

    2024-05-04 20:40:02       91 阅读

热门阅读

  1. 2024/5/3 C++五一

    2024-05-04 20:40:02       38 阅读
  2. PPT基础

    PPT基础

    2024-05-04 20:40:02      35 阅读
  3. SpringCloud相关面试题(详细解答)

    2024-05-04 20:40:02       33 阅读
  4. 2024十大免费cms建站系统有哪些

    2024-05-04 20:40:02       34 阅读
  5. 某夸克pan之搜索接口

    2024-05-04 20:40:02       33 阅读
  6. AI做画的算法原理

    2024-05-04 20:40:02       24 阅读
  7. 数字化思维的目的与价值,你真的懂吗?

    2024-05-04 20:40:02       28 阅读
  8. jvm内存模型五大部分是那些

    2024-05-04 20:40:02       34 阅读
  9. python直接发布到网站wordpress之二发布图片

    2024-05-04 20:40:02       33 阅读
  10. Mac Word文档没保存但是word突然卡住

    2024-05-04 20:40:02       31 阅读