How to get edit control of combo in Win95
Paul.B.Folbrecht@JCI.Com
Wednesday, October 16, 1996
Environment: Win95, Visual C++ 4.1
I used to know how to get the edit control portion of a combo box very
easily: ChildWindowFromPoint( cbCombo, CPoint( 1, 1 ) ). This
apparantly does not work in Win95! I get the handle to the combo box
itself. This always seemed like a hokey method to me, relying on a
hard-coded physical position like that, but it was documented by MS,
and I don't know of another way. How can I do this very simple thing
under Win95??
-Paul Folbrecht,
Compuware Corp.
Alex Sevugan -- asevugan@csci.csc.com
Thursday, October 17, 1996
[Mini-digest: 6 responses]
Try GetWindow(GW_CHILD) as Edit Window is the first
child of a Combo Box and I know this works in Win
95
-alaks
Paul.B.Folbrecht@JCI.Com wrote:
>
> Environment: Win95, Visual C++ 4.1
>
> I used to know how to get the edit control portion of a combo box very
> easily: ChildWindowFromPoint( cbCombo, CPoint( 1, 1 ) ). This
> apparantly does not work in Win95! I get the handle to the combo box
> itself. This always seemed like a hokey method to me, relying on a
> hard-coded physical position like that, but it was documented by MS,
> and I don't know of another way. How can I do this very simple thing
> under Win95??
>
> -Paul Folbrecht,
> Compuware Corp.
>
>
--
-----------------------------------------------
Alaks Sevugan CSC CIS
Technical Consultant 115 North Neil Street
(217) 351-8250 (2161) Champaign, Illinois
asevugan@csci.csc.com 61820
-----------------------------------------------
-----From: Sumit Chawla
Hello Paul,
Use CWnd member function GetWindow(GW_CHID). The CWnd here is your
combobox. This relies on the fact that the edit control is the
first child window of the combobox.
-Sumit Chawla
Computer Sciences Corporation
schawla@csci.csc.com
-----From: Michael Schneider
Hi Paul
in Win95 the border of the combo box is some pixels wider so try
CPoint(3,3). I know, that's still the same "hokey method", but it works
:-)
Mike
---------------------------------------------------
Michael Schneider
Pirckheimer Weg 13
91058 Erlangen
Tel.: ++49 9131 771539
E-Mail: Mike.Schneider@fim.uni-erlangen.de
WWW: http://home.t-online.de/home/09131771539-0001
---------------------------------------------------
-----From: groftde@ebs.ac.com (Derek F. Groft - UTL)
I had the same problem switching from NT3.51 to NT4.0. This works on 4.0
so hopefully it will work on Win95, but I have never tested it there.
HWND h = .GetDlgItem(1001)->m_hWnd;
This may be no more reliable than your old solution in terms of working in
the next release of the OS or VC++, but it works for now.
-----From: kitk@mudshark.sunquest.com (Kit Kauffmann)
i do this (in 3.1) by looking for a WM_CTLCOLOR msg with the ID of the combo
and CTL_COLOREDIT as nCtlType - obviously the messages for coloring have
changed in Win32, but a similar trick should work
HTH!
-----From: ktm@ormec.com
I've never seen that documentation, unless you mean the "subclassing a combo
box" example in the Win32 SDK documentation. I did a quick search, and
found three ways to do it:
METHOD 1
A little experimentation shows that using a CPoint of (3,3) works on Windows 95.
That point can be (I think) derived from
int yvalue = GetSystemMetrics(SM_CYEDGE)+ // 3-d combo box border (==2)
GetSystemMetrics(SM_CYBORDER) // edge of edit box (==1)
Note that on NT 3.51, (and Windows 3.x) SM_CYEDGE isn't used, and the edit box
part of the combo box doesn't have a border, which is why (1,1) used to work.
METHOD 2
A better way to do it is to get the child window of the combo box.
Here's an example, taken from KB article 128110.
//This code obtains the handle to the edit control of the combobox.
// hWnd is the handle of the combo box
HWND hEdit, hList;
hEdit = GetWindow(hWnd, GW_CHILD);
GetClassName (hEdit, wndClassName, 10);
if (!lstrcmp (wndClassName, "Edit"))
hList=GetWindow(hEdit, GW_HWNDNEXT);
else {
hList=hEdit;
hEdit=GetWindow(hList, GW_HWNDNEXT);
}
Other examples (e.g. KB article 142481 and some messages from the MFC-L
archive), assume that the edit box is always the first child window of the combo
box and just use hEdit = GetWindow(hWnd, GW_CHILD) without additional checks,
so it's not clear exactly what's going on with the calls to
GetWindow(GW_HWNDNEXT).
METHOD 3
The MFC FAQ at http://www.stingsoft.com/mfc_faq/ states (item 6.2.11)
Look into the mfc sample - npp - npview.cpp! Turns out all combo's create
their edits with an ID of 1001 (decimal) so - if pComboBox is the pWnd
object pointing to the combo - all you need is:
pComboBox->GetDlgItem(1001);
Katy
--
Katy Mulvey ktm@ormec.com
Software Development Engineer
ORMEC Systems http://www.ormec.com
19 Linden Park; Rochester, NY 14625
| Вернуться в корень Архива
|