Solved

ListBox on EditView ...

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 79
Add content to output file 4 67
has22 challenge 11 105
sumHeights  challenge 17 75
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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