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. Duplicate Dialogs

Duplicate Dialogs

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 3 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.
  • J Offline
    J Offline
    Jay Hova
    wrote on last edited by
    #1

    Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method. if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow(); THANKS in advance.

    R G J 3 Replies Last reply
    0
    • J Jay Hova

      Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method. if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow(); THANKS in advance.

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      Are you using the same pointer in your dialog class as you are when you use the menu? Yes, I know it's a silly question, but I can't really think of any other reason why it wouldn't work. The other thing you could try is to send a WM_COMMAND message corresponding to your menu item, so that all the window stuff is done in the same place. That would probably simplify things. I think this was mentioned before, but it's what I would do, so I'll mention it again :) Hope this helps,

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      J 1 Reply Last reply
      0
      • R Ryan Binns

        Are you using the same pointer in your dialog class as you are when you use the menu? Yes, I know it's a silly question, but I can't really think of any other reason why it wouldn't work. The other thing you could try is to send a WM_COMMAND message corresponding to your menu item, so that all the window stuff is done in the same place. That would probably simplify things. I think this was mentioned before, but it's what I would do, so I'll mention it again :) Hope this helps,

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        J Offline
        J Offline
        Jay Hova
        wrote on last edited by
        #3

        I am not using the same pointer....I don't know how to get the two classes to communicate with each other. Could you please show me how to get one pointer from one class to another one? I tried to do this, but was couldn't get the code to compile correctly. How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. THANKS FOR YOUR HELP.

        R 1 Reply Last reply
        0
        • J Jay Hova

          I am not using the same pointer....I don't know how to get the two classes to communicate with each other. Could you please show me how to get one pointer from one class to another one? I tried to do this, but was couldn't get the code to compile correctly. How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. THANKS FOR YOUR HELP.

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          Jay Hova wrote: How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. Say your menu item was ID_SHOWDIALOG (for example). You would send a message to your frame window exactly the same as what Windows does when a menu option is chosen.

          AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_SHOWDIALOG, NULL);

          Hope this helps,

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          J 1 Reply Last reply
          0
          • R Ryan Binns

            Jay Hova wrote: How would I do the option you mention about the WM_COMMAND? I do not totally understand what you mean by this. Say your menu item was ID_SHOWDIALOG (for example). You would send a message to your frame window exactly the same as what Windows does when a menu option is chosen.

            AfxGetMainWnd()->PostMessage(WM_COMMAND, ID_SHOWDIALOG, NULL);

            Hope this helps,

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            J Offline
            J Offline
            Jay Hova
            wrote on last edited by
            #5

            I'm sorry for being so slow with this, but what does this exactly do. How will this solve my problem? Also where would i put this code. The code that I posted originally is the same code I use for both menu items... Thanks again for your help and understanding

            R 1 Reply Last reply
            0
            • J Jay Hova

              I'm sorry for being so slow with this, but what does this exactly do. How will this solve my problem? Also where would i put this code. The code that I posted originally is the same code I use for both menu items... Thanks again for your help and understanding

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              Ok. Basically, using that piece of code will simulate in software exactly what happens when the user selects a menu item. You would put this code where you handle the radio button being pressed, so that pressing the radio button behaves the same as selecting a menu item. This means that the code to actually display the dialog would only be in one place, and should solve your problem. Hope this helps,

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              J 1 Reply Last reply
              0
              • J Jay Hova

                Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method. if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow(); THANKS in advance.

                G Offline
                G Offline
                G Steudtel
                wrote on last edited by
                #7

                Hi, I feel sorry for my short and as I thought understandable answer. I didnot know, that you never coded before. So let me dig a little deeper with this answer. In your main application class you should have a pointer to or an instance of class CMainCommand. This pointer or instance must be used by all calls to open the dialogs. Have a look at the headerfile of your application class to find out, wheter the CMainCommand thing is private/protected or public. In the application headerfile add a member function: CMainCommand* GetCommandPointer(void); Assuming it is a pointer (lets call it pMainCommand) write in the applications cpp-file CMainCommand* CWinApp::GetCommandPointer(void) { return pMainCommand;} Of course you have to substitute CWinApp and pMainCommand with the names of the actual class name and variable name. If you do not use a pointer, but an instance of the class replace pMainCommand with &mainCommand; In your OnOk handler write m_pCommantOpt = DYNAMIC_DOWNCAST(CWinApp,AfxGetApp())->GetCommandPointer(); Here too you have to substitute the CWinApp with the actual name of your application class. Also you have to include the applications header file into your cpp file. (But this should be done already by class wizard) This line above does: It retrieves a pointer to the application class instance, casts it to your application class and after the casting calls GetCommandPointer. Then delete the line where you create an new instance of CMainCommand, bailing out, when the pointer is inavlid and tell the user that someting went wrong. m_pCommantOpt = DYNAMIC_DOWNCAST(CWinApp,AfxGetApp())->GetCommandPointer(); if( m_pCommandOpt != NULL ) { m_pCommandOpt = new CMainCommand(this); if( m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE ) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } else { m_pCommandOpt->SetActiveWindow(); } } else AfxMessagebox("Something went wrong"); Regards G.Steudtel

                1 Reply Last reply
                0
                • R Ryan Binns

                  Ok. Basically, using that piece of code will simulate in software exactly what happens when the user selects a menu item. You would put this code where you handle the radio button being pressed, so that pressing the radio button behaves the same as selecting a menu item. This means that the code to actually display the dialog would only be in one place, and should solve your problem. Hope this helps,

                  Ryan

                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                  J Offline
                  J Offline
                  Jay Hova
                  wrote on last edited by
                  #8

                  Many thanks Ryan. You just solved my problem that I have spent way too many hours on. Worked like a charm.

                  R 1 Reply Last reply
                  0
                  • J Jay Hova

                    Many thanks Ryan. You just solved my problem that I have spent way too many hours on. Worked like a charm.

                    R Offline
                    R Offline
                    Ryan Binns
                    wrote on last edited by
                    #9

                    You're welcome :)

                    Ryan

                    "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                    1 Reply Last reply
                    0
                    • J Jay Hova

                      Hi, I posted this last week, and tried to work on this over the weekend but with no success. This is something that i can't seem to figure out. Can someone tell me how to do this exactly? I never really coded before and this is causing me much headaches. This was the suggestion that I received from G.Steudtel: Try to get the applications pointer of its CMainCommand instance, and use this pointer. Or send/post the command to the application as if the user has selected the dialog via the menu. Here is what I posted: I have a modeless window and a modal window, each having their own window option that when selected bring up the corresonding window. The modal window has radio buttons on it, so when a specific reaio button is selected and ok is entered, it will display the modless window. When I select the menu to bring up the modeless window it works fine, only opens one window or sets focus to it if it has not been created. When I select the modal window and check the appropriate radio it will display the modeless window regardless if it is created already. It will just continue to duplicate the modeless window. Can someone help me out so that it will set focus on the open window and not diplicate it. currently I am using this code in the OnOK method. if (!m_pCommandOpt) { m_pCommandOpt = new CMainCommand(this); if (m_pCommandOpt->Create(IDD_MAIN_TAB_DIALOG) == TRUE) { GetDlgItem(IDOK)->EnableWindow(FALSE); m_pCommandOpt->ShowWindow(SW_SHOW); } } else m_pCommandOpt->SetActiveWindow(); THANKS in advance.

                      J Offline
                      J Offline
                      Jay Hova
                      wrote on last edited by
                      #10

                      Thanks for all the help. I finally got it and it works just like you said it would. THANKS AGAIN!

                      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