gpt4 book ai didi

c++ - 当 CDialog.DoModal() 函数无法创建对话框时?

转载 作者:可可西里 更新时间:2023-11-01 13:26:20 24 4
gpt4 key购买 nike

MSDN说,对于CDialog.DoModal()函数,如果函数不能创建对话框,返回值为-1。它没有说明在哪种情况下它可能无法创建对话框。

对 MFC 源代码的快速调查表明,如果 (LPCDLGTEMPLATE)LockResource(hDialogTemplate) 返回 NULL,则 DoModal 函数可能返回 -1。

由于我的问题在我们的压力测试中无法稳定复现,所以我无法调试程序找到根本原因。这里有人遇到过类似的问题吗?

最佳答案

DoModal() 依赖于 CreateDialogIndirect() API函数。其堂兄的文档 DialogBox()声明函数在以下情况下可能会失败:

  • an invalid parameter value,
  • the system class was registered by a different module,
  • the WH_CBT hook is installed and returns a failure code,
  • one of the controls in the dialog template is not registered, or its window procedure fails on WM_CREATE or WM_NCCREATE.

前三个原因我个人没遇到过,但是被第四个咬了一次,因为我的对话框里面有一个没有在机器上注册的ActiveX控件。也许您遇到了同样的问题。

关于c++ - 当 CDialog.DoModal() 函数无法创建对话框时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9703083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com