在带有DLL对话框的CWinThread中使用CDialog :: DoModal [英] Using CDialog::DoModal in a CWinThread with a DLL Dialog

查看:51
本文介绍了在带有DLL对话框的CWinThread中使用CDialog :: DoModal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个常规的MFC DLL,它具有对话框资源和类.如果我从应用程序中使用DoModal()调用对话框而不使用线程,则一切正常.如果我从CWinThread使用DoModal()调用对话框,则会显示该对话框,但其父级不是我的应用程序,因此它的行为类似于无模式对话框,即当对话框仍显示时,我可以单击回到我的应用程序.哪个不好.

我特别制作了一个很小的项目来演示该问题,它在此处(不确定是否存在库,用于代码项目问题..?),所以如果有人感兴趣,也许可以看看吗?

感谢您的任何建议.

Hello,

I have a regular MFC DLL, which has a dialog resource and class. If I call the dialog with DoModal() from my app without using threading, all is OK. If I call the dialog with DoModal() from a CWinThread, the dialog shows, but its parent is not my app, so it kind of behaves like a modeless dialog, ie I can click back to my app when the dialog is still showing. Which is not great.

I especially made a very small project which demonstrates the problem, it''s here (not sure if there is a repository to use for codeproject questions..?), so if anyone is interested maybe they can have a look please?

Thanks for any advice.

推荐答案

我最好的支付模型dailog的方法是使用AfxLoadLibrary()

这可能不被您接受,但
试试这个,
在dll专案中
您有一个对话框,
定义
My best way of dispaying model dailog is using AfxLoadLibrary()

This may be not you accepted but,
try this,
in dll project
you have a dialog,
Define
__declspec (dllexport)void WINAPP DllCall(){
 CYouDlg myDlg;
 myDlg.DoModel();
}



并在调用项目时定义



and in calling project define

extern void WINAPP DllCall()


在调用类的顶部.

然后


at the top of the calling class.

and then

HINSTANCE TempHandle;
TempHandle=AfxLoadLibrary("YourDllName");
SetResourceHandle(TempHandle);
DllCall();



这项工作与使用相同方法为50个对话框实现dll一样好.
使用线程的dll给链接带来了一些时间问题.

本文可能会为您提供帮助.
Dll链接 [



this work so fine as implemented dll for 50 dialogs using same methods.
dll using Threads gives some time problem of linking.

This article may help you.
Dll linking[^]
its just suggestion
Thanks.


我仍然不确定您遇到的确切问题是什么,但是使用您的示例,您可以将父对话框一直传递到winThread并进入对话框,然后停止单击隐藏隐藏窗口.

所以:

启动将父级传递给对话框的对话框
I''m still not sure what the exact problem you are having is but, using your example you can pass the parent dialog all the way through to the winThread and onto the dialog, this then stops clicking behide loosing the window.

so:

Starting the dialog passing in the parent which is this
::PostThreadMessage (mMyThread->m_nThreadID, RUNDLGMSG, (WPARAM)mRunDLLDialogs, (LPARAM)this);



更改了您的功能以接受父级



Changed your function to accept the parent

_declspec(dllexport) void runDLLDlg (CWnd*);

>

在lParam中通过了父级



Passed the parent through in lParam

void MyThread::RunDlg(WPARAM wParam, LPARAM lParam)
{
    if (wParam != 0)
    {
        runDLLDlg ((CWnd*)lParam);
    } else {
        Dlg1 dlg1((CWnd*)lParam);
        dlg1.DoModal();
    }
}



一路穿过



pass all the way through

void runDLLDlg (CWnd* pParent)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	DLLDlg1 dlg1(pParent);
	dlg1.DoModal();
}


这篇关于在带有DLL对话框的CWinThread中使用CDialog :: DoModal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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