|
i will try and let you know, thanks alot
|
|
|
|
|
Hello guys,
I have a question : Is CWnd::SetTimer machine dependant ?
I am asking this question , because I have noticed that , for example a program which is using this function as a timer shows different delays in times on different PC - s.
On machines with faster processors a program using this method needs less time then on machines with slower processors.
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
The short answer is no. But to expound, it depends mostly on the load of the OS at that time. The timer won't fire untill the app (or thread) in question gets scheduled, or, if the app/thread in question has a lot of outstanding messages in the queue. A high-priority app running could quite easily delay it, or having many apps/threads running will have the same effect. Also, as a tidbit, different versions of Windows used different values for scheduling the time-slices each app/thread gets.
--
Joel Lucsy
|
|
|
|
|
Windows is not a real-time OS, so all time dependant functions will vary depending on the load of the machine.
On the best case, the timer callback will fall close to what you set it to, but most of the time it will be a little after.
I don't think that a Timer will be called before its ellapsed time.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You know Max I had once written a game "Snake" , like on any Nokia mobile phone and I used the CWnd::SetTimer function for implementing a timer where I was doing different operations(moving the snake,....)
But when I took this game to my friends PC he has much better PC then I do , It was impossible to play the game as the Snake started to move very fast , of course on my PC it was moving normally.
So my problem is that I need to implement a exact timer in my current project.And I am practically sure that CWnd::SetTimer won't work for that.
Any ideas how to do that
thanks
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
SetTimer and the WM_TIMER message are defined to have 10 millisecond resolution. Unfortunately, they are treated as least priority messages, and are handled only if there are no other messages pending. This means that the timer may trigger every 10 ms, or it might be 100 ms. As others have mentioned, system load affects WM_TIMER behavior as well.
You can measure much more accurate intervals using QueryPerformanceCounter() .
Software Zen: delete this;
|
|
|
|
|
you are right Giogi,
SetTimer is some Machine Dependent! it based on cpu,load on machine etc..
so as Mr. Gary has mentioned you can go for
BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount
);
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I'll do it Alok ,
thanks
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
I am attempting to adopt only new programming style so I have a question and would like opinions on it...
For debugging in console applications I have seen the following used quit often:
#define DEBUG 1
#define debug if (DEBUG) cout
Then to output debug messages I would do: debug << "Program initiating" << endl;
and so forth...
After which before release DEBUG is set to 0, is this still the modern way to go about doing this?
"Your KungFu is not strong enough"
|
|
|
|
|
I believe _DEBUG is defined when you do a debug build so this would allow you to control your trace statements between debug and release builds.
Elaine
The tigress is here
|
|
|
|
|
Hello,
This depends on your needs. If you're writing a time critical application, you may want to remove the debug messages from your application. If you're writing a service oriented application, you may want to write debug messages to a file or whatever.
I've a general debug (template) library which writes the debug messages wherever I want. I even don't have to write preprocessor statements in my code. I think that something similar is the way to go these days. simple tracing messages won't do anymore. The main reason for this is that you also want error information from release builds.
I think that you should experiment with different ways of saving debug output and write a simple conveniant library that fits your needs.
Hope this helps.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Dear all
In VC++ i'm able to initialise the structure member for int. But, for the below piece of code i'm getting compile time error.
struct one
{
CString name;
}two={"doubt"};
Please kindly suggest me a better way to solve this problem.
|
|
|
|
|
S.R.Sasi Kumar wrote: i'm getting compile time error.
What error? Is it C2552: 'two' : non-aggregates cannot be initialized with initializer list?
Only aggregate types can be initialized with an initializer list. Aggregate types are arrays, classes or structures that have:
- no constructors
- no private or protected members
- no base classes
- no virtual functions
- no non-aggregate members
CString has constructors and protected members so it is a non-aggregate type. As struct one has a non-aggregate member, it is also a non-aggregate, so you get error C2552.
struct one
{
CString name;
} two;
two.name = "doubt";
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
One approach to solving this problem is to have a second struct that contains your initializers:
struct one {
CString name;
} two;
struct one_init {
LPCTSTR name;
} two_init = { "doubt" };
two.name = two_init.name; Of course, this makes a lot more sense when you are initializing an array, and the structure members are more complex.
Software Zen: delete this;
|
|
|
|
|
Dear sir
I followed the same syntax(both the option) and i'm getting the following error when i try to initialize the structure in VC++
struct one
{
CString name;
} two;
two.name="doubt";
and also
struct one
{
CString name;
} two;
struct one_init
{
LPCTSTR name;
} two_init = { "doubt" };
two.name = two_init.name;
1.syntax error : missing ';' before '.'
2.missing storage-class or type specifiers
3.two' : redefinition; different basic types
Please suggest me to rectify the mistake.
|
|
|
|
|
Dear friends,
I have declared a structure variable in common.cpp and i want to use the structure members in one.cpp as well as two.cpp. When i include the common.h in those two files, i am getting the "LINKER ERROR" saying
"struct COMMSETTINGS commparam" (?commparam@@3UCOMMSETTINGS@@A) already defined in DLMSView.obj
Please help me in solving this problem
|
|
|
|
|
common.h:
struct COMMSETTINGS {
};
extern COMMSETTINGS commparam; common.cpp:
#include "Common.h"
COMMSETTINGS commparam; one.cpp and two.cpp:
#include "Common.h" Note the extern keyword used in common.h. This keyword, used in the declaration, tells the compiler/linker that the definition is found elsewhere. In this case, the definition is in common.cpp .
Software Zen: delete this;
|
|
|
|
|
Hi all:
I have a problem when I try to divide two floating point number to get a reasonable integer result. For example 1.0000 / 0.2000, this gives me 4 but not 5. Does anybody have any good idea to solve this problem please???
Many thanks
Asura
|
|
|
|
|
how do you do this ?
did you try using ::floor() and ::ceil() too ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
1.0000 / 0.2000 should give you 5. so the values must be a little different than you think.
In any case, one old trick is simply to add 0.5f to the result of the division. When you cast the result to an int if the original result was x.5 or greater the result will be x + 1 otherwise it will be x.
|
|
|
|
|
For negative numbers, you need to subtract 0.5f.
-0.7 + 0.5 = -0.2 => 0.0
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Stan has it right. The issue is that when converting from a real value to an int the compiler truncates the result. Here's something you can try :
int NearestInt( double value )
{
return (int)( value + 0.5 );
}
int NearestInt( float value )
{
return (int)( value + 0.5f );
}
-- modified at 13:37 Saturday 19th November, 2005
|
|
|
|
|
Testing VC++ code for pointer underflow/overflow for data type char *.
knarasimharao
|
|
|
|
|
I suppose you can check the index into the string, and the size of the string, which was allocated, so that the index should be less than the size, and always greater or equal to zero.
You can use:
AfxIsValidString(...)<br />
AfxIsValidAddress(...)
to check that the address is readable/writable.
this is this.
|
|
|
|
|
don't make the confusion : char* is not always a string !!!
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|