<small id='V0ZI4'></small><noframes id='V0ZI4'>

    <i id='V0ZI4'><tr id='V0ZI4'><dt id='V0ZI4'><q id='V0ZI4'><span id='V0ZI4'><b id='V0ZI4'><form id='V0ZI4'><ins id='V0ZI4'></ins><ul id='V0ZI4'></ul><sub id='V0ZI4'></sub></form><legend id='V0ZI4'></legend><bdo id='V0ZI4'><pre id='V0ZI4'><center id='V0ZI4'></center></pre></bdo></b><th id='V0ZI4'></th></span></q></dt></tr></i><div id='V0ZI4'><tfoot id='V0ZI4'></tfoot><dl id='V0ZI4'><fieldset id='V0ZI4'></fieldset></dl></div>

        <legend id='V0ZI4'><style id='V0ZI4'><dir id='V0ZI4'><q id='V0ZI4'></q></dir></style></legend>
          <bdo id='V0ZI4'></bdo><ul id='V0ZI4'></ul>

      1. <tfoot id='V0ZI4'></tfoot>
      2. CListCtrl 带复选框问题

        CListCtrl with checkboxes questions(CListCtrl 带复选框问题)
        <tfoot id='SDeAh'></tfoot>

              <tbody id='SDeAh'></tbody>

            1. <i id='SDeAh'><tr id='SDeAh'><dt id='SDeAh'><q id='SDeAh'><span id='SDeAh'><b id='SDeAh'><form id='SDeAh'><ins id='SDeAh'></ins><ul id='SDeAh'></ul><sub id='SDeAh'></sub></form><legend id='SDeAh'></legend><bdo id='SDeAh'><pre id='SDeAh'><center id='SDeAh'></center></pre></bdo></b><th id='SDeAh'></th></span></q></dt></tr></i><div id='SDeAh'><tfoot id='SDeAh'></tfoot><dl id='SDeAh'><fieldset id='SDeAh'></fieldset></dl></div>

                <small id='SDeAh'></small><noframes id='SDeAh'>

                  <bdo id='SDeAh'></bdo><ul id='SDeAh'></ul>
                • <legend id='SDeAh'><style id='SDeAh'><dir id='SDeAh'><q id='SDeAh'></q></dir></style></legend>
                • 本文介绍了CListCtrl 带复选框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  列表控件被定义为资源的单一选择.

                  The List Control is defined as Single Selection on the resources.

                  问题 1

                  我想在我的 CListCtrl 的第一列的标题上有一个复选框.在 OnInitDialog 我有

                  I want to have a checkbox on the header of first column of my CListCtrl. On the OnInitDialog I have

                      m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
                  
                      CString s;
                      s.LoadString(IDS_COLUMN1);
                  
                      #ifndef HDS_CHECKBOXES
                      // Copied from Microsoft SDKsWindowsv7.0AIncludeCommCtrl.h
                      #define HDS_CHECKBOXES  0x0400
                      #endif 
                  
                      CHeaderCtrl& header = *m_list.GetHeaderCtrl();
                      header.ModifyStyle(0, HDS_CHECKBOXES);
                  
                  
                      #ifndef HDF_CHECKBOX
                      // Copied from Microsoft SDKsWindowsv7.0AIncludeCommCtrl.h    
                      #define HDF_CHECKBOX  0x0040
                      #endif 
                  
                      LVCOLUMN lc = { 0 };
                      lc.mask = LVCF_FMT |LVCF_WIDTH |LVCF_TEXT | LVCF_SUBITEM;
                      lc.fmt |= HDF_CHECKBOX;
                      lc.cx = 96;
                      lc.pszText = (TCHAR*) (LPCTSTR)s;
                  
                      m_list.InsertColumn(0, &lc);
                  

                  如果我添加扩展的|LVS_EX_AUTOCHECKSELECT,它只显示标题的复选框,我绝对不想要,因为我希望检查动作和选择动作将用于不同的目的.

                  It only presents the header's checkbox if I add in the extended |LVS_EX_AUTOCHECKSELECT, which I definitely not want because I desire that checking action and selection action will be used for different purposes.

                  问题 2

                  我需要设置一个布尔值,并在用户选中或取消选中某个项目时将其标记为已修改.但是我不希望在插入项目时发生此操作,例如在加载表单时填写列表时,但它是无意触发的,因为 InsertItem 上触发取消选中操作">OnItemChanged.

                  I need to set a boolean and mark thing as modified when user checks or unchecks an item. But I don't want this action to occur when inserting items, for example when filling the list at form loading, but it is triggered without my intention, as InsertItem triggers "a uncheck action" on OnItemChanged.

                  它迫使我使用 m_is_inserting 成员标志来调节每个插入:

                  It obliged me to condition every insert with a m_is_inserting member flag:

                      m_is_inserting = true;
                      m_list.InsertItem(i, m_array[i]->GetName());
                      m_is_inserting = false;
                  

                  并对 LVN_ITEMCHANGED 处理程序做出相应的反应

                  and react accordingly on the LVN_ITEMCHANGED handler

                  void CMyDialog::OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
                  {
                      NMLISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
                  
                      if (pNMListView->uChanged & LVIF_STATE)
                      {
                          if (pNMListView->uNewState & LVIS_SELECTED)
                              OnSelect();
                          else
                          {
                              if (pNMListView->iItem != -1)
                              {
                                  if ((pNMListView->uNewState & LVIS_STATEIMAGEMASK) == 0x1000)
                                  {
                                      if (!m_is_inserting)
                                      {
                                          m_array[pNMListView->iItem]->m_active = false;
                                          SetModified();
                                      }
                                  }
                                  else if ((pNMListView->uNewState & LVIS_STATEIMAGEMASK) == 0x2000)
                                  {
                                      if (!m_is_inserting)
                                      {
                                          m_array[pNMListView->iItem]->m_active = true;
                                          SetModified();
                                      }
                                  }
                              }
                          }
                      }
                  
                      *pResult = 0;
                  }
                  

                  是否有更好的方法将真实的用户选中/取消选中操作与 InsertItem 副作用区分开来?

                  Is there a better way to distinguish a real user check/uncheck action from a InsertItem side effect?

                  问题 3

                  是否有更好的符号约定来获取选中/取消选中状态?幻数 0x10000x2000 毫无意义!

                  Is there a better symbolic convention for getting the check/uncheck state? Magic numbers 0x1000 and 0x2000 are pretty meaningless!

                  提前致谢.

                  推荐答案

                  先插入列标题.然后更改HDF_CHECKBOX.例如:

                  Insert the column headers first. Then change the HDF_CHECKBOX. For example:

                  m_list.SetExtendedStyle(LVS_EX_CHECKBOXES| LVS_EX_FULLROWSELECT);
                  
                  CHeaderCtrl &header = *m_list.GetHeaderCtrl();
                  header.ModifyStyle(0, HDS_CHECKBOXES);
                  
                  m_list.InsertColumn(0, L"Column0", 0, 120, 0);
                  m_list.InsertColumn(1, L"Column1", 0, 80, 1);
                  m_list.InsertColumn(2, L"Column2", 0, 80, 2);
                  
                  HDITEM hdi = { 0 };
                  hdi.mask = HDI_FORMAT;
                  header.GetItem(0, &hdi);
                  hdi.fmt |= HDF_CHECKBOX;
                  header.SetItem(0, &hdi);
                  
                  m_list.InsertItem(m_list.GetItemCount(), L"C0", 0);
                  m_list.InsertItem(m_list.GetItemCount(), L"C1", 0);
                  
                  m_list.SetCheck(0, 1);
                  m_list.SetCheck(1, 1);
                  

                  在处理通知时,您可以使用 GetCheck 方法查看项目是否被选中.示例:

                  When handling the notification you can use the GetCheck method to see if item is checked or not. Example:

                  if(pNMListView->uChanged & LVIF_STATE)
                  {
                      if(pNMListView->uNewState & LVIS_SELECTED)
                      {
                          ...
                      }
                      else if(pNMListView->uNewState & LVIS_STATEIMAGEMASK && pNMListView->iItem >= 0)
                      {
                          if(m_list.GetCheck(pNMListView->iItem))
                              TRACE("%d checked
                  ", pNMListView->iItem);
                      }
                  }
                  

                  这篇关于CListCtrl 带复选框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  Embed image in code, without using resource section or external images(在代码中嵌入图像,不使用资源部分或外部图像)
                  quot;First-chance exceptionquot; meaning in MFC Application?(“第一次机会例外在 MFC 应用程序中的含义?)
                  MFC: Changing the colour of CEdit(MFC:更改 CEdit 的颜色)
                  Adding #include lt;boost/thread/mutex.hppgt; breaks my ActiveX control?(添加 #include boost/thread/mutex.hpp破坏了我的 ActiveX 控件?)
                  error Please #define _AFXDLL or do not use /MD[d] occurs even after making changes in Project Properties(错误请#define _AFXDLL 或不使用/MD[d] 即使在项目属性中进行更改后也会发生)
                    <bdo id='uHOXc'></bdo><ul id='uHOXc'></ul>
                    <tfoot id='uHOXc'></tfoot>
                  • <i id='uHOXc'><tr id='uHOXc'><dt id='uHOXc'><q id='uHOXc'><span id='uHOXc'><b id='uHOXc'><form id='uHOXc'><ins id='uHOXc'></ins><ul id='uHOXc'></ul><sub id='uHOXc'></sub></form><legend id='uHOXc'></legend><bdo id='uHOXc'><pre id='uHOXc'><center id='uHOXc'></center></pre></bdo></b><th id='uHOXc'></th></span></q></dt></tr></i><div id='uHOXc'><tfoot id='uHOXc'></tfoot><dl id='uHOXc'><fieldset id='uHOXc'></fieldset></dl></div>

                          <tbody id='uHOXc'></tbody>
                        <legend id='uHOXc'><style id='uHOXc'><dir id='uHOXc'><q id='uHOXc'></q></dir></style></legend>

                        <small id='uHOXc'></small><noframes id='uHOXc'>