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

Posted on 2001-08-31
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.
Question by:Narendra_bt

Expert Comment

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.

Expert Comment

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.

Expert Comment

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

POINT ptn;
ptn.x = 2;
ptn.y = 2; //ComboxBox must be larger than two pixel
HWND hEdit = ::ChildWindowFromPoint(combox.m_hWnd,ptn);
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!


Accepted Solution

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.

Author Comment

ID: 6447087

Hello James,
 Thanks,it works perfectly.


Expert Comment

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 ?

Expert Comment

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.

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rewrite URL With Encoded Characters 6 78
mixString challenge 36 123
Include multiple hostnames in this command? 3 55
EvenOdd challenge 10 109
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

822 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