登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

sunwenhua168的博客

海纳百川,有容乃大

 
 
 

日志

 
 

引用 MFC——ListBox(转)  

2010-09-19 12:10:41|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
本文转载自生活很美《MFC——ListBox(转)》

 

引用

生活很美MFC——ListBox(转)

映射宏:

ON_LBN_DBLCLK 鼠标双击

ON_EN_ERRSPACE 输入框无法分配内存时产生

ON_EN_KILLFOCUS / ON_EN_SETFOCUS 在输入框失去/得到输入焦点时产生

ON_LBN_SELCHANGE 选择的行发生改变

使用以上几种消息映射的方法为定义原型如:afx_msg void memberFxn( );的函数,并且定义形式如ON_Notification( id, memberFxn )的消息映射。如果在对话框中使用列表框,Class Wizard会自动列出相关的消息,并能自动产生消息映射代码。

GetDlgItem(IDC_LIST1)->EnableWindow(FALSE)提供控件的id.获得指向控件的指针

是CWnd的成员函数

->ShowWindow(SW_SHOW)

->ShowWindow(SW_HIDE)显示或隐藏窗口,也是CWnd的成员函数

CListBox::AddString()函数可以向列表框中添加项目

事例程序:

void COptionListDlg::OnAddButton()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

if(m_edit==""){

MessageBox("请输入添加的数据");

return;

}

switch(m_radio){

case 0:

m_listbox1.AddString(m_edit);

break;

case 1:

m_listbox2.AddString(m_edit);

break;

case 2:

m_listbox3.AddString(m_edit);

break;

}

UpdateData(FALSE);

}

CListBox::GetCurSel()返回当前列表框选择项目的序号

CListBox::GetText()函数可以根据当前列表框的序号读取当前选择的项目

程序:

void COptionListDlg::OnSelchangeList1()

{

// TODO: Add your control notification handler code here

UpdateData(TRUE);

int index = m_listbox1.GetCurSel();

if(index == LB_ERR)

m_edit="";

else

m_listbox1.GetText(index,m_edit);

UpdateData(FALSE);

}

m_listbox1.DeleteString()

m_listbox1.InsertString()

程序:

void COptionListDlg::OnEditButton()

{

// TODO: Add your control notification handler code here

int index;

UpdateData(TRUE);

if(m_edit == ""){

MessageBox("请输入修改项目");

return;

}

switch(m_radio){

case 0:

index = m_listbox1.GetCurSel();

if(index == LB_ERR){

MessageBox("请选择要修改的项目");

return;

}

m_listbox1.DeleteString(index);

m_listbox1.InsertString(index,m_edit);

break;

case 1:

index = m_listbox2.GetCurSel();

if(index == LB_ERR){

MessageBox("请选择要修改的项目");

return;

}

m_listbox2.DeleteString(index);

m_listbox2.InsertString(index,m_edit);

break;

case 2:

index = m_listbox3.GetCurSel();

if(index == LB_ERR){

MessageBox("请选择要修改的项目");

return;

}

m_listbox3.DeleteString(index);

m_listbox3.InsertString(index,m_edit);

break;

}

}

  评论这张
 
阅读(951)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018