Solved

Simple combo box

Posted on 2000-03-30
15
181 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

18 Experts available now in Live!

Get 1:1 Help Now