Solved

ListBox on EditView ...

Posted on 1998-10-08
5
410 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 103
lucky13 challenge 11 140
unix example issues 18 89
Increment column based of a FK 8 20
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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