CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2000
    Posts
    138

    Where to put KillTimer() in Dialog

    Where is the best place to put the KillTimer()? DestroyWindow or PostNcDestroy()? Will those functions always get called? Someone told me that DestroyWindow() never gets called, which seemed wierd.


  2. #2
    Join Date
    Sep 1999
    Location
    TVM, Kerala, India
    Posts
    210

    Re: Where to put KillTimer() in Dialog

    You can put it in the Destructor function of the dialog class.

    ~Kareem~

    --------------------------------------------
    If it is useful to you, you can rate it.....

  3. #3
    Join Date
    Jul 2004
    Posts
    48

    Re: Where to put KillTimer() in Dialog

    Are you sure?
    When I put it into the destructor of a modal dialog, I get an assertion failed when I close the window before timer expired.
    Exact error:
    Assertion failed in afxwin2.inl row: 181
    In this line I see:
    _AFXWIN_INLINE CWnd* CWnd::SetActiveWindow()


    Someone an idea? Thanks a lot.

  4. #4
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: Where to put KillTimer() in Dialog

    You cannot put it in destructor, because timer is a resource associated with window, and at the time destructor is execited, window is already destroyed. You should create a handler for WM_DESTROY message and kill timer there.

    Cheers,
    Hob
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Where to put KillTimer() in Dialog

    Put it in the WM_DESTROY message. . before the CDialog:estroy () is called.

  6. #6
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: Where to put KillTimer() in Dialog

    Simply handle WM_CLOSE Function in your Code and write the Code in your OnClose() method.Because WM_CLOSE internally call DestroyWindow Function to DestroyWindow.

    Thanx

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Where to put KillTimer() in Dialog

    WM_CLOSE is only called when you use the close button from your systemmenu of your mainwindow.

  8. #8
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: Where to put KillTimer() in Dialog

    Quote Originally Posted by Skizmo
    WM_CLOSE is only called when you use the close button from your systemmenu of your mainwindow.
    what else you are expecting .and how you are going to close the app

    Thanx

  9. #9
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Where to put KillTimer() in Dialog

    Quote Originally Posted by humptydumpty
    what else you are expecting .and how you are going to close the app

    Thanx
    Closing the app. can be done in more then 1 way. For example. . if you don't catch the escape-button. .. it closes the app when you press escape, without sending a WM_CLOSE. Or. .if you have your own 'Close/Exit' button on a Dialog, you can do a 'EndModalLoop ()' and the also the WM_CLOSE is not send.

    The WM_DESTROY is always send, because no matter how to close your app. it must always destroy it's resources.

  10. #10
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: Where to put KillTimer() in Dialog

    Hello,

    WM_DESTROY handler is the best place to kill the timer. WM_CLOSE handler is not the proper option since the dialog can be closed without getting WM_CLOSE message sent (like closing with OK or Cancel key). Destructor of the dialog class also is not the proper place since the destructor is called after the window is dismissed with and the timer is associated with the window. That is why an assertion failure occured.

    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured