Solved

CEdit in a ComboBox

Posted on 2004-04-25
10
499 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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
 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 178
Login Script to Copy Folders 12 35
pre4 challenge 19 100
firstChar challenge 13 115
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: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

772 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