Solved

How to get a handle to edit control of CComboBox ???

Posted on 2001-08-31
7
3,304 Views
Last Modified: 2013-11-20

 Hello there,
   I created an object of CComboBox with CBS_DROPDOWN style which allows to edit the text.Now I have to implement UNDO functionality in it.But there is no undo method associated with CComboBox.Is there any way to get the handle of Edit Control of it,using which UNDO is possible. If it is not possible.please tell me how to use CComboBoxEx.I tried with that , but it doesn't shows the dropdown list.
please do reply soon.
0
Comment
Question by:Narendra_bt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6445782
I don't think it's posible.
To use CComboBoxEx declare a CComboBoxEx var in your window class and after the window was created call Create method for the combobox like in the code below:

m_cbxMyCombo.Create( CBS_DROPDOWN | WS_CHILD | WS_VISIBLE, CRect( 100, 100, 200, 200), this, 1 );    

This should do it.
0
 
LVL 7

Expert Comment

by:jimwasson
ID: 6445832
I think you're looking for GetDlgItem (the MFC version prototype is):
void CWnd::GetDlgItem( int nID, HWND* phWnd ) const

and associated functions GetDlgItemText() and SetDlgItemText.

You can look up the article "Retrieving Data from the Dialog Object" in the Visual Studio help for complete details.
0
 
LVL 1

Expert Comment

by:guoching
ID: 6446709
Since the edit box is a child window of ComboBox,we can use ::ChildWindowFromPoint(HWND,POINT) to get the Handle of Edit.

eg.
POINT ptn;
ptn.x = 2;
ptn.y = 2; //ComboxBox must be larger than two pixel
HWND hEdit = ::ChildWindowFromPoint(combox.m_hWnd,ptn);
0
Technology Partners: 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!

 
LVL 4

Accepted Solution

by:
jtwine100697 earned 50 total points
ID: 6447069
It is undocumented, but ComboBoxes create their edit control with an ID of 1001, so you should be able to use GetDlgItem(...) to get the handle of the edit control:

    CWnd *pCBEdit = m_cbComboBox.GetDlgItem( 1001 );

-=- James.
0
 

Author Comment

by:Narendra_bt
ID: 6447087

Hello James,
 Thanks,it works perfectly.

Narendra
0
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6447186
I don't know if it's recomanded to use a undocumented facility. It's undocumented because it my change and may not be avable in the next versions of window. But I think that it's a nice solution. jtwinwe where do u find out this ?
0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 6447703
> I don't know if it's recomanded to use a undocumented facility. It's undocumented because it my change [...]
> and may not be avable in the next versions of window.

With regard to APIs, that is very true.  But this particular behaviour is not likely to change: it has been this way since at least Windows 3.1.  Changing it risks breaking existing apps.

> But I think that it's a nice solution. jtwinwe where do u find out this ?

You can use Spy to determine the IDs of child windows.  It is also documented in an MFC FAQ somewhere.

-=- James.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

707 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