Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created Modeless dialog through another dialog in the WM_TIMER function.And my work is done with the dialog i want to distroy it automatically through code.So i have done in the following way


C++
OnTimer:
{
 ClsWindow *m_pWindow = new ClsWindow;
if(Aflag == true)

 m_pWindow ->Create(ClsWindow::IDD)
 m_pWindow->ShowWindow(SW_SHOW)
}

else
{

 m_pWindow->DestroyWindow()
}


The problem here is iam able to create the modeless dialog,but iam not able to destroy the window.This code works if i dont use the timer and if i use this in any button click event it works properly.I feel that as the timer is running continously its not able to destroy the window.Please suggest me to solve this.

Thanks in Advance.

[edit]code block added[/edit]
Posted
Updated 13-Nov-12 23:04pm
v2
Comments
Richard MacCutchan 14-Nov-12 5:04am    
What's the value of Aflag?
Rocky_Bas 14-Nov-12 5:14am    
Thats a bool flag,i use this flag to know when to create the window and when to destroy the window

1 solution

Every time you enter OnTimer you create a new ClsWindow and in case flag == false you destroy it. The pointer to the window you want to close was already lost after creation when leaving the OnTimer handler.
A property for ClsWindow *m_pWindow needs to be defined at class level and don't just overwrite it when entering the OnTimer.

OnTimer:
{ 
  if(Aflag == true)
  {
    m_pWindow = new ClsWindow;
    m_pWindow ->Create(ClsWindow::IDD)
    m_pWindow->ShowWindow(SW_SHOW)
  } else
  {
    m_pWindow->DestroyWindow()
  }
}


Good luck!
 
Share this answer
 
v2
Comments
Rocky_Bas 14-Nov-12 5:32am    
Yes i have diclared it out side the timer but still iam not able to destroy the window.
E.F. Nijboer 14-Nov-12 6:15am    
Did you also moved assigning the new ClsWindow inside the if? I changed my answer to give an idea what I mean. I also saw in your code given you omitted an { after the if statement. Maybe this was just a side effect when posting the code here, otherwise have a look at that as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900