Solved

ListBox on EditView ...

Posted on 1998-10-08
5
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1323092
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
ID: 1323093
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
ID: 1323094
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
ID: 1323095
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
ID: 1323096
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

615 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