Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

Simple combo box

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
thirumaran
Asked:
thirumaran
1 Solution
 
Vinayak KumbarSr Program ManagerCommented:
Try for ctrl + enter.
0
 
thirumaranAuthor Commented:
i tried ctrl+enter also.it doesn't work . This method works only during designing. not during run time.
Thiru
0
 
RONSLOWCommented:
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!

 
ZoppoCommented:
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
 
ZoppoCommented:
sorry, a typo: replace 'bCtrl' with 'bControl' ...
0
 
thirumaranAuthor Commented:
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
 
thirumaranAuthor Commented:
Adjusted points from 20 to 25
0
 
ZoppoCommented:
Well, the code works in my project ... perhaps you (or I) missed something ... could you post your code?

ZOPPO
0
 
ZoppoCommented:
Well, the code works in my project ... perhaps you (or I) missed something ... could you post your code?

ZOPPO
0
 
thirumaranAuthor Commented:
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
 
ZoppoCommented:
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
 
thirumaranAuthor Commented:
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
 
thirumaranAuthor Commented:
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
 
ZoppoCommented:
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
 
thirumaranAuthor Commented:
Thanx for ur answer.
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now