如何确切地找到调用哪个Dialog类DoModal()? [英] How to find exactly for which Dialog class DoModal() is called?

查看:106
本文介绍了如何确切地找到调用哪个Dialog类DoModal()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC应用程序中工作,它有很多对话框。调试时我无法分辨哪个类或函数创建对话框。



为了说明问题,我创建了一个简单的基于对话框的MFC应用程序。在调试模式下运行它并暂停调试。



我可以看到使用CDialog :: DoModal()在调用堆栈中调用DoModal。我如何准确理解哪个函数以及从哪个类调用DoModal()?

解决方案

请参阅我对该问题的评论。可能需要在某个地方设置断点。 调用堆栈是否显示堆栈中的所有调用,而不是向下?我希望你理解它,并从这个调试窗口中看到。这意味着,它会向您显示已经引导您到达断点的所有调用函数的调用。你无法看到从给定点调用的内容;基本上,你需要看到的还没有被调用。您可以使用逐步调试来执行,但可能需要花费太多时间。



所以,你必须把断点放到所有地方 CDialog :: DoModal 并在所有情况下检查实例,但也可能会变得太长。所以,正如你所知(据我所知),不同的对话类,你必须在每个类的某个方法中加上一个断点。但是哪里?我想,问题是这个方法在基类中,所以你不能在不同的终端类上放置不同的断点。怎么做?



您可以添加一些专门用于调试的代码。请注意 CDialog :: DoModal 是一种虚拟方法:

http://msdn.microsoft.com/en-us/library/619z63f5.aspx [ ^ ]。



这意味着你可以覆盖它在所有对话框类中,仅用于调试目的。写一些简单的实现,调用base的 CDialog :: DoModal 。它的唯一目的是为每个类在此行上设置一个断点。通过这种方式,您将看到在某些操作上调度调用的位置。



我试图解释一些基本的调试技术;而且它们并不那么容易解释。然后更容易发明一种调试技术,然后用简单的单词解释它是如何工作的,而不进行演示。还有很多其他的。他们在调试过程中提出了一些经验和逻辑思维。一般来说,尝试做更多的分析和逻辑思考,减少尝试次数,减少试错操作。



-SA

I am working in MFC application which has lots of dialog box. I am not able to tell which class or function created dialog box while debugging.

To illustrate the problem I have created a simple Dialog based MFC application. Run it in debug mode and pause the debugging.

I can see DoModal is called in call stack using CDialog::DoModal(). How do I understand exactly which function and from which class this DoModal() is getting called?

解决方案

Please see my comment to the question. Probably, you need to set a break point at certain place. Isn't it obvious that "Call stack" shows all calls up the stack, not down? I hope you understand it and can see from this debug window. It means, it shows you the calls which already led you to the break point, all calling functions. You cannot see what is called from a given point; essentially, what you need to see wasn't yet called. You can follow the execution using step-by-step debugging, but it may take too much time.

So, you have to put break-point to all places where CDialog::DoModal and examine the instance in all case, but it also might become too long. So, as you have (as far as I could understand), different dialog classes, you have to put a break point in some method of each class. But where? I guess, the problem is that this method is in the base class, so you cannot put different break points on your different terminal classes. What to do?

You can add some code specially for debugging. Pay attention that CDialog::DoModal is a virtual method:
http://msdn.microsoft.com/en-us/library/619z63f5.aspx[^].

It means that you can override it in all your dialog classes in question, just for debugging purpose. Write some trivial implementation calling the base's CDialog::DoModal. The only purpose of it is to put a break point on this line, for each of your classes. This way, you will see where the calls are dispatched on certain action.

I tried to explain only some of the basic debugging technique; and they are not so easy to explain. It's easier to invent a debugging technique then to explain how it works in simple words, without demonstrating it. There are many others. They come up with some experience and logical thinking during debugging. Generally, try to do more analysis and logical thinking and less attempts, less of trial-and-error operations.

—SA


这篇关于如何确切地找到调用哪个Dialog类DoModal()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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