Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Why doesn't my timer work?  (Read 3761 times)

0 Members and 1 Guest are viewing this topic.

Stan Huang

    Topic Starter


    Beginner

    • Experience: Experienced
    • OS: Windows 7
    Why doesn't my timer work?
    « on: September 12, 2013, 02:58:18 AM »
    I have a well-defined derived CWnd class, say myClass. I set a timer at beginning: SetTimer (999, 1000, 0) inside a member function of myClass.
    Then I defined my own timer service routine:
    void myClass::OnTimer(UINT_PTR nIDEvent)
    {
        MessageBox("err","err",MB_OK);
        MessageBeep(0xFFFFFFFF);   // Beep
        debugMsg ("hello");
        serial.Write("hello", 5);
        CDialog::OnTimer(nIDEvent);
    }

    But I found it doesn't work according to the four non-executed statements. That is, no message box is popped out, no beep sound, no hello message, no message sent to serial port. What's wrong with it?

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Why doesn't my timer work?
    « Reply #1 on: September 13, 2013, 04:32:16 PM »
    Are you able to post the full source code? I think your problem is located elsewhere than the shared source. I am guessing you have all your includes etc otherwise it wouldnt compile, so what you have now is source that compiles but you are not getting the operation of the source that is desired.

    At times like this I generally will place a message to pop up at certain sections of the source code to verify that it is calling and executing the routines. And comment out this or remove it and move on. I have also used the method of commenting out full sections of code via /* followed by */ to try to isolate problems and then when I know that the problem is located within the commented section of code I know where to look. Or there is a function within this section of code that is missing the proper #include<  >. Also I have also run into issues with my includes to where adding or removing the .h such as #include<iostream.h> or #include<iostream> makes a difference for the library header that is related to the malfunction, although using .h is the older C standard library header and without the .h is the modern C++ standard library header. I havent run into this in a while and I think it was with Borland C++ that I ran into this problem years ago.

     Generally source like this that compiles and does not function as intended is because there is a minor typo in which something as small as a lower case letter in place of an uppercase letter or missing underscore or added underscore between the call and the function cause the problem and the compiler is satisfied, although I know that with BloodShed Dev C++ it will warn me of uninitialized calls when compiling which point out the fact that I initialized something as Get_UPC and further on in the source I have GET_UPC and it compiles but it doesnt function properly, although like I said usually I get a warning when compiling, if not a error that needs to be corrected before it will compile.

    So does this compile clean with no errors and no warnings, or does it compile successfully yet your getting warnings which could help find the cause for the malfunction?

    Which IDE and version are you using to create/compile this program?