MFC 类似控件数组实现方法

本文指导如何在MFC项目中调整控件ID,使之连续,以便通过ID访问类似数组操作。通过修改resource.h文件和理解_APS_NEXT_CONTROL_VALUE的作用,确保新添加控件ID的连续性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

如果控件的ID是连续的,就可以通过访问ID的方式来实现相当于控件数组的循环操作。

1、打开项目resource.h文件
2、首先要让IDC_CMB_hometype0-7,的ID连续

......
#define IDC_CMB_hometype0               1182
#define IDC_CMB_hometype1               1183
#define IDC_CMB_hometype2               1184
#define IDC_CMB_hometype3               1185
#define IDC_CMB_hometype4               1186
#define IDC_CMB_hometype5               1187
#define IDC_BUTTON1                 	1188
#define IDC_BUTTON2                     1189
#define IDC_CMB_hometype6               1191
#define IDC_CMB_hometype7               1192

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        131
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1189
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

修改为:

#define IDC_CMB_hometype0               1182
#define IDC_CMB_hometype1               1183
#define IDC_CMB_hometype2               1184
#define IDC_CMB_hometype3               1185
#define IDC_CMB_hometype4               1186
#define IDC_CMB_hometype5               1187
#define IDC_CMB_hometype6               1188
#define IDC_CMB_hometype7               1189
#define IDC_BUTTON1                 	1190
#define IDC_BUTTON2                     1191

3、注意:
_APS_NEXT_CONTROL_VALUE 值为 1189,改为1192。
以免界面后加的控件占用前面的ID值。后加的控件ID号从1192开始。

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        131
#define _APS_NEXT_COMMAND_VALUE         32771
#define _APS_NEXT_CONTROL_VALUE         1192
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

这样就可以得到连续的ID值,便于后续像数组一样访问ID值操作控件。

4、程序文件中

#define IDC_CMB_hometype_BaseAddr               1182

所有控件可以通过地址顺序累加来访问

IDC_CMB_hometype_BaseAddr + i

感谢:
MFC中修改控件的ID号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值