Solved

Simple combo box

Posted on 2000-03-30
15
180 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
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
 
LVL 30

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 30

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 30

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 30

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 30

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 30

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

22 Experts available now in Live!

Get 1:1 Help Now