Solved

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

Posted on 2001-08-31
7
3,196 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
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 140
substring method in java 1 136
fix34  challenge 9 166
mapAB Challlenge 35 173
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.

733 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