Thread: Change the clock

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    155

    Change the clock

    Hi, I may have this in wrong place but I thought it dipends on the O/S your using. Ok I have been looking over the net and on here (may have miss something tho) and didnt find a way to do this. I am using windows XP, and using C++ to do this. I want to change the clock time in the lower right hand side on the screen to likes say 1:00 (doesnt matter AM or PM). I dont know how to tho, I know how to check what time it is but not how to change it. Anyone know where I can look or maybe some code I can look at?

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    You can set the clock in C++ to the nearest second using the
    the C:

    stime()

    function in time.h. My documentation tells me it is UNIX only, but I have been using it on Windows with BCB.

    In Windows, you could also use the:

    SetSystemTime()

    Win api call. More accuate than stime().
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Why do you want to mess around with the system clock?

    Backup schedules, browser caches, program make dependencies, email headers, and many other things will be screwed up by bogus clock hacking.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    To make changing the clock a little easier with how I have my program set up, and mostly b/c I can I guess. What the heck is "bogus clock hacking"?

    Ok I tried using SetSystemTime() but no luck atm. I got some code fom MSDN but I have never gotten any luck from their so call "helpful site" LOL.
    Code:
    #include <windows.h>
    
    // SetNewTime - sets system time
    //
    // Parameters
    //    hour     - new hour (0-23)
    //    minutes  - new minutes (0-59)
    //
    // Return value - TRUE if successful, FALSE otherwise
    
    BOOL SetNewTime(WORD hour, WORD minutes)
    {
        SYSTEMTIME st;
    
        GetSystemTime(&st);       // gets current time
        st.wHour = hour;          // adjusts hours 
        st.wMinute = minutes;     // and minutes
        if (!SetSystemTime(&st))  // sets system time
            return FALSE;
        return TRUE;
    }
    I know it needs a int main but if I add one it still doesnt work for me. Can someone show me a way on how to us this line of code or maybe tell me what they mass up on so I can fixs it?
    Last edited by adr; 03-01-2006 at 06:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. c++builder6 change form names problem
    By Leite33 in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2008, 08:20 AM
  3. how to change static char* and not lose mem ?
    By jabka in forum C Programming
    Replies: 15
    Last Post: 09-07-2007, 05:33 PM
  4. Replies: 2
    Last Post: 11-08-2002, 03:22 AM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM