CEdit in a ComboBox

I'm trying to save real estate in my program.  I have a sometimes large paragraph of information that I want to make available to my user to look at and even cut and paste parts of it if they want.  My solution is to use a combobox control where the showing text says something like "Click the arrow on the right to read the information" and when the user clicks on the combobox's arrow, they get a drop down that contains a read-only edit control with the text, scrollbar, etc.  Like a regular edit box, they can still select and copy and paste text from this box.  Then click the arrow again to close the box.  

I've been working on this for hours and I'm pretty frustrated.  Any help would be greatly appreciated.  Let me know if you have any questions.  Thanks in advance.
jjjkkklllAsked:
Who is Participating?
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Have an edit box.  When it gets the focus increase it's size (use SetWindowPos or MoveWindow).  When the focus leaves the edit then reduce it's size to the default.
0
 
r2farCommented:
It would take an aweful long time for me to explain in detail how to do this... In short you need both a combo box and an edit box that the combo box has control over...

Check this out >> http://www.codeproject.com/netcf/historycombo.asp?target=combobox
0
 
peterchen092700Commented:
I would try a different approach:

* Catch the CBN_DROPDOWN notification to be notified when the combo-box opens.
* in the handler, close it immediately (CB_SHOWDROPDOWN, WPARAM=false), and create a "in-place-edit" control.

This would be a simple edit control, that
 - has WS_POPUP style
 - the dialog as parent
 - destroys itself when it loses focus

a simple - but not the best - example how to create an in-place edit is on http://www.codeproject.com/combobox/lbed.asp

Additionally you might want to handle ESC and RETURN in the edit, so these keys are not "taken away".




0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Nass89Commented:
Hi,
I'm agree to both suggested solutions from r2far and peterchen, with a modification to it. Place a combobox over an Editbox and when Combobox is clicked, hide the Combobox and show the Editbox and so on. I have tested something like this for three controls based on a user selection and it worked fine.

Good Luck!


0
 
jjjkkklllAuthor Commented:
Hey guys, thanks a lot for the ideas.  I tried for a while to create an in-place edit control, but I couldn't get it going.  I decided a better solution is do something like AndyAinscow suggested.  I put an edit control on my dialog with just enough height to show the first line.  Then I put a bitmap button right next to it that looks just like the combobox's down arrow (this way I have more control over what it looks like color-wise, etc.)  Now when the user clicks the "down arrow" I handle the click and use movewindow to expand the edit box down to full size.  They click it again and I return the box to its original size.  

The problem I'm having is that there's a lot of buttons and static controls and edit boxes under the box, so when it expands down, it covers over the other controls.  Which is what I want.  The problem is that some of the controls show through the new edit box and the buttons show up when you mouse over them.  Pretty messy.  Is there a way to make sure this doesn't happen.  That the new edit box is the only box in the area until the user hits the button or the box loses focus (I haven't handled that yet).  Thanks for the help.
0
 
r2farCommented:
I am not sure what this is for, but is it possible for you to have one large, multi-line edit box that does not shrink or expand.  then have a group of radio buttons to select what is displayed and edited in the box.  You could even use a static text control to display the first line of each content.

This suggestion is made without much knowledge of it's application so i hope it helps.
0
 
jjjkkklllAuthor Commented:
Yeah, that's a good idea too.  However, I really want this new box to add information and not affect the rest of the program or interface, which is pretty good.  I just want to be able to fit in a way to make more information available within tight real estate.  The perfect solution is a dropdown box that holds the info.  If I can't get this painting problem solved, I'm thinking the next option is to create a dialog box and pop that up over the edit control when the user hits the "down" button.  
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
When you resize use code like
GetDlgItem(IDC_CTLxxx)->ShowWindow(SW_SHOW);  or SW_HIDE
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
obviously for the controls that are covered by your enlarged edit
0
 
jjjkkklllAuthor Commented:
Hi guys,

Again, thanks for all the help.  I figured it all out.  The edit control that enlarges has to be after the other controls in the tab order.  That seems to solve that problem.  Here's the final code.  I have an edit control and a button next to it.  I handle the onkill focus of the edit control to know when to close the box back up.  I use bSuggestionOpen to know when the box is open.

void CPers1::OnDropbutton()
{
      RECT rect;
      m_edit1.GetWindowRect(&rect);
      ScreenToClient(&rect);
      
      if(bSuggestionOpen == TRUE)
      {
            bSuggestionOpen = FALSE;
      }
      else
      {
            rect.bottom += 100;
            bSuggestionOpen = TRUE;
                                //set focus so when I know it will lose focus to close
            m_edit1.SetFocus();
      }
      
      m_edit1.MoveWindow(&rect);
}

void CPers1::OnKillfocusSuggestionpers1()
{
      if(bSuggestionOpen == TRUE)
      {
            RECT rect;
            m_edit1.GetWindowRect(&rect);
            ScreenToClient(&rect);
            rect.bottom -= 100;
            m_edit1.MoveWindow(&rect);      
            bSuggestionOpen = FALSE;
      }
                //I had to add this so when the edit box loses control to click the drop button,
                //the box doesn't close before ondropbutton is handled and opens it again.
      if(GetFocus() != NULL)
      {
            if( GetFocus()->GetDlgCtrlID() == IDC_DROPBUTTON)
                  bSuggestionOpen = TRUE;
      }
}

It seems to work okay.  Let me know if you see anything that needs tweaking.  I'm going to give AndyAinscow the points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.