Modeless windows
-
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();
-
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();
If your modeless dialogs are bell behaved, then they auto-
delete
inPostNcDestroy
. The problem is thatm_pStats
will be non-NULL
even after the window it formerly pointed to has gone into oblivion. You can try the following approach. Define aCStats **
member intoCStats
just like this:class CStats
{
...
CStats ** m_myself;
};After calling
new CStats
and beforeCreate
usem_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 setm_pStats
toNULL
:Void CStats::PostNcDestroy()
{
*m_myself=NULL;
delete this;
}Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
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();
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
-
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
-
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();
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.
-
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
-
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.