|
Here is the codes
float a,b;
a = (( (AlphaTotal - PrevAlphaTotal) / PrevAlphaTotal ) * 100 );
b = (( (BetaTotal - PrevBetaTotal ) / PrevBetaTotal ) * 100 );
CString testing;
CStringList ReturnedData;
testing.Format("Alpha Percentage %f", a );
ReturnedData.AddTail(testing);
testing.Format("Beta Percentage %f", b );
ReturnedData.AddTail(testing);
(--->ReturnedData will be used to output in view class)
The results would be:
If a or b = 65.50...it displays 0.00
If a or b = 180.50...it displays 100.00
Why i know that because.....I try just type some number in the formula...for example,
a = ((700-500)/500)*100;
b = ((81-60)/60)*100;
Then output is:
Alpha Percentage 0.00
Beta Percentage 0.00
How to fix it??????????????????????
|
|
|
|
|
Are AlphaTotal, PrevAlphaTotal, etc. all integral types? Probably so. Use floating point types (or cast the variables to doubles) otherwise the division operator does an integer divide, which throws away any remainder. That's why 200/500*1000 is 0 - 200/500 is an integer divide and returns 0.
--Mike--
http://home.inreach.com/mdunn/
"Holding the away team at bay with a non-functioning phaser was an act of unmitigated gall. I admire gall."
Lt. Cmdr. Worf
|
|
|
|
|
Oh thanks!!!! It works now...
but i have one more question. For example,
a = 180.98763
I just want to display 180.99....and save it to a char or CString because i want to save to my CStringList........what can i do???
can i use:
char Buffer[128];
sprintf(Buffer, " %f %f", a,b);
I have a and b......I want to display liked:
| 180.98 | 123.56 |
??????
|
|
|
|
|
When i use this code to save the result to a char,
char Buffer[128];
sprintf(Buffer, " %f %f", a,b);
my program is forced to terminate....why?
|
|
|
|
|
For example, a = 180.98763 I just want to display 180.99
A format string of "%.2f" will do that. Check the printf() documentation for a full list of the format strings.
--Mike--
http://home.inreach.com/mdunn/
"Holding the away team at bay with a non-functioning phaser was an act of unmitigated gall. I admire gall."
-- Lt. Cmdr. Worf
|
|
|
|
|
I'm currently doing the following to load a bitmap
HBITMAP hBitmap =(HBITMAP) LoadImage(NULL,"c:/activextree/closedfolder.bmp",IMAGE_BITMAP,20,20,LR_LOADFROMFILE);
But need to be able to pull this off a network.
how can I do this?
What Id like to do is something like the following (which doesn't work)
HBITMAP hBitmap =(HBITMAP) LoadImage(NULL,"http://localhost/foo/closedfolder.bmp",IMAGE_BITMAP,20,20,LR_LOADFROMFILE);
thanks for any help
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
You'd need to first make a HTTP connection, then try it. Also you need to make sure that image can be read.
|
|
|
|
|
thanks for the response. What is the easiest way to make an http connection?
-Jack Mott
jackm@scalablesoftware.com
|
|
|
|
|
Well you could connect using the CHttpServer class. I can't help you with it's use, but you should just play around with it, cuz I don't think it's well documented.
|
|
|
|
|
I want to paint small icon part of a bitmap over a Cstatic background image. (and also over another static transparent text)
All is fine if I disable the CStatic bitmap my small icon bitmap
is drawed but when I enable the background my icon does not appear.
I think that it's drawed before the CStatic bitmap an thus erased ?
here is the code that draw the small bmp part: (code from
"Drawing Transparent Bitmap with ease with on the fly masks in MFC
By Raja Segar"
void CMydialogDlg::OnPaint()
{
////////////////////////////////////////////////////
//PAINT THE ICON
CPaintDC dc(this); // device context for painting
CDC dcMem; // memory device context
dcMem.CreateCompatibleDC(&dc);
// Select the bmp into the tmp memory DC
CBitmap* pOldBmp = (CBitmap*) dcMem.SelectObject(&m_bmpPLMain);
DrawTransparentBitmap( &dc, // The destination DC.
0, // Where to draw
0,
16, // Width & Height
16,
&dcMem, // the DC holding the bmp
0, // x & y pos in source bmp
0);
CDialog::OnPaint();
}
seem tricky uh ?
Thanks
|
|
|
|
|
Call the CDialog::OnPaint in the beginning of your function
Bjarne Nielsen
|
|
|
|
|
>Call the CDialog::OnPaint in the beginning of your function
already tried but it don't work at all.
The only things that was able to *draw* over the Cstatic Bitmap was to
deal with the CTlcolor function but the result was at least
very bad and strange (perhaps wrong method ?)
My bmp need to be draw over all the other graphic.
Anyway thanks for the reply
Any other solution ?
|
|
|
|
|
I have a byte array that is allocated with a size of 4096. That is the max, and I will probably never fill up the array. Then I pass this array to a function that needs to send all that data that is in the array to the serial port.
What is the best way to go about this?
My first idea was to create a CString object to represent the data....like so.....
void SendDataToPort(unsigned char * pData)
{
CString StringToSend;
int iCursor = 0;
while(pData[iCursor] != NULL)
{
StringToSend += pData[iCursor];
iCursor++;
}
// Use either CString::GetBuffer() or CString::operator LPCTSTR() to get the string.
// Sent it.
}
I would think there is an easier way to do this to do this. Also, what is the syntax for using CString::operator LPCTSTR(). Last, I noticed when people post code in messages, they can make it appear with a yellow background, and the code format remains in-tact, how is that done?
Thanks,
John
|
|
|
|
|
CString is not a good idea if there are 0 bytes in your array. Can you just pass the array and the # of bytes to send to the function? If not, use MFC's CByteArray class to hold the bytes.
--Mike--
http://home.inreach.com/mdunn/
"Holding the away team at bay with a non-functioning phaser was an act of unmitigated gall. I admire gall."
Lt. Cmdr. Worf
|
|
|
|
|
I need to send the data in this array with the WriteFile() function. The array is passed in like so:
void SendArray(unsigned char * Data)
How come when I send this array using WriteFile() it always sends 4 bytes, versus sending all the data in the array, here's what I use..
WriteFile(hPort, Data, sizeof(Data), &dwBytesSent, NULL);
|
|
|
|
|
> WriteFile(hPort, Data, sizeof(Data), &dwBytesSent, NULL);
The reason it only writes 4 bytes is because your asking it write the size of a pointer, which is only four bytes. You should add another parameter to tell WriteFile how many bytes to write.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Greetings,
I was wondering how I can get a LOGFONT from an IFont without using a CFont.
For I am in a atl object, and I don't have access to a CFont MFC class.
I am interested in getting the actual pixel size of the text, but the IFont's
get_Size() gets me the size in CY*pSize, and I don't know how to convert it
into the LOGFONT's lfHeight.
I assume that the text width is somehow store in the "CY" object, but I am not
sure how to work with it for I am very new to COM.
Thanks for any help.
|
|
|
|
|
from mapidefs.h line 396
typedef union tagCY {
struct {
#ifdef _MAC
long Hi;
long Lo;
#else
unsigned long Lo;
long Hi;
#endif
};
LONGLONG int64;
} CY;
and from MSDN
IFont::get_Size
Retrieves the point size of the font expressed in a 64-bit CY variable. The upper 32-bits of this value contains the
integer point size and the lower 32-bits contains the fractional point size.
HRESULT get_Size(
CY* psize
);
Parameters
psize
[out] Pointer to the caller-allocated variable that receives the size.
Return Values
The method supports the standard return value E_UNEXPECTED, as well as the following:
S_OK
The size was retrieved successfully.
E_POINTER
The address in psize is not valid. For example, it may be NULL.
CY CYsize;
pIFont->get_Size(&CYsize);
int Height = CYSize.Hi;
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
If CFont has the capabilities to do the conversion, why not copy the code from there.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
If I have an .INI file stored on a server and several instances of an application (on different PCs) accessing it by means of GetPrivateProfileString() function. Is it possible for one user to lock the file by calling GetPrivateProfileString() and causing another user's GetPrivateProfileString() call to fail? In other words, what happens when two users attempt to access the same .INI file at the same time?
D Osborn
|
|
|
|
|
Are all of the machines that are trying to access this ini file running the same version of windows? If not, is it always the Win 9x/ME machines that are failing?
|
|
|
|
|
For those who came in late ...
The 1st Phantom swore an aoth on the skull of his father who had been killed by Pirates to fight evil. Ghost Who Walks .....
Whoops sorry wrong story. Anyway my All American Dream Database program continues. Previous help I received here recommended I set the width of the first column of my ListCtrl to zero to hide the Primary Key from the user. This worked a treat, I required the key to be in the row to make it easy for myself to update the selected database record when required.
Now I wish to allow my user on another screen to reorder the records independant of the key. By this I mean I have an Order column for use in reports that the user can reset the order.
I envisaged using the ListCtrl that has become my friend in this project. I would display the Customer (with hidden Primary Key), allow them to re-order the list and then I would cycle through the records updating them sequentially with the new order.
Problem is the SetItemPosition() function only works when in Icon or Small Icon mode and SetExtendedStyles only has drag and drop ability on rows not columns. Of course I am using Report mode and need to re-order the rows not columns. This stops me from using drag and drop or Up/Down command buttons to enable the re-ordering.
What have I missed? I'm sure it is obvious but not to me. How should I be doing this, preferably I would like to be able drag the row into it's new position.
Thanks in advance for the help.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
Hi all,
I have a question. I am writing a program that scans the keyboard for keypresses and stores them in a file. This seems to work fine when I use it in the main app window but when I want to go to another external application and scan for keypresses there it won't let me do it. Has anybody got any suggestions on how I could do this or has anybody any example source code for this?
I would be very grateful if you could help me.
cheers,
Dave.
P.S. if you could mail me at david.higgins@compaq.com with any suggestions I would be grateful too.
|
|
|
|
|
Hi David!
See MSDN article "Win32 Hooks".
|
|
|
|
|
I overrided the OnCreateClient function for my MDI child window to add a splitter. Everything work just fine except when I type into one of the views I get an illegal error, and I beleive everyone knows what i'm talking about. I was just really hoping someone here could help me with this problem. Also I am compiling with a shared DLL for MFC and service pack 3.
|
|
|
|