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.

[URL] ....

View 14 Replies


ADVERTISEMENT

C++ :: Sleep Function When Drawing Analog Clock

Jan 19, 2015

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.

View 5 Replies View Related

Visual C++ :: What Header For Sleep Function

Jan 26, 2014

I have been googling for a long time to find the header used with sleep().

View 5 Replies View Related

Visual C++ :: How To Call Sleep Function Prototype

Dec 23, 2012

I have two problems with the code below:

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[])

[Code] ....

View 3 Replies View Related

Visual C++ :: Notification Supposed To Be Sent Out During Forced Sleep In XP?

Oct 2, 2012

I run the following API to put Windows XP SP3 into sleep (or standby mode) from a worker thread:

Code:
BOOL bForced = TRUE;
SetSuspendState(FALSE, bForced, FALSE);

Then in the main thread, while processing window messages:

Code:
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
if(message == WM_POWERBROADCAST) {
if(wParam == PBT_APMSUSPEND) {
AddLogMsg(_T("SUSPEND event received"));

[Code] ....

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.

View 1 Replies View Related

C++ :: Function That Makes Shows Time Entered In Clock Format

Mar 11, 2014

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;

[Code].....

View 6 Replies View Related

Visual C++ :: Drawing Text On A Bitmap?

Oct 5, 2012

I wrote a simple clock that shows the time over bitmap as follows:

Code:
void CMyClock::OnPaint()
{
CRect rect;
GetClientRect(&rect);

[Code]....

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.

View 5 Replies View Related

Visual C++ :: MFC Coordinate System - Drawing Of Angles?

Oct 11, 2013

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:

Code:
180 -y
|
|
-x 270---------------- 90 +x
|
|
0 +y

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):

Code:
0 +y
|
|
-x 270---------------- 90 +x
|
|
180 -y

View 4 Replies View Related

Visual C++ :: Drawing A Rubber Band Rectangle

Jan 23, 2015

I am trying to draw a rubber band rectangle. I have got a following code from a site but its giving an error:

Code:
class CSampleView: Public CView{
...
public:
CrectTracker m_tracker;//Changed to CRectTracker
...
};

Secondly, in the constructor to initialize the object CRectTracker document class:

CSampleDoc :: CSampleDOC () {
// Initialize tracker position, size and style.
m_tracker.m_rect.SetRect (0, 0, 10, 10);
m_tracker.m_nStyle = CRectTracker :: resizeInside |
CRectTracker :: dottedLine;
}

The error is:

error C2065: 'm_tracker' : undeclared identifier

How to get rid of this error??

View 4 Replies View Related

Visual C++ :: Custom Pyramid Drawing Program

Jul 6, 2014

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;

[Code] .....

View 7 Replies View Related

Visual C++ :: Control For Owner-drawing Items With 1 Or 2 Columns?

Jan 22, 2014

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?

View 14 Replies View Related

C/C++ :: Use Analog Device Through USB Interface

Sep 25, 2014

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?

View 2 Replies View Related

Visual C++ :: Drawing (radius Sized) Lines From Center To Boundary Of Circle

Feb 3, 2014

I am facing a programming logic problem. I want to draw radius sized lines from centre of circle to the circle boundary.

My code is:

int x1, y1, x2, y2, i, r, old_xc,old_yc, x,y;
int xc, yc;
x1=170;
y1=300;
x2=70;
y2=400;
pDC->Ellipse(x1,y1,x2,y2);

[Code] .....

The lines are touching the circle boudary at only start while the rest of lines are smaller and the shape is a triangle instead of a pie slice.

View 8 Replies View Related

Visual C++ :: Is It Worthwhile To Write ActiveX Module Dedicated To Drawing Charts

Oct 22, 2014

I know the user installation must involve some registry manipulations and some other trickery. But the ActiveX way seems to be more modular.

Is it worthwhile to separate the charting modules from the exe and make an activex dll for this purpose?

View 5 Replies View Related

C++ :: How Does Clock Return Same Value Every 72 Minutes

Apr 19, 2014

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?

View 2 Replies View Related

C++ :: How To Change Clock Time

Nov 28, 2013

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?

View 1 Replies View Related

C++ :: Operation Time Or Clock Cycles?

Apr 21, 2014

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?

View 4 Replies View Related

C++ :: Code For Digital Clock - Adding While Loop?

Aug 23, 2013

This is my code for a digital clock. It only refreshes when i type in a letter.

#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
//char dateStr [9];
char timeStr [9];
char almtimestr[9];

[code]....

View 3 Replies View Related

C/C++ :: PC Based Digital Clock Via Parallel Port

Dec 11, 2012

I have this project and I already have a code and the circuit, but I studied assembly language it's supposed to display the hours and minutes.

Here's the code:

TITLE CLOCK.ASM
    DOSSEG
    .MODEL SMALL
    .STACK 0100H
    .DATA
    PRINTERPORTBASEADDRESS equ 378h

[Code] ....

This is the circuit diagram [URL] ....

View 7 Replies View Related

C# :: Sleep / Wait - Unity 3D

Jun 3, 2013

I have been trying to make a sleep function in C# that will allow the game to be briefly paused when played. I am using Unity 3D.

View 2 Replies View Related

C# :: How To Get Monitor Out Of Sleep Mode

Jul 12, 2012

How can you get a monitor out of sleep mode in c#?

I tried the following, but then the monitor wakes up and falls back to sleep mode immediately.

Code:

uint SC_MONITORPOWER = 0xF170;
uint WM_SYSCOMMAND = 0x0112;
SendMessage(this.Handle, WM_SYSCOMMAND,
(IntPtr)SC_MONITORPOWER, (IntPtr)(-1));

View 1 Replies View Related

C :: Sounding A Beep While Using Sleep

Feb 22, 2015

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..

View 3 Replies View Related

C# :: Wait For Thread To Finish Without Using Sleep?

Apr 30, 2012

After i've created a thread,

Code:
Thread thread = new Thread(new ThreadStart(alpha.ThreadProc)); h

How to wait for that thread to finish without using Sleep?

View 8 Replies View Related

C++ :: Using Clear Device And Sleep Functions In Graphics

Dec 14, 2014

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.

View 3 Replies View Related

C++ :: Drawing A Map - Tiling In SDL

Jan 18, 2013

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.

View 1 Replies View Related

C++ :: How To Use Mouse In Drawing Shapes

May 3, 2013

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 ..

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved