Solved

Simple combo box

Posted on 2000-03-30
15
187 Views
Last Modified: 2013-11-20
Hi ,
     I had designed a combo box,with styles set as simple and also programmed in such a way that whatever i type in the top is displayed in the box below when i press enter. Now, i am not able to type multilines of text,because if i press enter the typed line goes to the text box below.So whatever i type afterwards comes above the previous one. Please help me in displaying multi lines of text in this control
thanx,
thiru
0
Comment
Question by:thirumaran
[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
15 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2672439
Try for ctrl + enter.
0
 

Author Comment

by:thirumaran
ID: 2672734
i tried ctrl+enter also.it doesn't work . This method works only during designing. not during run time.
Thiru
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2672779
combo boxes don't support multi-lines of text.

Instead, use a multi-line edit box and a list box.  Place one above the other so they look like a simple combo box.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Zoppo
ID: 2672991
Hi thirumaran,

You could also use a counter which holds where to insert the next string. Here's an example based on suggestion I gave you yesterday:

----------------------------------------------------------------------------------------------------------------
class CMyDialog : public CDialog
{
 // add following members to your dialog class
 void InitCombo();

 HWND m_hEdit;
 int m_iCounter;
 ...
}

void
CMyDlg::InitCombo()
{
 // this function retrieves the handle of the combo box control's edit control to avoid
 // that text of edit control is also added when user presses enter while combo box
 // control's list has the input focus.
 // call this function near end of OnInitDialog()
 CWnd* pChild = m_cb.GetWindow( GW_CHILD );
 ASSERT( pChild );
 TCHAR buf[256];

 m_hEdit = NULL;
 for( int i = 0; i < 2; i++ )
 {
  GetClassName( pChild->m_hWnd, buf, 256 );
  if ( strcmp( buf, "Edit" ) == 0 )
  {
   m_hEdit = pChild->m_hWnd;
   break;
  }
  pChild = pChild->GetWindow( GW_HWNDNEXT );
 }

 ASSERT( m_hEdit )
 m_iCounter = 0;
}

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
 if ( pMsg->message == WM_KEYDOWN )
 {
  if ( pMsg->wParam == VK_RETURN )
  {
   CWnd* pFocus = GetFocus();
   BOOL bControl = GetKeyState( VK_CONTROL ) < 0;
   if ( NULL != pFocus && pFocus->m_hWnd == m_hEdit )
   {
    CString t;
    m_cb.GetWindowText( t );

    if ( !t.IsEmpty() || !bCtrl )
     m_cb.InsertString( m_iCounter++, t );

    t.Empty();
    m_cb.SetWindowText( t );

    if ( bCtrl )// if CTRL is pressed with ENTER reset counter to start new 'paragraph'
    {
     m_iCounter = 0;
    }

    return TRUE;
   }
  }
 }
 return CDialog::PreTranslateMessage(pMsg);
}
----------------------------------------------------------------------------------------------------------------

With this everytime you press ENTER when edit box has focus the text of the edit box is added after the last entered string until you press CTRL+ENTER.

hope that helps,

ZOPPO
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2673138
sorry, a typo: replace 'bCtrl' with 'bControl' ...
0
 

Author Comment

by:thirumaran
ID: 2675467
But when i run the program with the code given by u(zoppo) as soon as i type something in the top box and press enter or control enter the screen goes away.
nothing is stored anyway. Please help me in this regard.
thanx,
thiru
0
 

Author Comment

by:thirumaran
ID: 2678778
Adjusted points from 20 to 25
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2679106
Well, the code works in my project ... perhaps you (or I) missed something ... could you post your code?

ZOPPO
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2679120
Well, the code works in my project ... perhaps you (or I) missed something ... could you post your code?

ZOPPO
0
 

Author Comment

by:thirumaran
ID: 2679427
Hi Zoppo,
 the following is the code,which i typed from your answer.But when i press enter or press ctrl+enter the screen goes off.

void CDateCtrlDlg::InitCombo()
{
      CWnd* pChild = m_cb.GetWindow( GW_CHILD );
    ASSERT( pChild );
    TCHAR buf[256];
    m_hEdit = NULL;
    for( int i = 0; i < 2; i++ )
    {
            GetClassName( pChild->m_hWnd, buf, 256 );
        if ( strcmp( buf, "Edit" ) == 0 )
        {
                  m_hEdit = pChild->m_hWnd;
            break;
            }
        pChild = pChild->GetWindow( GW_HWNDNEXT );
      }
    ASSERT( m_hEdit ) ;
    m_iCounter = 0;
}


BOOL CDateCtrlDlg::PreTranslateMessage(MSG* pMsg)
{
      if(pMsg->message == WM_KEYDOWN)
      {
         if(pMsg->wParam == VK_RETURN)
         {
                  CWnd *pFocus = GetFocus();
                  BOOL bControl = GetKeyState( VK_CONTROL ) < 0;
                  if(NULL != pFocus && pFocus->m_hWnd == m_hEdit)
                  {
                        CString t;
                        m_cb.GetWindowText(t);
                        if(!t.IsEmpty() || !bControl)
                              m_cb.InsertString(m_iCounter++,t);
                        t.Empty();
                        m_cb.SetWindowText(t);
                        if(bControl)
                        {
                              m_iCounter = 0;
                        }
                        return TRUE;
                  }
            }
         }
          return CDialog::PreTranslateMessage(pMsg);
}

0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2679453
Hmm, that's strange, coz same code is working for me and further it's just a modification of the code you accepted in the other question. Try to set a breakpoint inside the second 'if' (with VK_RETURN) and debug into to see if the code is reached at all...
0
 

Author Comment

by:thirumaran
ID: 2679592
Hi Zoppo,
 the following is the code,which i typed from your answer.But when i press enter or press ctrl+enter the screen goes off.

void CDateCtrlDlg::InitCombo()
{
      CWnd* pChild = m_cb.GetWindow( GW_CHILD );
    ASSERT( pChild );
    TCHAR buf[256];
    m_hEdit = NULL;
    for( int i = 0; i < 2; i++ )
    {
            GetClassName( pChild->m_hWnd, buf, 256 );
        if ( strcmp( buf, "Edit" ) == 0 )
        {
                  m_hEdit = pChild->m_hWnd;
            break;
            }
        pChild = pChild->GetWindow( GW_HWNDNEXT );
      }
    ASSERT( m_hEdit ) ;
    m_iCounter = 0;
}


BOOL CDateCtrlDlg::PreTranslateMessage(MSG* pMsg)
{
      if(pMsg->message == WM_KEYDOWN)
      {
         if(pMsg->wParam == VK_RETURN)
         {
                  CWnd *pFocus = GetFocus();
                  BOOL bControl = GetKeyState( VK_CONTROL ) < 0;
                  if(NULL != pFocus && pFocus->m_hWnd == m_hEdit)
                  {
                        CString t;
                        m_cb.GetWindowText(t);
                        if(!t.IsEmpty() || !bControl)
                              m_cb.InsertString(m_iCounter++,t);
                        t.Empty();
                        m_cb.SetWindowText(t);
                        if(bControl)
                        {
                              m_iCounter = 0;
                        }
                        return TRUE;
                  }
            }
         }
          return CDialog::PreTranslateMessage(pMsg);
}

0
 

Author Comment

by:thirumaran
ID: 2682550
I am not able to detect the error,even if i keep the breakpoint as said by you. The dialog box disappears after typing in the combo box.
thiru
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 25 total points
ID: 2682847
I fear my only chance to help you out with this would be sending me your project (or at least a sample project) where this doesn't work so I can debug it.

If you agree, my email is 'zoppo@cdsgmbh.de'.

ZOPPO
0
 

Author Comment

by:thirumaran
ID: 2692710
Thanx for ur answer.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ShiftLeft challenge 21 95
NotAlone Challenge 20 93
EvenOdd challenge 10 160
changeXy challenge 13 98
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
Suggested Courses

734 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