CWnd :: CreateDlgIndirect离开m_hWnd == NULL [英] CWnd::CreateDlgIndirect leaves m_hWnd==NULL

查看:324
本文介绍了CWnd :: CreateDlgIndirect离开m_hWnd == NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的对话框未显示,使用:

A dialog I'm working on isn't displaying, using:

CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,CWnd* pParentWnd, HINSTANCE hInst)

对CreateDlgIndirect的调用是在一个长期使用的基类中,它有效地获取了资源文件中对话框模板的IDD-在其他许多对话框中也可以正常使用,但是我看不到对话框有什么不同.以更常规的方式创建对话框时,我的对话框可以正常工作,但是我必须使用基类,因为它内置了许多其他功能.

The call to CreateDlgIndirect is in a lon-used base-class, which effectively takes the IDD of the dialog template in the resource file - it works fine for many other dialogs but I can't see what's different in my dialog. My dialog works fine when created in a more normal way, but I have to use the base class as it has loads of other functionality built in.

我在dlgcore.cpp中通过CWnd :: CreateDlgIndirect拖网时发现的是,普通的Win32 API调用失败了:

What I find when trawling through CWnd::CreateDlgIndirect in dlgcore.cpp, is that the plain Win32 API call is failing:

hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate,pParentWnd->GetSafeHwnd(), AfxDlgProc);

由于某种原因我无法进入该功能,所以我所看到的是HWND为NULL.

I can't step into that function for some reason, so all I see is the HWND is NULL.

任何人都可以提出可能导致这种情况的问题吗?我比较了两个对话框资源模板,它们的属性是相同的.

Can anyone suggest what kind of problems might be causing this? I compared the two dialog resource templates and their properties are the same.

我在对话框上有一个自定义控件.当我删除它时,它可以工作.不知道为什么,这会有什么不同?

edit: I have one custom control on the dialog. When I remove this, it works. No idea why, what difference might this make?

推荐答案

CreateDialogXXX失败的一种比较晦涩的方法是让对话框上的子控件失败.通常是因为应用程序在尝试进行对话框创建之前尚未初始化公共控件库.请参见 InitCommonControlsEx

One of the more obscure ways for CreateDialogXXX to fail is for a child control on the dialog to fail creation. Usually because the application has not initialized the common controls library before attempting to effect the dialog creation. See InitCommonControlsEx

一种检查方法是在资源编辑器中打开对话框,转到对话框的属性,然后找到并打开DS_NOFAILCREATE标志.通常称为模糊的名称,例如"No Fail Create".或直接将DS_NOFAILCREATE添加到内存中的对话框模板中.这将使对话框显示出来,而罪魁祸首应该因其不存在而明显.

One way to check this is to open the dialog in the resource editor, go to the dialog's properties, and find and turn on the DS_NOFAILCREATE flag. Usually called something obscure like "No Fail Create". Or add the DS_NOFAILCREATE directly to your dialog template in memory. This will allow the dialog to show, and the culprit should be evident by its absence.

在子控件是实际的自定义控件的情况下-自定义窗口类要么未正确注册,要么根本未注册.检查注册中使用的HINSTANCE-除非指定了CS_GLOBAL标志,否则窗口类由(hInstance,ClassName)标识-这样可以防止在不同dll中使用相同名称的窗口类发生冲突.

In the case that the child control is an actual custom control - well the custom window class is either not registered correctly, or at all. Check the HINSTANCE used in registration - unless the CS_GLOBAL flag is specified, window classes are identified by (hInstance, ClassName) - this prevents window classes using the same name in different dlls conflicting.

这篇关于CWnd :: CreateDlgIndirect离开m_hWnd == NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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