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. Modeless windows

Modeless windows

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

    Hi, I have an app that has a few modeless windows....I have a menu that allows the user to bring up a couple of these windows individually. My problem is that one window has an options that when selected brings up one of the previous windows. I want it to set the focus to the opened window instead of creating a duplicate. I thought i had a solution but it doesn't work. Can someone help me please? THANKS in advance. Here is my code. I thought this code would work but it doesn't.

    if (m_pStats== NULL)
    {
         m_pStats= new CStats;
         
         if (m_pStats->Create(IDD_STATS) == TRUE)
              m_pStats->ShowWindow(SW_SHOW);
    }
    
    else
         m_pStats->SetActiveWindow();
    
    J T J 3 Replies Last reply
    0
    • J Jay Hova

      Hi, I have an app that has a few modeless windows....I have a menu that allows the user to bring up a couple of these windows individually. My problem is that one window has an options that when selected brings up one of the previous windows. I want it to set the focus to the opened window instead of creating a duplicate. I thought i had a solution but it doesn't work. Can someone help me please? THANKS in advance. Here is my code. I thought this code would work but it doesn't.

      if (m_pStats== NULL)
      {
           m_pStats= new CStats;
           
           if (m_pStats->Create(IDD_STATS) == TRUE)
                m_pStats->ShowWindow(SW_SHOW);
      }
      
      else
           m_pStats->SetActiveWindow();
      
      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      If your modeless dialogs are bell behaved, then they auto-delete in PostNcDestroy. The problem is that m_pStats will be non-NULL even after the window it formerly pointed to has gone into oblivion. You can try the following approach. Define a CStats ** member into CStats just like this:

      class CStats
      {
      ...
      CStats ** m_myself;
      };

      After calling new CStats and before Create use m_myself to let the window know about the variable pointing to it:

      if (m_pStats== NULL){
      m_pStats= new CStats;
      m_pStats->m_myself=&m_pStats;
      ...

      Now, in PostNcDestroy you can take advantage of this variable to set m_pStats to NULL:

      Void CStats::PostNcDestroy()
      {
      *m_myself=NULL;
      delete this;
      }

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      1 Reply Last reply
      0
      • J Jay Hova

        Hi, I have an app that has a few modeless windows....I have a menu that allows the user to bring up a couple of these windows individually. My problem is that one window has an options that when selected brings up one of the previous windows. I want it to set the focus to the opened window instead of creating a duplicate. I thought i had a solution but it doesn't work. Can someone help me please? THANKS in advance. Here is my code. I thought this code would work but it doesn't.

        if (m_pStats== NULL)
        {
             m_pStats= new CStats;
             
             if (m_pStats->Create(IDD_STATS) == TRUE)
                  m_pStats->ShowWindow(SW_SHOW);
        }
        
        else
             m_pStats->SetActiveWindow();
        
        T Offline
        T Offline
        Toni78
        wrote on last edited by
        #3

        While Joaquin brings I up a very good point I have a different suggestion. Instead of m_pStats->SetActiveWindow() try m_pStats->BringWindowToTop() and then m_pStats->SetFocus(). // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        J 1 Reply Last reply
        0
        • T Toni78

          While Joaquin brings I up a very good point I have a different suggestion. Instead of m_pStats->SetActiveWindow() try m_pStats->BringWindowToTop() and then m_pStats->SetFocus(). // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

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

          Toni, This does not do anything different from what I had. Do you have any other ideas....it is beginning to drive me crazy to have all these duplicate screens. ;P Thanks again for your help

          T 1 Reply Last reply
          0
          • J Jay Hova

            Hi, I have an app that has a few modeless windows....I have a menu that allows the user to bring up a couple of these windows individually. My problem is that one window has an options that when selected brings up one of the previous windows. I want it to set the focus to the opened window instead of creating a duplicate. I thought i had a solution but it doesn't work. Can someone help me please? THANKS in advance. Here is my code. I thought this code would work but it doesn't.

            if (m_pStats== NULL)
            {
                 m_pStats= new CStats;
                 
                 if (m_pStats->Create(IDD_STATS) == TRUE)
                      m_pStats->ShowWindow(SW_SHOW);
            }
            
            else
                 m_pStats->SetActiveWindow();
            
            J Offline
            J Offline
            Jay Hova
            wrote on last edited by
            #5

            Hi, First off, thanks for the suggestions and help. I tried both and they did not work for what I want. Maybe I should explain better. I have one window called stats and one window called config. Each having their own menu option to display them. If I constantly use the menu item to bring up stats it works fine with the code I wrote, continuously setting focus to the opened window instead of creating a new one. My problem is when i bring up the config window. When "ok" is hit on my config window it should open the stat window if it is closed or just set focus to it. No matter if i display the stats window and the bring up the config window, or if i just repeatedly bring up the config window it will continue to make new instances of the stats window everytime config is brought up. Can someone help me solve this problem so that only one stats window is displayed no matter how i use the menu? THANKS IN ADVANCE! Any help would be appreciated, this is beginning to drive me nuts.

            M 1 Reply Last reply
            0
            • J Jay Hova

              Toni, This does not do anything different from what I had. Do you have any other ideas....it is beginning to drive me crazy to have all these duplicate screens. ;P Thanks again for your help

              T Offline
              T Offline
              Toni78
              wrote on last edited by
              #6

              Jay Hova wrote: Do you have any other ideas Unfortunately, I don't. Sorry! // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

              1 Reply Last reply
              0
              • J Jay Hova

                Hi, First off, thanks for the suggestions and help. I tried both and they did not work for what I want. Maybe I should explain better. I have one window called stats and one window called config. Each having their own menu option to display them. If I constantly use the menu item to bring up stats it works fine with the code I wrote, continuously setting focus to the opened window instead of creating a new one. My problem is when i bring up the config window. When "ok" is hit on my config window it should open the stat window if it is closed or just set focus to it. No matter if i display the stats window and the bring up the config window, or if i just repeatedly bring up the config window it will continue to make new instances of the stats window everytime config is brought up. Can someone help me solve this problem so that only one stats window is displayed no matter how i use the menu? THANKS IN ADVANCE! Any help would be appreciated, this is beginning to drive me nuts.

                M Offline
                M Offline
                mlsteeves
                wrote on last edited by
                #7

                Try this:if( IsWindow( m_pStats.m_hWnd ) == FALSE ) { //create m_pStats window } else { //Set m_pStats active }

                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