CWnd::Create question.
-
The Create function of the MFC CWnd class has a parameter for the ID of window/control. (Almost) all CWnd derived classes have such a parameter. When I create a control dynamically, do I have to specify a correct ID or can I just fill in any value (e.g. 0 or -1)? Is this ID actually used? and if so, for what is it used and how do I obtain the next available ID?
-
The Create function of the MFC CWnd class has a parameter for the ID of window/control. (Almost) all CWnd derived classes have such a parameter. When I create a control dynamically, do I have to specify a correct ID or can I just fill in any value (e.g. 0 or -1)? Is this ID actually used? and if so, for what is it used and how do I obtain the next available ID?
You can specify any ID you want to. The normal ID used for 'don't care' is
IDC_STATIC
(-1). The ID will be used if you want to retrieve the control by its ID, such as when callingGetDlgItem
,GetDlgItemText
,SetDlgItemText
, etc. The only way you could get the 'next available ID' would be to walk the window's child controls usingGetWindow
(get the first with GW_CHILD, then use GW_HWNDNEXT to get subsequent children) callingGetDlgCtrlID
on each one.