创建一个类似于regedit的应用程序
我想创建一个与 regedit 执行相同操作的应用程序,但更简单,因为我只想以树的形式枚举键。我正在尝试使用 RegOpenKeyEX 打开一个键,然后使用 RegEnumKeyex 来枚举它,但即使我递增索引值,我仍然会枚举相同的键。
第二个问题是,递归在此应用程序中是否有帮助?
提前致谢
I want to create an application which does the same stuff as regedit, but simpler as i just want to enumerate the Keys in the form of a tree. I am trying to use RegOpenKeyEX to open a key and then RegEnumKeyex to enumerate it, but i keep getting the same key enumerated, even though i am incrementing the Index value.
Second question is, will recursion be helpful in this application.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这个代码示例将帮助您了解代码中出了什么问题:
http://msdn.microsoft.com/en- us/library/ms724256(v=vs.85).aspx。
至于第二个问题。在此应用程序中,递归可能会帮助您构建您通常在左侧的 regedit 中看到的键树。
Perhaps this code sample will help you understand what went wrong in your code:
http://msdn.microsoft.com/en-us/library/ms724256(v=vs.85).aspx.
As for the second question. Recursion will probably help you in this application in order to build the Keys tree that you usually see in regedit on the left.
您可能不想为此使用递归。递归会深度优先遍历三个。您通常想要的是增量广度优先遍历。
您通常会通过使用标准顶级节点(KHLM、HKCU 等)创建显示树并使用
I_CHILDRENCALLBACK
告诉它每个节点都有子节点来实现此目的。然后,当用户展开节点时,您将收到 TVN_ITEMEXPANDING 通知。对此,您只需枚举该节点下的一级项目并将它们插入到显示树中。同样,对于每个可能有子节点的节点,您可以使用 I_CHILDRENCALLBACK 让它执行回调,表明它有子节点。
编辑:我还应该提到:您引用的第一个问题(似乎重复枚举相同的项目)的一个常见原因是未能在每次迭代时更新名称参数的长度。它是一个输入/输出参数,设置为每次调用时检索的当前名称的长度。例如:
You probably don't want to use recursion for this. Recursion will traverse the three depth-first. What you usually want is an incremental breadth-first traversal.
You'll typically do that by creating your display tree with the standard top-level nodes (KHLM, HKCU, etc.) and use
I_CHILDRENCALLBACK
to tell it that each of those has child nodes.Then, when the user expands a node, you'll receive a TVN_ITEMEXPANDING notification. In response to that, you enumerate exactly one level of items under that node and insert them into your display tree. Again, for each that might have children, you use
I_CHILDRENCALLBACK
to have it do a callback that says it has child nodes.Edit: I should also mention: one common reason for the first problem you cite (seeming to get the same item enumerated repeatedly) is failing to update the length of name parameter every iteration. It's an in/out parameter that gets set to the length of the current name being retrieved at each call. For example: