MFC resource.h命令/消息ID [英] MFC resource.h command/message IDs

查看:458
本文介绍了MFC resource.h命令/消息ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个MFC应用程序,这是多年来和不同的开发团队很混乱。包含所有命令/消息映射的resource.h文件随着时间的推移变得相当大,并且有很多问题(如重复的ID)。我不熟练MFC,所以这个问题可能听起来很愚蠢...



MSDN文档提到命令ID和消息ID不应小于WM_USER和WM_APP 。我看到Visual Studio中生成的resource.h中的大多数命令ID大约从100开始。这不会导致一些干扰MFC / Windows命令和消息,与应用程序定义的ID重叠?例如,我有一个命令ID:

  #define ID_MY_ID 101 
pre>

并且有一个具有相同ID的Windows命令。当MC将此命令发送到APP时,它会像应用程序定义的ID_MY_ID一样处理,并且应用程序正在采取不必要的操作。这是一种可能的情况吗?



此外,是否有一些第三方工具可以帮助分析项目资源?



更新1:



新问题出现了:
向应用程序类添加新的自定义命令的首选方法是什么?正如我所理解的,在他们以下面的方式添加之前:添加一个命令ID到resouce.h,然后添加一个消息映射处理程序到处理类。

解决方案

您正在混合两件事:


  1. 消息ID。这些必须大于WM_USER。消息ID未在resource.h中定义。根据您的说明,您似乎未使用应用程式私人讯息。

  2. 命令ID。您的应用程序本身不能有重复的命令ID。命令ID值也不应干扰afxres.h中定义的标准MFC标识。这些命令ID从0xE100开始,因此resource.h中的值不太可能。资源编译器将在rc文件中为重复的ID生成错误

可能没有必要手动编辑resource.h 。



我建议使用资源符号工具(右键单击资源视图中的资源,从弹出菜单中选择,我假设你使用VC ++)从resource.h中删除所有未使用的ID。


I'm working on an MFC application, that got pretty messy over years and over different teams of developers. The resource.h file, which contains all command/message mappings grew pretty big over time, and has lots of problems (like duplicate IDs). I am not proficient with MFC, so the question might sound pretty stupid...

MSDN docs mention that Command IDs and Message IDs should not be less than WM_USER and WM_APP correspondingly. I saw that most of the command IDs in resource.h generated by Visual Studio begin around 100. Shouldn't this cause some interfering with MFC/Windows commands and messages, that overlap with the application defined IDs? For example, I have a command ID :

#define ID_MY_ID 101

and there is a windows command that has the same ID. When MC send this command to the APP, it's handled like an application defined ID_MY_ID, and the app is taking unnecessary actions. Is it a possible scenario?

Also, is there some third party tool that helps to profile the project resources?

Update 1:

New question showed up: What is the preferred way of adding new custom commands to the application classes? As I understood, before they were added in the following way: add a command ID to the resouce.h, and then add a message map handler to the handling class.

解决方案

You are mixing two things:

  1. Message IDs. These must be larger than WM_USER. Message IDs are not defined in resource.h. It seems from your description that you are not using application private messages.
  2. Command IDs. Your application itself must not have duplicate command IDs. The command ID values should also not interfere with the standard MFC IDs defined in afxres.h. Theses command IDs start at 0xE100, so it is unlikely that the values in resource.h. The resource compiler will generate an error for duplicate IDs in you rc file

There is probably no need for you to edit resource.h manually.

I would recommend to use the "Resource symbols" tool (right click on the resources in resource view and choose from the popup menu, I assume you are using VC++), to remove all the unused IDs from resource.h.

这篇关于MFC resource.h命令/消息ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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