|
Yes, it has worked.
Thanks for the inputs. Thank you very much.
|
|
|
|
|
HI,
i cannot copy CString value to char.but it show error.I typecast the CString value ,but still i get errors.
Pls help me out.
char cAlarmStatus;
CString AlCond;
if(...)
AlCond = "HH";
else
AlCond = "LL";
strcpy(objAlarmData->cAlarmStatus,(LPCTSTR)AlCond);
I get error that cannot convert parameter one form char to char*.
Pls help me how to copy this CString AlCond to cAlarmStatus
Anu
|
|
|
|
|
char T[100] = {0};
CString S = "Hello";
strcpy(T, S.GetString());
Maxwell Chen
|
|
|
|
|
To add with Maxwell's answer,
In your code you used 'char' and not 'char*'..
Try using as Maxwell said or you can allocate memory at runtime with the lenght of CString object and copy the string (but don't forget to release/delete the memory allocated)
Do your Duty and Don't expect the Result
|
|
|
|
|
What do you really need?
I mean, you cannot usually copy the whole CString content to a char variable (it can hold a single character), you need a character array or a pointer to dynamic allocated memory.
On the other hand, you probably don't need at a CString object:
const char * pszAlarmStatus;
if(...)
pszAlarmStatus = "HH";
else
pszAlarmStatus = "LL";
that's all.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
dear all
how to get index of minimum of one array? the following is my code...but however the outcome is wrong after compiled...actually the error is corrNum.
fitness[10] is an 10 elements array,first i would like to calculate minimum value of fitness, and then i need to use its index of this minimum value of array,but result is wrong.anyone can help me? thanks a lot.
for (int i=0;i<10;i++)
{
double minValue = fitness[9];
if (fitness[i] <= minValue)
{
minValue = fitness[i];
for (int j=0;j<150;j++)
{
value = h[i][j] - irisIndNew[j];
if (value == 0)
corrNum = corrNum + 1;
}
}
}
Li Zhiyuan
|
|
|
|
|
Try moving the line "double minValue = fitness[9];" outside of the for (int i...) loop. It's getting assigned to fitness[9] every time through the loop.
double minValue = fitness[9];
for (int i=0;i<10;i++)
{
if (fitness[i] <= minValue)
{
minValue = fitness[i];
for (int j=0;j<150;j++)
{
value = h[i][j] - irisIndNew[j];
if (value == 0)
corrNum = corrNum + 1;
}
}
}
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
thanks friend.
could you help me to check the following code? why i couldn't assign value of p[gbest_Ind][][] to gbest1[gbest_Ind][][], thanks a lot
minValue = fitness[0];
for (int count = 0;count<10;count++)
{
if (fitness[count] < minValue )
{
minValue = fitness[count];
gbest_Ind = count;
}
}
for (int j = 0; j<3; j++)
for (int k = 0; k<4; k++)
{
gbest1[gbest_Ind][j][k]=p[gbest_Ind][j][k];
}
Li Zhiyuan
|
|
|
|
|
#include <algorithm><br />
<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
double myArray[10] = {2.12,432.12,543.1,0.32,0.65,12.,54.2,542.5,100,200};<br />
<br />
double* start = myArray;<br />
double* minimumPosition = min_element(myArray, myArray + 10);<br />
<br />
double minValue = *minimumPosition;<br />
int indexOfMinimum = minimumPosition - start;<br />
return 0;<br />
}
|
|
|
|
|
I have a graph plotted on a picture control. Now I want to click the mouse on top of the graph (CDC * GraphRegion) and get the coordinate of the picture control of the clicked point. How can I do it?
|
|
|
|
|
Handle the OnLButtonDown of the picture control. It will pass you the coordinates of the mouse when it was clicked in a CPoint object. The point will be in client coordinates of the picture control.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Using VS2005 I often find myself making incremental changes to an app then finding that it will start crashing in some weird way. In the general, the weirder that it crashes - the better - because then I know to just clean the solution and rebuild it.
Just wondering what the general rule is on the optimal frequency of "build solution," "clean solution," and "rebuild solution." ?
As for me, as the first paragraph suggests - I just use "build" repeatedly until I start getting some weird heap corruption thingie that I'm pretty sure I'm not causing, by then I know it's time to "clean solution" and build again....
But that's just me - an amateur hack who's copy of Ivor Horton was stolen in Ecuador.
-@LRG
|
|
|
|
|
Hi all,
recently, I changed from VS2005/XP to VS2008/Vista. Suddenly, my MFC application wants to contact the IP 224.0.0.22. I know that this is an IP for some multicast protocol.
This did not happen with VS2005 under XP! I do not know if this is an VS2008 issue and/or Vista issue.
Is there any way to disable this ? I do not want to scare customers using my application thinking this is a virus or trojan...
Thanks Ingo
|
|
|
|
|
I want to test for an invalid character in entered numeric (integer) data,
(e.g., enter "d23", instead of "123")
In the following code, the do loop loops infinitely after
an invalid entry, "d23". Seems like cin is not stopping to
accept more input the second time around.
Can anyone tell me what I'm doing wrong?
Thanks,
Tom
------------------------
#include <iostream>
using namespace std;
void main()
{
int x;
cout << "Type in an integer value: ";
cin >> x;
while (cin.fail())
{
cin.clear();
cout << "Invalid character.\n Type in an integer value: ";
cin >> x;
}
cout << x << endl;
}
|
|
|
|
|
hain wrote: cin >> x;
while (cin.fail())
What about:
while (! (cin >> x))
{
cin.clear();
while (cin.get() != '\n');
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
dear friend
why we can't use cin.get directly here? why we use while loop here? thanks
Li Zhiyuan
|
|
|
|
|
Thanks David, terrific, that works perfectly!
Problem is, your solution is mysterious to me...
I don't understand it.
Why doesn't the get() move the stream pointer
forward (after an error), so that by the time we
get back to cin>>x, the extraction starts after the
'\n' (i.e., nothing is extracted)?
Thanks again,
Tom
|
|
|
|
|
cin >> x stops at the first whitespace, so cin.get() is used to get passed all that.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I should have been able to figure that out!
Thanks!
Tom
|
|
|
|
|
I'm trying to use the PSM_QUERYSIBLINGS message to query information between some CPropertyPages.
It works great if the pages have already been "shown" but the property page class never gets the message if the property page tab has not already been clicked on for that page. I thinks it's the issue of the propertypage window does not get created until it needs to.
How can I use PSM_QUERYSIBLINGS to get information from another propertypage object before the propertypage window is "shown"? Is there a way to force all the property page windows to exist from the start?
|
|
|
|
|
PROPSHEETPAGE Structure
...
PSP_PREMATURE flag:
"Version 4.71 or later. Causes the page to be created when the property
sheet is created. If this flag is not specified, the page will not be
created until it is selected the first time. This flag is not supported
when using the Aero-style wizard (PSH_AEROWIZARD)."
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I saw that earlier but my first question was does version 4.71 represent? MFC 4.71 ? or the control version is 4.71 ?
And my next question was concerning the PSH_AEROWIZARD. Does that mean if someone uses the page on a Vista box with Aero turned on, PSP_PREMATURE will be ignored?
Thanks for the response.
|
|
|
|
|
bob16972 wrote: my first question was does version 4.71 represent?
Shell and Common Controls Versions[^]
I'm not sure about the aero flag and/or Vista.
Regardless, sending messages to windows that don't exist isn't
going to work (obviously).
As David Crow mentioned, there shouldn't be any need to send messages to
pages the user hasn't (and may never) interacted with yet. If a page needs
some initialization value or needs to initialize controls, then it should be done
when the page receives the WM_INITDIALOG message and/or the PSN_SETACTIVE notification
(OnSetActive() in MFC).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Why would you need to query a page that has not been interacted with by the user?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|