简体   繁体   English

将焦点放在MFC视图中托管的无模式对话框上

[英]Set focus on a modeless dialogs hosted in an MFC view

I have an MFC view, and I have another project which implements and MFC dialog. 我有一个MFC视图,还有另一个实现和MFC对话框的项目。 I want to host the dialog in my view. 我想在我的视图中托管对话框。 My view is of class CFormView. 我的观点是CFormView类。

I did it that way in my view code: 我是在我的视图代码中这样做的:

m_myDialog->Create(myDialog::IDD, this);

Now, I see my dialog, but I can't set focus on it and can't use it. 现在,我看到了对话框,但是我无法专注于该对话框并且无法使用它。

What do I have to change in order to host my dialog in my view, and be able to use it and set focus to it, just as part of the view? 为了在视图中托管对话框,并能够使用对话框并将焦点设置为视图的一部分,我必须进行哪些更改?

Thanks 谢谢

I know this is a few weeks old, but you need to provide more code or a better context of what is taking place. 我知道这已经使用了几周,但是您需要提供更多代码或更好的上下文信息。

I had a similar problem to yourself & found this hard to find info on when I first tried this. 我有一个与自己类似的问题,当我第一次尝试时发现它很难找到信息。 Following is an abstract of something I've used. 以下是我使用过的东西的摘要。 I'm sure there's probably a better way to do this, but I find it works the way I want; 我敢肯定有更好的方法可以做到这一点,但是我发现它可以按照我想要的方式工作。

        //MyApp.h

        class MyDialogClass;

        class MyApp : public CWinAppEx
        {
        public:
            MyApp();
            virtual BOOL InitInstance();
            //code etc
            MyDialogClass *p_myDlg;
        };


        //MyApp.cpp
        #include "MyApp.h"
        #include "CMyView.h"
        #include "mydialogclass.h"


        BOOL MyApp::InitInstance()
        {
        //code etc

            p_myDlg = CMyView::GetView()->p_myDlg;  

        //can be used here or elsewhere. I have mine linked with a button
            p_myDlg->ShowWindow(true);

        };


        //CMyView.h

        class MyDialogClass;

        class CMyView : public CFormView
        {
         protected: // create from serialization only
            CMyView();
            DECLARE_DYNCREATE(CMyView)

         public:
            enum{ IDD = IDD_CMyView_VIEW };

                static CMyView* GetView();
                MyDialogClass *p_myDlg;
            afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
        };


        //CMyView.cpp
        #include "MyApp.h"
        #include "CMyView.h"
        #include "mydialogclass.h"

        int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
        {
            if (CFormView::OnCreate(lpCreateStruct) == -1)
                return -1;

            p_myDlg = new MyDialogClass(this);

            return 0;
        }

        void CMyView::DisplayDialogFoo()
        {

           //can be used here or elsewhere. I have mine linked with a button
           p_myDlg->ShowWindow(true);

        }

        //mydialogclass.h
        class MyDialogClass : public CDialog
        {
            DECLARE_DYNAMIC(MyDialogClass)
         public:
            MyDialogClass(CWnd* pParent /*= NULL*/);
            enum { IDD = IDD_MyDialog_DLG };
        };

        //mydialogclass.cpp
        #include "mydialogclass.h"

        MyDialogClass::MyDialogClass(CWnd* pParent /*=NULL*/)
            : CDialog(MyDialogClass::IDD, pParent)
        {
            Create(IDD, pParent);
        }

There's also an article here I just found: http://www.codeproject.com/Articles/1651/Tutorial-Modeless-Dialogs-with-MFC 我在这里也发现了一篇文章: http : //www.codeproject.com/Articles/1651/Tutorial-Modeless-Dialogs-with-MFC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM