|
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
|
|
|
|
|
A console app is one where you have a window with text in it, not in a window with buttons, etc. A calculator program is a program where you type 3+3= and it gives you 6.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Does anyone else have any suggestions for me?
Thanks Guys
|
|
|
|
|
The first program I wrote to flex my newly acquired
programming skills many years ago was a numerical
version of the board game Mastermind :
http://www.archimedes-lab.org/mastermind.html[^]
using four-number sequences instead of colored pegs
for the "code".
I actually wrote this program in Basic, on paper,
after reading the first chapter or so of a book
whose title I've forgotten and before buying my
first computer. It ran to hundreds of lines of code.
After buying my Specravideo with 64kb of memory I
typed it in over three evenings and it ran first
time!
I later read a few more chapters of the book and
realized that I'd missed a rather important property
of "variables": I hadn't realized you could change
their value after initially assigning a value to them!
Armed with this new revelation I managed to trim my
Mastermind code down to about 40 lines.
The second program I wrote was a version of
John Conway's "The Game of Life".
http://www.math.com/students/wonders/life/life.html[^]
A good one for learning about data structures.
You could implement it as an 2-dimensional array of
check-boxes on a dialog box if you're not yet
into graphics programming.
I think both these programs would still make
pretty good beginner exercises.
Steve T
|
|
|
|
|
How about something like:
TempToFahrenheit( const double dCelcius )
{
}
TempToCelcius( const double dFahrenheit )
{
}
void main( void )
{
double dFahrenheit = TempToFahrenheit(29.2);
double dCelcius = TempToCelcius(120);
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Linked lists are always nice to fool around with.
You could create a linked list, let some user type strings, numbers or whaterver in the console, so you can add them to the list. Than you can sort it, delete items from it, and all the other things you'll do in your future career
If you'll choose to do this, you'll learn an awfull lot about memory management and pointers.
I also got the blogging virus..[^]
|
|
|
|
|
|
Hi ,
I utilize Visual C++ .NET 2003 in my project.
I have a class with a few methods. I have to delete one of these methods.
In the Class View I have selected the method to suppress.
I have tried with the del key of the numeric keypad without success. I have tried with the contextual menu but the delete option is not present.
How can I delete a method of a class with Visual C++ .NET 2003 ?
Claude
|
|
|
|
|
|
Do you think he was serious ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I change the foreground color of an edit control?
And is there a simple algorithm to determine if two colors have enough "contrast" to be distinguishible?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
peterchen wrote:
How can I change the foreground color of an edit control?
handle WM_CTLCOLOR message and call SetTextColor() on the supplied DC.
peterchen wrote:
And is there a simple algorithm to determine if two colors have enough "contrast" to be distinguishible?
I don't know about a simple algorithm, but it seems to me that the user should be able to set those kind of things for themselves, as people can have different perceptions as to what colours contrast and what colours do not. Have a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnhess/html/hess10092000.asp[^].
"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:
handle WM_CTLCOLOR message and call SetTextColor() on the supplied DC.
That should work
PJ Arends wrote:
but it seems to me that the user should be able to set those kind of things
It is just an additional visual cue, and I'd rather disable it than making it an option. The basic idea is to disable it when COLOR_WINDOW is anything else but white, but I'd like to be more tolerating.
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|