Solved

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

Posted on 2001-08-31
7
2,894 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Accepted Solution

by:
jtwine100697 earned 50 total points
Comment Utility
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
Comment Utility

Hello James,
 Thanks,it works perfectly.

Narendra
0
 
LVL 2

Expert Comment

by:BogdyPtr
Comment Utility
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
Comment Utility
> 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Help INsttalling wget on Mavericks OS X 3 81
only14 challenge 19 63
zeroMAx challenge 20 76
changeXy challenge 13 56
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 …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

12 Experts available now in Live!

Get 1:1 Help Now