Link to home
Start Free TrialLog in
Avatar of ndb
ndb

asked on

ListBox on EditView ...

I ran the MFC Applicationwizard and used CEditView as base class instead of CView.
Now I want to attach a ListBox on it like in Visual Basic and Visual C++. That ListBox must foolow the caret position.
How can I do this?
BTW: I am novice in MFC and VC++ stuff.
Avatar of Answers2000
Answers2000

1. Override PreCreateWindow for the CEditView.  In this make sure the WS_CLIPCHILDREN style is set

cs.style | = WS_CLIPCHILDREN

2. Add a member variable to the CEditView derived class
 CListBox  m_List

3. Override OnCreate for CEditView. Call m_List.Create to create the list box.  Make sure it has WS_CHILD style.  Make the list box visible using m_List.ShowWindow(SW_SHOW)

4. In Edit view, handle the reflected EN_SELCHANGE message (=EN_SELCHANGE).  This will tell you the selection/caret has moved within the edit control.  Use m_List.MoveWindow to move the list box

5. If the edit view has horizontal scrollbars you need to also handle =EN_HSCROLL, which will occur when the edit control is scrolled (even if caret doesn't move) and use m_List.MoveWindow

6. If the edit view has vertical scrollbar, handle also =EN_VSCROLL, similarly to #5

7. If you want the list box to disappear for a while, use m_List.ShowWindow(SW_HIDE)

8. If you want to the list box to reappear, use m_List.ShowWindow(SW_SHOW) ;
Let me know if you consider this an answer to your Q, or one of the steps is not clear enough
Avatar of ndb

ASKER

How do I change the color and the borderstyle of that ListBox?
I know that the ListBox is ceated 'cause my mousepointer changes from chape but I can't see the ListBox.
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Typo in my prev comment

>> You can add a simple border, by setting the style (in m_List.Create call) to WS_BORDER.

should have said

You can add a simple border, by setting the style (in m_List.Create call) to include WS_BORDER. (styles are separated by |)