Loading ...
Sorry, an error occurred while loading the content.

Re: [wtl] BUG: CListBox in Mutilple/Extended selection mode

Expand Messages
  • Yuri Kirilenko
    Hi Simon-Pierre, For what hack the original WTL-code, if for getting an index of focused item in the multiple-selection list box it is possible to create the
    Message 1 of 5 , Dec 1, 2000
    • 0 Attachment
      Hi Simon-Pierre,
       
      For what hack the original WTL-code, if for getting an index of focused item in
      the multiple-selection list box it is possible to create the wrapper class:
       
      class CMyListBox : public CListBox
      {
      public:
         int GetFocusFromMultipleSelection() const
         {
            ATLASSERT(::IsWindow(m_hWnd));
            ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
            return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
         }
      };
       
      Here you can do all assertions, whichever you want.
       
      Cheer, Yuri.
       
      -----Original message-----
      From: simon-pierre.cadieux@... <simon-pierre.cadieux@...>
      To: wtl@egroups.com <wtl@egroups.com>
      Sent: 30 November 2000, 19:59
      Subject: Re: [wtl] BUG: CListBox in Mutilple/Extended selection mode

      Yuri,
       
      Although not right in trying to replace
       
      ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
       
      by
       
      ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
       
      Dave's conclusion to replace the assertion by
       
      ATLASSERT((GetStyle() & LBS_NOSEL) == 0);
       
      (in fact it should be
       
      #if defined(_DEBUG) && (WINVER >= 0x0400)
      ATLASSERT((GetStyle() & LBS_NOSEL) == 0);
      #endif
      )
       
      is right. If you keep on reading the documentation on LB_GETCURSEL it is said that
       
      "If sent to a multiple-selection list box, LB_GETCURSEL returns the index of the item that has the focus rectangle. If no items are selected, it returns zero."
       
      So it is legitimate to call GetCurSel even for multiple-selection list box.
       
      Regards,
       
      Simon-Pierre
       
      ----- Original Message -----
      Sent: Thursday, November 30, 2000 1:11 PM
      Subject: Re: [wtl] BUG: CListBox in Mutilple/Extended selection mode

      Hi Dave,

      The original code is quite right:

      int GetCurSel() const
      {
        ATLASSERT(::IsWindow(m_hWnd));
        ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
        return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
      }

      Look to LB_GETCURSEL specification:

      "Do not send this message to a multiple-selection list box.
      To retrieve the indexes of the selected items
      in a multiple-selection list box, use the LB_GETSELITEMS message.
      To determine whether the item that has the focus rectangle
      in a multiple selection list box is selected,
      use the LB_GETSEL message."

      Best regards, Yuri


      -----Original message-----
      From: dshiel@... <dshiel@...>
      To: wtl@egroups.com <wtl@egroups.com>
      Sent: 30 November 2000, 15:51
      Subject: [wtl] BUG: CListBox in Mutilple/Extended selection mode

      >Hi there,
      >
      >I'm not sure whether this has been reported before (or subsequently
      >fixed in WTL 3.1) but here's the bug and the fix.
      >
      >I have a dialog with a listbox in Extended selection mode (i.e. style
      >LBS_EXTENDEDSEL).
      >In my code, when I call CListBox::GetCurSel() an ATL assertion occurs.
      >On closer inspection of the CListBox::GetCurSel function in
      >AtlCtrls.h (Line 345) I noticed that the following line will never
      >work.
      >
      >ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
      >
      >I changed it to the following, and everything works fine.
      >
      >ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
      >
      >Once this was done I started to think why this line is here at all.
      >Surely you don't want an assertion to occur if the listbox is in
      >single selection mode either.
      >
      >The assertion should only occur if the selection style is LBS_NOSEL.
      >
      >So the assertion code should probably be,
      >
      >ATLASSERT((GetStyle() & LBS_NOSEL) == 0);
      >
      >This assertion should also be copied to the CListBox::SetCurSel()
      >method.
      >
      >Later,
      >Dave.

    Your message has been successfully submitted and would be delivered to recipients shortly.