Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetID of the parent of a CWnd

311 views
Skip to first unread message

Thierry POQUET

unread,
May 31, 2001, 9:15:09 AM5/31/01
to
Hi,

I'm trying to map the ID of an item clicked with the ID of the dialog
where it belong.
On the MouseActivate event i can get the ID of the Control but i cannot get
the ID of the Dialog.

Can anybody tell me if it's possible, having a CWnd to get the ID of the
parent of this CWnd ?

I tried the following (having the original pWindow):

UINT iIDWindow;
UINT iIDControl;
CWnd* pParentWnd;

iIDControl = pWindow->GetDlgCtrlID(); // Get
the control ID (this work)
pParentWnd = pWindow->GetParent(); // Get
the Parent of the CWnd (this work)
iIDWindow = GetDlgCtrlID(pParentWnd->GetSafeHwnd()); // Get the ID of the
parent ?
or iIDWindow = pParentWnd->GetDlgCtrlID(); // Get the
ID of the parent ?

But all of them return 0...


Jake Montgomery

unread,
May 31, 2001, 2:40:55 PM5/31/01
to
Thierry,

I think the problem may be that the dialog does not have a 'Control ID' so
that GetDlgCtrlID() returns 0. The resource ID of the dialog is NOT the control
ID. According to the MSDN documentation for ::GetDlgCtrlID() top level windows
can never have a control ID.

I would suggest comparing pParentWnd->m_hWnd to the dialog you are looking
for. There are other approaches, but this is probably the simplest.

Good Luck,
Jake.

Chrys

unread,
May 31, 2001, 3:35:35 PM5/31/01
to
> iIDWindow = GetDlgCtrlID(pParentWnd->GetSafeHwnd()); // Get the ID of
the
> parent ?

This would be the dialog on which the controls reside, right?
You will notice if you use Spy++ that the controls all have a Control_Id and
the dialog
does not.

So 0 is a reasonable answer to expect back from GetParent()->GetDlgCtrlID();

Sam Hobbs

unread,
May 31, 2001, 4:35:47 PM5/31/01
to
The location used by Windows to store the control id is the same location
used to store a menu handle, so if you were to give your dialog a menu then
I think you would get the menu handle returned as a control id for the
dialog. I doubt you want to do that, but that probably helps to understand.


"Thierry POQUET" <tpo...@eleyms.com> wrote in message
news:DtrR6.388$E42.8411@NewsReader...

Thierry POQUET

unread,
Jun 1, 2001, 3:02:37 AM6/1/01
to
Thank guy's i found a solution:

In Debug Mode it's possible to see the ID of the Dialog, but the MFC do not
include any function to access it.
However the "m_nIDHelp" member of the class CDialog is a protected member.
Therefore i created a derived CDialog who has an added Funtion called GetID
wich return me the ID of the Dialog box and so far it seem to work a treat.
Unfortunatly this does not work for Menu :)

Thanks a lot for your help.

"Thierry POQUET" <tpo...@eleyms.com> wrote in message
news:DtrR6.388$E42.8411@NewsReader...

0 new messages