给定我有一个引用该控件的CWnd对象,是否有一种方法可以引用MFC对话框上的所有子窗口或控件? [英] 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?

查看:42
本文介绍了给定我有一个引用该控件的CWnd对象,是否有一种方法可以引用MFC对话框上的所有子窗口或控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个带有多个按钮的MFC对话框.(例如,红色",蓝色",绿色"和黄色"按钮)这些按钮都具有ID,例如("IDC_BUTT_RED","IDC_BUTT_BLUE","IDC_BUTT_GREEN","IDC_BUTT_YELLOW")

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")

鉴于我有一个CWnd对象,该对象引用了放置这些按钮的对话框窗口.有没有办法获取这些ID的列表?

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?

我知道有一个 CWnd :: GetNextDlgGroupItem 方法,该方法基于描述应该遍历一组控件.我尝试使用它,传入一个引用按钮之一的CWnd对象,然后调用 GetWindowText 方法进行检查,但是它始终返回对自身的引用.

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.

推荐答案

您可以使用EnumChildWindows枚举对话框的所有子窗口.这是一个C API函数,因此您可以使用并获取HWND而不是CWnd.当每个子窗口的HWND传递给回调函数时,您可以调用GetClassName查找其窗口类名称(例如"BUTTON"),并调用GetWindowLong查找其ID.

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.

这篇关于给定我有一个引用该控件的CWnd对象,是否有一种方法可以引用MFC对话框上的所有子窗口或控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆