Creating a CListbox manually ends up with corrupted HWND. [FIXED]
-
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
CListBoxI 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!
-
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
CListBoxI 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!
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