Solved

ListBox on EditView ...

Posted on 1998-10-08
5
409 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:ndb
  • 4
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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) ;
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
Let me know if you consider this an answer to your Q, or one of the steps is not clear enough
0
 
LVL 1

Author Comment

by:ndb
Comment Utility
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.
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 200 total points
Comment Utility
1. To add a border
You can add a simple border, by setting the style (in m_List.Create call) to WS_BORDER.

2. To change color
i) The best thing to do is to derive a class from CListBox (use app wiz to generate a skeleton class derived from CListBox say CMyListBox)
ii) Change m_List variable from CListBox type to CMyListBox
iv) In CMyListBox add a member variable for a brush, say m_hBrush
v) In CMyListBox constructor create the brush to desired color, e.g.
      m_hBrush = CreateSolidBrush( RGB(0,0,128) ) ; // dark blue
vi) In CMyListBox destructor delete the brush, e.g.
   DeleteObject( m_hBrush)
vii)  In CMyListBox respond to =WM_CTLCOLOR message (see TN062 for more info on how this works).change the color and return the brush, e.g.
HBRUSH CMyListBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
      pDC->SetBkColor( RGB(0,0,128) ) ; // dark blue
      pDC->SetTextColor( RGB(0,255,255) ) ; // cyan

      return m_hBrush ;
}


3. Also Make sure the list box has a reasonable size for width and height


4. Also make sure the list box contains some stuff.  For example after calling m_List.Create in the edit view, add a couple of strings, e.g.

m_List.AddString( "Hello" ) ;
m_List.AddString( "World" ) ;

0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
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 |)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now