Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Use Modeless Dialog inside MFC DLL

Use Modeless Dialog inside MFC DLL

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++toolshelptutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andraw Tang
    wrote on last edited by
    #1

    Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!

    O H N 3 Replies Last reply
    0
    • A Andraw Tang

      Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!

      O Offline
      O Offline
      Ozer Karaagac
      wrote on last edited by
      #2

      You can simply pass NULL to CDialog constructor as parent window. In this case, MFC searches a proper one. If it doesn't find any, dialog's parent window is set to the main application window. You also don't have to use above constructor for modeless dialog boxes. You can use default constructor then you can specify parent window later by Create() function.

      m_pDlg = new CMymfc9Dialog();

      m_pDlg->Create(IDD_MYMFC9DIALOG, NULL); // or parent wnd instead of NULL

      m_pDlg->ShowWindow(SW_SHOW);

      A 1 Reply Last reply
      0
      • A Andraw Tang

        Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!

        H Offline
        H Offline
        Hans Dietrich
        wrote on last edited by
        #3

        In your DLL, put this function:

        void MyDLLClass::ShowDialog(CWnd *pWnd)
        {
        m_pDlg = new CMymfc9Dialog(pWnd); // m_pDlg is variable in MyDLLClass
        }

        In your app, call the ShowDialog() function.

        Best wishes, Hans


        [Hans Dietrich Software]

        A 1 Reply Last reply
        0
        • A Andraw Tang

          Hi, dear all, I am creating a MFC DLL utility program that will be used by client application through exported functions in DLL. Now I have to problem about how to create a modeless dialog in MFC dll. I searched some examples about creating modeless dialog in MFC exe application. Usually they create a dialog pointer in View class and initialize it as: m_pDlg = new CMymfc9Dialog(this); But my program is MFC DLL, there is no CView class, how can I initialize the m_pDlg? what argument should I pass to it? Thanks!

          N Offline
          N Offline
          Nitheesh George
          wrote on last edited by
          #4

          Hi, From your posting, I think that you wanted to a dialog box which is added a resource in your MFC dll. If I am right, It is a matter of simple. Please see the sample below. extern "C" __declspec(dllexport) showMyDialog(CWnd *parent) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); CDialog *myDialog = new CDialog(IDD_DIALOG1, parent); myDialog->ShowWindow(SW_NORMAL); } Make sure that you release the allocated memory in WM_NCDESTROY message handler code. Then about the code. There is a problem when we want to show a dialog from an MFC DLL. The MFC will using main application resource handle to find the specified resource. If you not specify the AFX_MANAGE_STATE(AfxGetStaticModuleState( )); at the begginig of the exported function, the MFC framework will try to find the resource in main application's resource. If the specified resource not found, then the showWindow fails and if found, MFC will try to load that resource may causing an unexpected behaviour. For more infomation see the MSDN documentation of AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Hope this helps Thanks Nitheesh George Nitheesh George http://www.simpletools.co.in

          A 1 Reply Last reply
          0
          • O Ozer Karaagac

            You can simply pass NULL to CDialog constructor as parent window. In this case, MFC searches a proper one. If it doesn't find any, dialog's parent window is set to the main application window. You also don't have to use above constructor for modeless dialog boxes. You can use default constructor then you can specify parent window later by Create() function.

            m_pDlg = new CMymfc9Dialog();

            m_pDlg->Create(IDD_MYMFC9DIALOG, NULL); // or parent wnd instead of NULL

            m_pDlg->ShowWindow(SW_SHOW);

            A Offline
            A Offline
            Andraw Tang
            wrote on last edited by
            #5

            Thanks! Now I use pMatTable = new CMatTable(this->m_pMainWnd); pass main window as parent window, it works now.

            1 Reply Last reply
            0
            • H Hans Dietrich

              In your DLL, put this function:

              void MyDLLClass::ShowDialog(CWnd *pWnd)
              {
              m_pDlg = new CMymfc9Dialog(pWnd); // m_pDlg is variable in MyDLLClass
              }

              In your app, call the ShowDialog() function.

              Best wishes, Hans


              [Hans Dietrich Software]

              A Offline
              A Offline
              Andraw Tang
              wrote on last edited by
              #6

              Thanks!

              1 Reply Last reply
              0
              • N Nitheesh George

                Hi, From your posting, I think that you wanted to a dialog box which is added a resource in your MFC dll. If I am right, It is a matter of simple. Please see the sample below. extern "C" __declspec(dllexport) showMyDialog(CWnd *parent) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )); CDialog *myDialog = new CDialog(IDD_DIALOG1, parent); myDialog->ShowWindow(SW_NORMAL); } Make sure that you release the allocated memory in WM_NCDESTROY message handler code. Then about the code. There is a problem when we want to show a dialog from an MFC DLL. The MFC will using main application resource handle to find the specified resource. If you not specify the AFX_MANAGE_STATE(AfxGetStaticModuleState( )); at the begginig of the exported function, the MFC framework will try to find the resource in main application's resource. If the specified resource not found, then the showWindow fails and if found, MFC will try to load that resource may causing an unexpected behaviour. For more infomation see the MSDN documentation of AFX_MANAGE_STATE(AfxGetStaticModuleState( )); Hope this helps Thanks Nitheesh George Nitheesh George http://www.simpletools.co.in

                A Offline
                A Offline
                Andraw Tang
                wrote on last edited by
                #7

                Thanks for reminding me, I do get application crash since I didn't use AFX_MANAGE_STATE(AfxGetStaticModuleState()) at first.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups