|
Greetings,
Frustrations from yesterday.I am trying to load a bitmap into a CBitmap object. I have succesfully done this 100 times before but this time I get an assertion error caused at AfxMakeResourceHandle(). I am calling the LoadBitmap() function at the constructor so it only takes place ones, so its not a problem of loading a bitmap over an existing one.
The image exists and the path is correct and the function is as follows:
[code]
m_bmKnob.LoadBitmap(IDB_51MAX);
[/code]
I have already made sure that there is no duplicate IDB number. Cannot find any informationm about this elsewhere. Something tells me its something very small and silly that I am missing but I have been going over and over it with no luck...
Thanks!
|
|
|
|
|
Some more details...
According to MSDN AfxGetResourceHandle is:
Use the HINSTANCE handle returned by this function to access the
application's resources directly, for example, in calls to the Windows
function FindResource.
Example
//Load the menu specifying the module handle where resource is to be
//found & resource ID
HMENU hMenu = ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_PANEL));
I have also tried:
m_bmKnob.FromHandle(LoadBitmap(_AtlBaseModule.GetModuleInstance(),
MAKEINTRESOURCE(IDB_51MAX)));
That compiles and doesn't give an assertion, however later when the bitmap
needs to be used it crashes as actually nothing was ever "sucessfully" loaded
into theCBitmap file.
Does this shed any light into possibilities? I willl post any progress as soon as there is some...have a nice weekend!
|
|
|
|
|
|
Hello,
The project contains several ATL based ActiveX controls with MFC support, the resources are added to the project.
|
|
|
|
|
Well...
it seems the answer is the following:
[code]
CBitmap myBitmap;
AFX_MANAGE_STATE(AfxGetStaticModuleState());
myBitmap.LoadBitmap(IDB_SOMEBITMAP);
[/code]
Now I need to figure out what that all means!
Ciao
|
|
|
|
|
Hi!
I've created an XML file in VS.NET.
I've created a Schema with "Create Shema" on the XML-menu.
My XML-file then look like this:
?xml version="1.0" encoding="utf-8"?<br />
ROOT xmlns="http://tempuri.org/XMLFile1.xsd"<br />
ELEM<br />
/ELEM<br />
/ROOT
(Taken away the > and < signs)
The Schema-file (XMLFile1.xsd) now exists in the current dir.
How do I now validate my XML against that Schema?
When I press: "Validate XML Data" on the on the XML-menu I got the following error:
Visual Studio could not locate a schema for this document. Validation can only ensure this is a well formed XML document and cannot validate the data against a schema.
_____________________________
...and justice for all
APe
|
|
|
|
|
I have a string that's about 450 bytes that I want to assign to a CString, but the string is getting cut off.
CString rawData(i_pszRawData);
int buffLen = rawData.GetLength ();
buffLen is always 230 and not 450 bytes!
If these an embedded zero or null character or binary zero in the string, is there a way around it so that the full 450 is assigned to the CString?
Thanks.
-C
|
|
|
|
|
Wheatbread wrote:
If these an embedded zero or null character or binary zero in the string, is there a way around it so that the full 450 is assigned to the CString?
CStrings are designed to hold zero-terminated strings. if you need to hold arrays with zeros in them, you'll need to use something else, like an array of BYTEs.
Image Toolkits | Image Processing | Cleek
|
|
|
|
|
Hi, I have encountered a problem with a very basic operation. does anybody have any idea about this?
Please see sample code below:
//////////////////////////////////////////
double a, b;
a = 99.99
b = 99.99
if (a <= b){
::MessageBox(NULL, L"TRUE", L"", MB_OK);
}
else{
::MessageBox(NULL, L"FALSE", L"", MB_OK);
}
//////////////////////////////////////////
somehow, it always display FALSE. Anybody knows how to handle this situation?
SDE
|
|
|
|
|
Doubles are NOT precise numbers. They are approximate representations. Whenever you need to compare doubles (or check if zero), you need to do approximate math, using an acceptable number of precision digits to your app. An example is below:
BOOL IsDoubleZero(double dVal)
{
if (dVal < 0.000001 && dVal > -0.000001)
return TRUE;
return FALSE;
}
BOOL AreDoublesEqual(double dVal1, double dVal2)
{
doubld dDiff = dVal1 - dVal2;
if (dDiff < 0.000001 && dDiff > -0.000001)
return TRUE;
return FALSE;
}
onwards and upwards...
|
|
|
|
|
Wow - never knew that. What about floats? Same thing? Hope so else I just screwed up an interview question!
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Angel1058 wrote:
What about floats? Same thing?
Yes.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I find that absolutely astonishing - you can't compare two doubles or floats for equality? So all these financial and scientific calculations using massive numbers with loads of decimal places aren't accurate - they are approximations?!?
It's not that I am doubting anything written here but I still find that amazing. 99.99 isn't guaranteed to equal 99.99.
Are there any precise types then?
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Angel1058 wrote:
So all these financial and scientific calculations ... they are approximations?!?
Correct.
Most scientific and financial applications (including my hack TakeStock[^] (forgive the shameless plug - but after all, it is freeware) will instead store floating point numbers as an aggregation of integers (which can be accurately compared).
So a bank balance of $12,345,678.90123 will instead be stored as the integer value 1,234,567,890,123 "milli cents". Since the number of mCents could be extremely large, you need store this value in a collection of int s. In the 70's and early 80's, many programmers used PL/1 which included a DECIMAL data structure for exactly this kind of thing.
Microsoft provides the CURRENCY [^] type that suffices for most financial calculations.
Hope this helps!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks guys. These have been a great help. I've been thinking about this for quite some time now.
|
|
|
|
|
Is this your actual code? What cmpiler, what settings do you use?
While it is true what was said - floats and doubles are not accurate representations - a simple assignment like yours typically is ok.
(And your ode with default debug/release settings outputs "TRUE" for me).
float and double both use a limited number of digits, certain numbers e.g 1/3, cannot berepresented accurately this way. Also, during calculations, final digits simply get lost. So comparing *results* as replied is a must.
However, you should also consider the alternative:
bool IsEqualRel(double a, double b, double eps = 1e-5)
{
_ASSERTE(a!= 0 && b != 0);
if (a==b) return true;
if (a<0 != b<0) return false;
return fabs((a-b)/a+b)) < eps;
}
bool IsZero(double a, double eps = 1e-5)
{
return a==0 || fabs(a) < eps;
}
which works for all magnitudes except comparison to zero (that's why the separate IsZero function).
With the absolute posted by the other guy, 1e-27 == 100e-27 and 10000000000000 != 10000000000001 which is often not what you need when working with numbers in this range.
I never really know a killer from a savior boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Hello All Great programmers!!
i am facing some exporting symbol from Win32 static Library.
i have declared function like this
extern const char * cl_strerror(int);
and when i call it from my mfc dialog based application( iam including required library file and header file in MFC app),it's give following error
testlibststaticDlg.obj : error LNK2001: unresolved external symbol "char const * __cdecl cl_strerror(int)" (?cl_strerror@@YAPBDH@Z)
Please somebody give some useful pointer
Ashutosh Tripathi
|
|
|
|
|
Hi
Use;
extern "C" const char * cl_strerror(int);
or
extern "C"
{
const char * cl_strerror(int);
}
to group more than one external reference.
Martin
|
|
|
|
|
when i declare char * cl_strerror(int); as
extern "C" const char * cl_strerror(int);
i got following error compiling the Library file
error C2059: syntax error : 'string'
Could you resolve the error please
Ashutosh Tripathi
|
|
|
|
|
Hi
Try changing it to this;
extern const char * __stdcall cl_strerror(int);
HTH
Martin
|
|
|
|
|
I know there are articles galore on double buffering but I can't get it to work!! I've copied below a very simple OnPaint method and nothing gets drawn. If I draw direct onto the CPaintDC it works. CGraphicStatic is derived from CStatic and the ON_WM_PAINT message map is used.
void CGraphicStatic::OnPaint()
{
CPaintDC actualDC(this);
CDC memDC;
memDC.CreateCompatibleDC(&actualDC);
CRect cr;
GetClientRect(&cr);
memDC.Rectangle(cr);
actualDC.BitBlt(0,0,cr.Width(),cr.Height(),&memDC , 0 , 0 , SRCCOPY);
}
but the following does..
void CGraphicStatic::OnPaint()
{
CPaintDC actualDC(this);
CRect cr;
GetClientRect(&cr);
actualDC.Rectangle(cr);
}
Hopefully, like my other posts, this is something stupid!
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
You need to create a bitmap and select it into the memory device context before you can draw on it.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
For a compatible DC, you have to give it a backing buffer - a bitmap object - to paint onto. A newly-created compatible DC has a 1-pixel monochrome bitmap selected into it. Any painting outside this area is simply discarded.
You need to create a new bitmap compatible with the original DC (using CreateCompatibleBitmap ) and select that into memDC using SelectObject before you start painting. If you make it compatible with the memory DC you get a monochrome bitmap, rather than one with the colour depth of the original.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Superb - worked a treat. Many thanks
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
I'm writing an add-in for IE and i would like to know if the document has been loaded entirely or it just resulted in a fragment (it happens oftenly when you hit the Stop button).
Do you know how could i accomplish this? I didn't find anything valuable from IHTMLDocument2 ...
"though nothing
will keep us together
we can beat them
for ever and ever"
rechi
|
|
|
|