CListBox message ON_LBN_SELCHANGE not sent?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I defined a class name FileList that extends CListBox. Near the top of the file FileList.cpp, I have:

<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px BEGIN_MESSAGE_MAP(FileList, CListBox) </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)     ON_LBN_SELCHANGE(IDC_FILELIST, OnSelChange) </td></tr><tr><td>END_MESSAGE_MAP() </td></tr></tbody></table>
In the same file, I defined the OnSelChange method:

<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue void</font><font style="font-size:11px  FileList::OnSelChange() { </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)   <font style="color:blue int</font><font style="font-size:11px  index = </font><font style="color:blue this</font><font style="font-size:11px ->GetCurSel(); </font></td></tr><tr><td>  <font style="color:blue int</font><font style="font-size:11px  textLen = </font><font style="color:blue this</font><font style="font-size:11px ->GetTextLen(index); </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)   CString str; </td></tr><tr><td>  <font style="color:blue this</font><font style="font-size:11px ->GetText(index, str.GetBuffer(textLen)); </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)   AfxTrace(_T(<font style="color:blue "Selected: %sn"</font><font style="font-size:11px ), str); </font></td></tr><tr><td>} </td></tr></tbody></table>
In the file FileList.h, I declared the OnSelChange method:

<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px </font><font style="color:blue protected</font><font style="font-size:11px : </font></td></tr><tr><td style="background-color:rgb(247, 247, 247)   afx_msg <font style="color:blue void</font><font style="font-size:11px  OnSelChange(); </font></td></tr><tr><td>  DECLARE_MESSAGE_MAP() </td></tr></tbody></table>
I created the FileList with:

<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px <table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap <tbody><tr><td><font style="font-size:11px dwStyle = WS_CHILD | WS_VISIBLE | LBS_STANDARD; </font></td></tr><tr><td style="background-color:rgb(247, 247, 247) fileList.Create(dwStyle, CRect(724, 100, 900, 300), &m_cwnd, IDC_FILELIST); </td></tr></tbody></table>
I put a breakpoint in the method OnSelChange, but didnt get there, no matter which of the CListBoxs item I clicked on. By the way, how do I prevent multiple-selection? I only want users to select one item at a time.




View the full article
 
Back
Top