Why can not I get the resource ID of a dialog using GetDlgCtrlID?
int CTestDlg::GetID()
{
return GetDlgCtrlID();
}
Printable View
Why can not I get the resource ID of a dialog using GetDlgCtrlID?
int CTestDlg::GetID()
{
return GetDlgCtrlID();
}
Interesting.
Try passing in NULL as the parameter. What does GetDlgCtrlID() return?
Kuphryn
Is your dialog a child window or a top-level window?
From the documentation of GetDlgCtrlID():
Although GetDlgCtrlID may return a value if hwndCtl is a handle to a top-level window, top-level windows cannot have identifiers and such a return value is never valid.
I have tired creating the dialog as a top-level window as well as a child window, but it always returns 0.
Well, how can I get the resoucre ID even it is a top-level window?
Since he obviously uses the 'CWnd' version, how would he supposed to pass 0? The function does not take any parameter as opposed to the API version... :rolleyes:Quote:
Originally Posted by kuphryn
Note that GetDlgCtrlID() gives you the control ID of a control - that's something else than the resource ID. AFAIK, there's no way to determine the original resource ID of a dialog once it is created. Anyway, what do you need this for? If you absolutely need to know the ID of the resource at runtime, you could do the following: Create your own CDialog-derived class and derive all your app's dialogs from that class (instead of deriving directly from CDialog). Then add a ctor similar to that of CDialog, which, besides from calling the base ctor, saves the resource ID that is passed upon creation to a member variable. You can then add a member function GetResourceID() which returns that value.Quote:
Originally Posted by PomeloWu