Solved

CEdit in a ComboBox

Posted on 2004-04-25
10
496 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:jjjkkklll
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:r2far
ID: 10913265
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
 
LVL 7

Expert Comment

by:peterchen092700
ID: 10913520
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
 
LVL 5

Expert Comment

by:Nass89
ID: 10915485
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
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 10915808
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
 

Author Comment

by:jjjkkklll
ID: 10930776
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
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!

 
LVL 4

Expert Comment

by:r2far
ID: 10931642
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
 

Author Comment

by:jjjkkklll
ID: 10933823
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10935729
When you resize use code like
GetDlgItem(IDC_CTLxxx)->ShowWindow(SW_SHOW);  or SW_HIDE
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10935730
obviously for the controls that are covered by your enlarged edit
0
 

Author Comment

by:jjjkkklll
ID: 10940137
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

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

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Powershell based monitoring system 2 127
method notes when mouse over in eclipse 5 68
has77  challenge 9 68
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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 discusses moving either the default database or any database to a new volume.

757 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

21 Experts available now in Live!

Get 1:1 Help Now