Is there a way to get a reference to all the child windows or controls on an MFC dialog, given that I have a CWnd object referencing that control?

六月ゝ 毕业季﹏ 提交于 2021-02-08 03:44:34

问题


Lets say I have an MFC Dialog with several buttons on it. (E.g. "Red", "Blue", "Green", and "Yellow" buttons) These buttons all have IDs such as ("IDC_BUTT_RED","IDC_BUTT_BLUE","IDC_BUTT_GREEN","IDC_BUTT_YELLOW")

Given that I have a CWnd object that references the dialog window that these buttons are placed on. Is there a way to get a list of these IDs?

I know there is a CWnd::GetNextDlgGroupItem method, that based on the description should iterate through a group of controls. I tried using it, passing in a CWnd object referring to one of the buttons, then calling the GetWindowText method to check, but it always returns a reference to itself.


回答1:


You can enumerate all of the dialog's child windows using EnumChildWindows. This is a C API function so you use and get HWNDs instead of CWnds. When each child window's HWND is passed to your callback function you can call GetClassName to find its window class name (like "BUTTON") and GetWindowLong to find its ID.



来源:https://stackoverflow.com/questions/27788886/is-there-a-way-to-get-a-reference-to-all-the-child-windows-or-controls-on-an-mfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!