Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating a CListbox manually ends up with corrupted HWND. [FIXED]

Creating a CListbox manually ends up with corrupted HWND. [FIXED]

Scheduled Pinned Locked Moved C / C++ / MFC
designtestingbeta-testinghelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    I am creating a CListBox manually as part of a auto-complete editbox (CEdit) to display possible choices. The complete UI is something like:

    CDialog
    CMFCPropertyGridCtrl
    Subclassed CMFCPropertyGridProperty to use my own CEdit Class, AutoCompleteEditBox (override CreateInPlaceEdit).
    CEdit
    CListBox

    I create my listbox in the AutoCompleteEditBox:

    void AutoCompleteEditBox::ShowListBox()
    {
    if ( !m_ListBox.GetSafeHwnd() )
    {
    UINT extendedStyle = WS_EX_CONTROLPARENT | WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_TOPMOST;
    UINT style = LBS_NOTIFY|WS_POPUP|WS_BORDER|WS_VISIBLE|WS_VSCROLL;

    /// I tried setting the parent to different CWnd (The dialog, the CMFCPropertyGridCtrl...)
    CWnd* parent = nullptr;
    if ( m_ParentWindow )
    {
    parent = m_ParentWindow;
    }
    else
    {
    parent= GetParent();
    }

    	BOOL ret = m\_ListBox.CreateEx(extendedStyle, \_TEXT("LISTBOX"),NULL,style, CRect( 0,0,0,0), parent, 0 , this);
    

    //// At this point the HWND of the list box is 0xFEEEFEEE.

    	ASSERT( ret);
    }
    

    }

    And this gets called

    int SuggestionListBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CListBox::OnCreate(lpCreateStruct) == -1)
    return -1;

    //// At this point the HWND of the listbox is valid.
    m_pEdit = (AutoCompleteEditBox*)lpCreateStruct->lpCreateParams;
    return 0;
    }

    For testing purpose, I created the AutoCompleteEditBox as a child of the top level CDialog and everything works as expected. Any ideas, suggestions or things I might have missed ? Thanks, Max. ================= I finally fixed the creation issue. The Edit box created was using the id AFX_PROPLIST_ID_INPLACE; I thought it was OK to continue use it, I replaced the id with a different one and now all is working nicely (well, it is not finished, but I can continue updating and upgrading the feature).

    I'd rather be phishing!

    B 1 Reply Last reply
    0
    • M Maximilien

      I am creating a CListBox manually as part of a auto-complete editbox (CEdit) to display possible choices. The complete UI is something like:

      CDialog
      CMFCPropertyGridCtrl
      Subclassed CMFCPropertyGridProperty to use my own CEdit Class, AutoCompleteEditBox (override CreateInPlaceEdit).
      CEdit
      CListBox

      I create my listbox in the AutoCompleteEditBox:

      void AutoCompleteEditBox::ShowListBox()
      {
      if ( !m_ListBox.GetSafeHwnd() )
      {
      UINT extendedStyle = WS_EX_CONTROLPARENT | WS_EX_TOOLWINDOW|WS_EX_WINDOWEDGE|WS_EX_TOPMOST;
      UINT style = LBS_NOTIFY|WS_POPUP|WS_BORDER|WS_VISIBLE|WS_VSCROLL;

      /// I tried setting the parent to different CWnd (The dialog, the CMFCPropertyGridCtrl...)
      CWnd* parent = nullptr;
      if ( m_ParentWindow )
      {
      parent = m_ParentWindow;
      }
      else
      {
      parent= GetParent();
      }

      	BOOL ret = m\_ListBox.CreateEx(extendedStyle, \_TEXT("LISTBOX"),NULL,style, CRect( 0,0,0,0), parent, 0 , this);
      

      //// At this point the HWND of the list box is 0xFEEEFEEE.

      	ASSERT( ret);
      }
      

      }

      And this gets called

      int SuggestionListBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
      if (CListBox::OnCreate(lpCreateStruct) == -1)
      return -1;

      //// At this point the HWND of the listbox is valid.
      m_pEdit = (AutoCompleteEditBox*)lpCreateStruct->lpCreateParams;
      return 0;
      }

      For testing purpose, I created the AutoCompleteEditBox as a child of the top level CDialog and everything works as expected. Any ideas, suggestions or things I might have missed ? Thanks, Max. ================= I finally fixed the creation issue. The Edit box created was using the id AFX_PROPLIST_ID_INPLACE; I thought it was OK to continue use it, I replaced the id with a different one and now all is working nicely (well, it is not finished, but I can continue updating and upgrading the feature).

      I'd rather be phishing!

      B Offline
      B Offline
      Bram van Kampen
      wrote on last edited by
      #2

      Well, I am not familiar with the class 'CAutoCompleteEditBox' etc. I still use MFC42. This version does not have anything that fancy, but the nearest would be a CComboBox, with the Edit option set to True. Make sure that the Resource Template has the property 'USER_DRAWN' if you want to add your own options. You add these on an EN_CHANGE message. The best way to investigate this is to open the Resource file in a Text Editor, and inspect and edit the values for the control. In MFC42 you would be required to, as a minimum, implement the '(On)DrawItem()' virtual function, The Standard Implementation of (On)DrawItem() Asserts in MFC42! I have in the mean time derived my own libraries for things like this. Hope this is of help. :)

      Bram van Kampen

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups