|
G_S wrote:
is there a way of determinig the OS running.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/osversioninfo_str.asp[^]
But like Shog said, if you use unsupported API's, then you need to dynamically load them, or your app won't run, even if you never run the code that calls them. The alternative is to write your own versions. I did that with TransparentBlt and AlphaBlend many years ago, so I could support W95 and still call them.
G_S wrote:
how many different windows platforms are there.
Assuming you start with W95, there's W95, W98, NT4, WME, W2000, WXP. Then W98 has service pack 2 to consider, that added a lot, from memory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you for the link.
So the best work around the dependencies is to dynamically load and test for the functins.
Thanks for the anwser this helps.
G_S
|
|
|
|
|
No, the best way is to use the link I gave you to find out what OS you have, then to dynamically load the functions and only allow the code to use them based on the results of that test, which will have told you if they are present, based on OS version. There's only one test involved, the dynamic loading is because otherwise Windows will try to load the functions, even if they don't exist, regardless of the fact that your code deals with that problem for you.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I use this code snippet
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Hiya
I have a variable that shoud return a value of say... 50. Instead it's returning 49.9999999956 which may sound pretty good but I need the 50. I found this thing in the Std library which is an enum called float_round_style that includes something called round_toward_infinity ... but I can't find how to actually use the durn code, an example or anything other than the description . Can anyone tell me how to use it? Is there any other easier way to acomplish what I want?
Thanks!!!
|
|
|
|
|
double d = 49.9999999956;
int i = (int)d;
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Nope, that leaves me with 49, not 50.
|
|
|
|
|
I find that very difficult to comprehend. Numbers should round up from .5 upwards, thought. That makes the floor function totally useless.
This will work.
#include<math.h>
double d = 49.99999956;
int i = (int)ceil(d);
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you! that sure works!!!
|
|
|
|
|
The Function "double ceil(double);" will always round UP.
that is even if you have 49.00005 the ceil() function will round UP to 50;
if you want to round to the nearest Integer
you need somthing else.
G_S
|
|
|
|
|
G_S wrote:
The Function "double ceil(double);" will always round UP.
I guess that's why it's called ceil ( as in ceiling ).
G_S wrote:
if you want to round to the nearest Integer
you need somthing else.
I was helping someone who wants to round UP. However, casting to int seems to just drop the floating point part, when I assumed it would round to the nearest int, up or down. HEnce, I suggested ceil.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
To alter the processor's default rounding behavior, you can use the _controlfp() function to set specific FPU flags (such as _RC_CHOP , _RC_UP , _RC_DOWN , _RC_NEAR ).
You must be careful in the forest
Broken glass and rusty nails
If you're to bring back something for us
I have bullets for sale...
|
|
|
|
|
Hello,
The standard implies that when a floating point value is converted to a intergral value, the fractional part is discarded...
I also got the blogging virus..[^]
|
|
|
|
|
ceil()
You must be careful in the forest
Broken glass and rusty nails
If you're to bring back something for us
I have bullets for sale...
|
|
|
|
|
Thank you, that was easy!!!
|
|
|
|
|
double d = 49.99999999;
int i = (int)(d + 0.5);
i will now be properly rounded.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
PJ Arends wrote:
double d = 49.99999999;
int i = (int)(d + 0.5);
Nice very nice but what about the (-) negative ones test it you'll see.
int i;
if(d<0)
i = (int)(d - 0.5);
else
i = (int)(d + 0.5);
G_S
|
|
|
|
|
The method PJ showed, and you expanded for negative numbers, is a standard way.
Shog hinted at another way doing it using _controlfp (or _control87).
The rounding control flags specify how the assembly instruction frndint will round.
From Intel info on frndint:
The Control Word 16-bit register is used ...
The RC field (bits 11 and 10) or Rounding Control determines how the
FPU will round results in one of four ways:
00 = Round to nearest, or to even if equidistant (this is the initialized state)
01 = Round down (toward -infinity)
10 = Round up (toward +infinity)
11 = Truncate (toward 0)
So, by default, it rounds the way you want.
The problem is i don't know of any C function that calls this, hence the workaround of adding 0.5 and then truncating by cast to int.
A more general (non-portable) solution would be to write your own function that calls frndint.
e.g.
__forceinline double FkRound( double N )
{
__asm {
fld N
frndint
}
}
Before calling this you could call _controlfp() to set the way you want rounding to work, or just to make sure it hasn't been changed by some other code.
This works for both positive and negative numbers.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hello!
I found several examples on how to create applications that use tray icons. However, didn't find what I really need. How can I (if at all possible) enumerate all existing tray icons and read their popup (hint) text?
That would be especially useful, e.g. if I have a probe application in tray that shows temperature or whatever on its popup text and I want to use that in my own application.
Thanks in advance!
|
|
|
|
|
There's a better way to get the information you want... Stealing stuff from hint text is kinda tacky... IMHO.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
So, what would be the better way?
|
|
|
|
|
Well, first of all -- I don't think the hint text is rendered until the mouse moves over the icon....
Do you want the temperatur? You should find out if you can programatically get the termperature from a website -- like weather underground -- they have xml weather feeds...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
I need to develop a program of choice for a project. I am learning C++ and have just finished learning functions. Any ideas on a program to develop? I have lots of time to fiddle around with it if it is hard for me!
|
|
|
|
|
If you're just learned how to write a function, I suggest a console calculator program. Actually, I suggest you buy 'The C++ Programming Language' by Bjarne Stroustroup, and do the exercises in that.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the tip. By the way ...
Christian Graus wrote:
If you're just learned how to write a function, I suggest a console calculator program.
I'm not quite sure what you mean by a "console calculator program"
Thanks
|
|
|
|