Visual C++ :: Drawing Analog Clock - Sleep Function
Jan 19, 2015
The question says: Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().
OK, I wrote below code. It is in its primary stages and has not been completed yet.
Code:
#include <GUI.h>
#include <time.h>
#include <iostream>
using namespace Graph_lib;
//---------------------------------
class Dynamic_clock : public Window {
[Code] .....
I expect the system in void clock_hands() (line 38) attaches hour1 (line 41) then waits for 1000 ms (using Sleep(1000)) then detaches hour1 and attaches hour2 this time. But it doesn't occur in practice. When the system reaches Sleep(1000); it seems to go into a comma! It doesn't show the hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.
Make an "analog clock" that is, a clock with hands that move. You get the time of day from the operating system through a library call. A major part of this exercise is to find the functions that give you the time of day and a way of waiting for a short period of time (e.g., a second for a clock tick) and to learn to use them based on the documentation you found. Hint: clock(), sleep().
OK, I wrote below code. It is in its primary stages and has not been completed yet.
#include <GUI.h> #include <time.h> #include <iostream> using namespace Graph_lib;
[Code] .....
I expect the system in void clock_hands() (line 38) attaches hour1 (line 41) then waits for 1000 ms (using Sleep(1000)) then detaches hour1 and attaches hour2 this time. But it doesn't occur in practice. When the system reaches Sleep(1000); it seems to go into a comma! It doesn't show the hour1 so seeing the movement of clock ticks by the clock's hands will not be possible.
1. I cannot find a header file to #include that has the sleep function prototype.
2. When I add my own sleep function prototype, I get an unresolved external reference error (for _sleep, not sleep).
What must I #include to get the sleep function prototype? What lib must I include in the linker configuration to resolve the external reference? (I suspect that if I #include the correct header file, the second question might become moot.)
The "man page" at [URL] .... says the header file is <WinBase.h>. But #include'g only <WinBase.h> results in compilation errors.
A response marked "answer" at [URL] ..... says <windows.h> [sic]. #Include'g only <Windows.h> does eliminate the compilation errors.
But apparently that does not bring in the sleep function prototype. Neither does also subsequently #include'g <WinBase.h>. (Which seems to be #include'd by <Windows.h> anyway.)
But even with my own function prototype shown below, I get an unresolved external reference for _sleep. Is that a symptom of my problem: my sleep reference is changed to _sleep? If so, how can avoid that?
According to "man page" (see link above), the external should be resolve in kernel32.lib. And kernel32.lib does appear in the "Additional Dependencies" list under Configuration Properties Linker Input.
Since I am not using C++ features, I tried setting "Compile as C" under Configuration Properties C/C++ Advanced, to no avail.
My code....
#include "stdafx.h" #include <stdlib.h> #include <time.h> #include <Windows.h> void sleep(DWORD msec); // added later int _tmain(int argc, char* argv[])
So when SetSuspendState is called with request for a 'forced' sleep mode, the PBT_APMSUSPEND notification is never broadcast. Only if I set forced parameter to FALSE I receive it.
PBT_APMRESUMEAUTOMATIC is received in either case.
PBT_APMSUSPEND is always received when run on Windows Vista/7.
Program should continually have user enter a positive integer, and quits on zero entered. This entered number represents the total number of seconds and after each number is entered a function is called that displays the time in hours, minutes and seconds. Sample output is as follows:
Enter Total Seconds --> 3605 1:00:05
The function needs only one value parameter and should return nothing back to main. If the minutes or seconds are a one digit number then make sure to display a leading zero as the example above shows.
Here is my program. my question is how do i make the numbers appear like this? 1:00:05
#include <iostream> #include <iomanip> using namespace std;
Now I got rid off the white border but everytime I draw a text it write on top of the previous text so after few seconds everything is a mess and the time is no longer readable.
I am drawing in a simple (square) MFC window. I realize that (0,0) starts in the upper left hand corner. I wanted to see how MFC handled drawing of angles, so I use this code:
Code: double CompassDegreesToRadians(double compassDegrees) { return((PI / 2.0f) - (compassDegrees * PI / 180.0f)); } // Make pen CPen penRed; penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0)); // Test Angles
[Code] .....
Using this code, and changing the value of angle1 to these values (0, 90, 180, 270) I think MFC uses the coordinate system:
This seems like a strange coordinate system to use. Am I doing something wrong? If this is correct, how can I convert my calculations to this coordinate system? (compass degrees):
I am trying to figure out how to create a program that will draw a triangle using *'s with a base the has a user-inputted number of *'s like so:
* *** *****
It needs to take a user inputted number and draw a pyramid like the above pyramid with the number of *'s in the base matching the user inputted number (i.e., user enters 10, so the triangle has 10 *'s in the base). I figured it would be best to first create a loop to draw out the correct number of *'s before trying to create another loop to draw out the correct number of spaces, to properly align the *'s into a triangle shape.
int width = 0; int height = 0; int i = 0; int leafWidth = 0;
I want to show a list of graphical items in 1 or 2 columns (user selected). I will draw the items (owner-draw). I tried many hours today to find a solution with clistctrl. Is it possible to make it with clistctrl?
I am supposed to write a C program to send through USB interface to the analog device AD9914. Now I am doing the USB interface part where my computer has to detect the AD when it is plugged in and send the signals to it. I have to write the program to detect the device when it is plugged in. What kind of functions can I use? I know that the registry stores the device when it is plugged in. What functions are available to read?
I am reading up on the clock() function: URL....It states: "On a 32bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approximately every 72 minutes."
How could this return the same value, if clock is the number of clock ticks elapsed since program execution. Wouldn't the number of clock ticks continue to grow, and as such, when we divide by 1000000, the return value should continue to grow. So how does this function return same value every 72 minutes?
The system clock starts once the system is executed. But how can I update the clock value to certain other value? Let say, for example. If a=10, then, immediately the clock is set to 10 seconds after the current clock time. Is it possible?
So I am making a game and I want to push performance to the limit. That's why I really want to know how many clock cycles every operation, cast, memory allocation - EVERYTHING takes. Or approximate time consumption ratio, anything like that.
I tried doing it myself: I created a timer based on clock cycle counting, measured time of an empty loop and the same loop with various operations inside, but the results were extremely inconsistent and confusing: empty loop would take more time that the same loop with an addition, the time would vary greatly,... I guess it's because of background operations using up some of the CPU...
Since I didn't manage to find anything on the internet I guess there might be something I'm missing: maybe it depends on the processor?
I need to be able to sound an alarm (a beep) for 10 seconds in C.this beep has to mirror a sleep period, before the code loops back to the beginning. Now I've got the loop sorted and I can make it beep and sleep, however the beep follows 10 seconds after the sleep..Both the beep and the sleep need to happen at the same time..
I have a college project which is a car racing game using C++ and the old-school graphics library BGI. After I draw the map and placed the objects(Car,obstacles,road's borders etc..)I added Sleep(); function to the function named Obstacles(); but the problem is, I can't move the car with the right&left arrows.a
Another problem,If I added a cleardevice(); command all objects disappears only the obstacles function keeps working. the Code is here:
char c; do{ c = (char)getch(); if (c == KEY_LEFT) { x = x - 10, x1 = x1 - 10; } if (c == KEY_RIGHT) { x = x + 10, x1 = x1 + 10;
[code].....
note: this is not the whole code, it's only a small portion of it, not a debugging question only need a hint how to fix it.
I'm in the beginning stages of designing my first video game using SDL, and have run into a bit of an impasse. I attempt to draw the map using a simple tile function and nothing prints to the screen. I am going to attach the function itself.
bool Tile::draw_tiles ( void ) { GV gv;
//Open the map std::ifstream map ( "test.map" ); for ( int y = 0; y < GV::MAP_HEIGHT / 64; y++ ) { for ( int x = 0; x < GV::MAP_WIDTH / 64; x++ ) {
[Code] ....
Extra notes: 1. Compiles fine. 2. No run time errors (this function returns true). 3. Apply surface is a function that takes an x and y value for position on the map, an image, a screen to print it to, and a rectangle to cut out the image out of. 4. I did some bug testing and added another function to print the image SDLS_tiles by itself (its just a simple sprite map) after the map.close() function, and it worked fine.
i have to make an application called " paint " in c++ . It should facilitate user to draw different shapes using a mouse. Now the biggest hurdle i am facing is the usage of mouse .. what is the header file for usage of mouse ? i am using visual studio 2010 . the syntax is creating problems ..