|
That was easy!
Thanks
|
|
|
|
|
I am working with the VC++ 7 build-in CImage class.
there is a
CImage::SetTransparentColor(int nIndex);
but if i use
m_bmpMyBitmap.SetTransparency(0); /* which should set color 0 in palette transperent */
m_bmpMyBitmap.Save(dlg.GetPathName(), GUID_NULL);
and save it to gif or png the color is not transperent
|
|
|
|
|
What is the most reliable way to convert a float variable to a double variable?
The reason I ask is this:
float fData=2.7;<br />
double dData=fData;
After the above operation dData is: 2.7000000476837158
not 2.7
I know this is probably due to some problem with .7 being represented accurately in binary. How do I ensure that 2.7 float = 2.7 double without resorting to string based conversions and truncating etc?
|
|
|
|
|
there is no easy way to do this, since both float and double are approximations.
i believe the best you can do is to do the float->double cast, then choose an arbitrary precision (say 6 decimal places) and round up or down.
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Hi Chris, yes that would be perfect (2 decimal places actually). Is there a function that will round a float in any of the libraries that you know of? (reason I ask is that I can't seem to find anything applicable)
|
|
|
|
|
i'd start with this:
int scale = 1000;
f*=scale;
if(f>0)
f+=0.5;
else
f-=0.5;
double d =(double)(((double)(int)f) / scale);
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Hi Chris, thanks for that info, however it results in:
2.7000000000000002
As did another (less elegant) double rounding function along similar lines I just came across on the net.
Wierd.
|
|
|
|
|
Hmmmm, I tried your example using my version of round and it gave me 2.7000000000000:
double round(double value, unsigned decimalPlaces)
{
double scale = pow(10.0, (double)decimalPlaces);
double temp = value * scale;
temp += (value < 0 ? -0.5 : 0.5);
return (int)temp / scale;
}
By the way, I also got a compiler warning with the float assignment, so I had to add an "f" to the end of the value to get rid of it:
float fData = 2.7f;
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
Oops! I guess that 2.7000002 *is* the double representation of 2.7.
Thanks for your help, ignore my other reply.
|
|
|
|
|
The problem is that you don't have a 2.7 to begin with.
Instead of trying to represent 2.7 in a double, you are trying to extend a float value which is close to 2.7 to a double. In other words, there is a huge range of double values which come close to a float value of 2.7 while only one is actually a double value of 2.7.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Sure, I know that!
My question was what is a reliable way to convert them.
I guess I should have mentioned that I only ever care about 2 decimal places of precision. (users are entering hours of labour worked and it's always 2 decimal places in the user interface)
|
|
|
|
|
In that case, don't use doubles at all, use scaled integers!!! That's what they do in the commercial world when trying to represent money - find the smallest atomic unit & count in multiples of that....
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Yes it looks like that's what is required for the conversion, unfortunately I can't change the fact that at one end is a float and at the other end is a double because I'm working between two COM components from different developers.
|
|
|
|
|
Well...knowing the representation of floats and doubles (IEEE754), you could use code like this (it'll work for normalized floating point numbers).
float x = whatever;
long y = *(long*)(&x);
const __int64 signBit = (y & 0x80000000) << 32;
const __int64 exponent = (__int64( ((y >> 23)&0xff) - 127 + 1023)) << 52;
const __int64 fraction = (__int64(y & 0x007fffff)) << 29;
__int64 ly = signBit | exponent | fraction;
double lx = *(double*)(&ly);
This will convert float => double with no loss of precision or change in value.
However, I think you'll find that it is the same operations as are done by the floating point part of the processor when it does the float => double conversion, in which case, you might just as well use a straight C assignment...
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
I remember I had this problem before too and I had to do it as the following:
<br />
float flt = 2.7f;<br />
TCHAR sz[65] = _T("");<br />
_stprintf(sz, _T("%.3f"), flt);
<br />
double dbl = _tcstod(sz, NULL);<br />
Now, if you watch the value of dbl you'll see 2.7000000000000, which is what you expected...
|
|
|
|
|
I want to set some member variables of my CDialog (modeless).
SO I do stuff like
CImageDisplay* pImageDisplay = new CImageDisplay;
if (pImageDisplay == NULL) return;
BOOL ret = pImageDisplay->Create(IDD_IMAGEDISPLAY, this);
Where do I put pImageDisplay->width = 100; ? Before the create() or after the create()?
Appreciate your help,
ns
|
|
|
|
|
I tried both - it doesnt seem to matter...
Appreciate your help,
ns
|
|
|
|
|
It doesn't matter because you've reserved memory space for the dialog once you have declared the dialog variable.
When you create the dialog you are telling windows to attach a dialog resource,which is the parent window...
But the class it's already created once you've declared the variable.
hope this helps...
|
|
|
|
|
Thats really interesting - I was trying to deduce the sequence of events with stepping and breakpoints but the IDD_DIALOG resource connection didnt show up with my strategy so your response makes that clearer!! Thanks.
Appreciate your help,
ns
|
|
|
|
|
Fellow cpians , how can I hook to a file to catch that the file changed ?
I'm must code a application that is always monitoring a file on the filesystem and every time that the file is updated , I need to be notified of the fact to reload the file data in my COM Server.
Some Windows message , DDE event , hooking mechanism (In a long distant past I already have done something like this, but it's part of my forgotten memories)???
Thanks in advance.
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
Remember just because a good thing comes to an end, doesn't mean that the next one can't be better.-Chris Meech
|
|
|
|
|
ReadDirectoryChangesW
OR
FindFirstChangeNotification
|
|
|
|
|
The 2 functions don't work only on a single file , but making a directory with only 1 file should do the trick.
So many thanks for your help
Cheers,Joao Vaz
And if your dream is to care for your family, to put food on the table, to provide them with an education and a good home, then maybe suffering through an endless, pointless, boring job will seem to have purpose. And you will realize how even a rock can change the world, simply by remaining obstinately stationary.-Shog9
Remember just because a good thing comes to an end, doesn't mean that the next one can't be better.-Chris Meech
|
|
|
|
|
Hi,
I am running into a problem with deriving an atl class. I am using VS.Net and have run the wizard to create an non-attributed atl service. I want it to be an interactive service so I decided that I would need to derive the CAtlServiceModuleT class and add m_status.dwServiceType |= SERVICE_INTERACTIVE_PROCESS; to make the service an interactive process.
This is the class that I created in a header file I call ATLINTERACTIVEPROCESS.H
#pragma once
#include <atlbase.h>
#ifndef _ATL_NO_SERVICE
template <class T, UINT nServiceNameID>
class ATL_NO_VTABLE CAtlInteractiveServiceModuleT : public CAtlServiceModuleT<T, nServiceNameID>
{
public :
CAtlInteractiveServiceModuleT() throw()
{
m_status.dwServiceType |= SERVICE_INTERACTIVE_PROCESS;
}
};
#endif
</code>
When I compile this I get the following errors
ATLINTERACTIVESERVICE.h(7) : error C2504: 'CAtlServiceModuleT' : base class undefined
ATLINTERACTIVESERVICE.h(15) : see reference to class template instantiation 'CAtlInteractiveServiceModuleT<t,>' being compiled
ATLINTERACTIVESERVICE.h(7) : error C2143: syntax error : missing ',' before '<'
I would assume that including <atlbase.h> would "define" the base class.
If I take the code and drop it in the atlbase.h header file just under CAtlServiceModuleT<> everything compiles fine. Unfortunately I don't want to keep this code in the atlbase.h file because it could be changed by microsoft and my collegues would have to have a "special" version of atlbase.h to compile this service. Does anyone have any idea what I am doing wrong? Can derived template classes exist in other header files than their base classes? Are there defines that I am missing? As a side note is there a way to debug the compile pass?
Please help!!
Cheers,
Clint
|
|
|
|
|
The 'CAtlServiceModuleT' class is hidden by the ATL namespace.
Cheers,
Clint
|
|
|
|
|
I have to parse a CSV file, make changes to it and then re-write to another file... The CSV part is ok, but when I use \r in CStrings, I get a "block" character.. I know it is ok but if I view it in Notepad or any other file viewer, there won't be any carriage returns, just those characters representing the \r...
Why is that?
Thanks!
---------------
Tired of Spam? Introducing InboxShield® for Microsoft® Outlook®
http://www.edovia.com
|
|
|
|