|
Antony M Kancidrowski wrote:
You are missing an open bracket at the start of the if statement
correct... and corrected
but you understood what i would like to explain, isn't it ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I would like to set the listcontrol so that items (in the first column) *cannot* be selected. This can be done in a listbox, but is there any way to fix a listcontrol to behave this way ?
Thanks in advance,
Raymond Mercier
|
|
|
|
|
Hey,
Well a short question realy.
What does the ^ do in C++?
example:
int number = 0;
number ^= 1;
the output for number is 1. When in math would be 0.
Thanks.
humpa humpa
|
|
|
|
|
^ is the bitwise exclusive-or operator
SO :
0x1100
^ 0x1010
-----------
= 0x0110
that's why
number ^= 1;
means
number = number ^ 1;
means
number = 0 ^ 1; // == 1
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I see. Thanks for your quick answer.
humpa humpa
|
|
|
|
|
http://www.codeproject.com/cpp/bitbashing.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!
|
|
|
|
|
Hi,
I'm using the following code to try to get a double variable from an edit box, but I keep getting an error: c2660
<br />
double x=0;<br />
CString strx;<br />
......<br />
<br />
for(int i=0;i<K,i++)<br />
{<br />
::GetDlgItemText(IDC_WELLRAD,strx);
x=atof((LPCTSTR)strx);<br />
...<br />
}
How can I fix this error, please? what is HWND hdlg??
|
|
|
|
|
aaadetos wrote:
what is HWND hdlg??
Is the handle to the dialog window.
Assuming you are running this code in a CDialog derived class.
You could try something like this:
HWND hWndDlg = GetSafeHwnd();
You can then use this to get the handle to the control.
HWND hWndCtrl = ::GetDlgItem(hWndCtrl, IDC_WELLRAD);
Then use the control handle with GetWindowText()
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
I'm sorry. Please see the revised code: i meant to type: GetDlgItemText , not GetDlgItem . the function in which I'm using GetDlgItemText is not in the CDialog class. How would I use GetSafeHwnd() then?
|
|
|
|
|
The easiest way is to have a pointer to your dialog class within the class that you have the code.
Header file
CMyDialog* m_pMyDialog;
CPP file
HWND hWnd = m_pMyDialog->GetSafeHwnd();
etc...
IMPORTANT: Note that you need to set m_pMyDialog to point at your dialog class before using it.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
CString strEdit;
((CEdit*)GetDlgItem(IDC_MY_EDIT))->GetWindowText(strEdit); TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
You do not need to cast to CEdit as CWnd will do
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
[Perplexed!]
I already tried to do the following:
<br />
{<br />
...<br />
CString strx;<br />
CDialog *pDialog;<br />
<br />
pDialog -> GetDlgItemText(IDC_WELLRAD,strx); <br />
x = atof((LPCTSTR)strx);<br />
...<br />
}
and toxcct's code as well. The first gave an ASSERT error while the other gave an unhandled exception in mfc42d.dll, in wincore.cpp ->C:\...\MFC\SRC\WINCORE.CPP at the line *** below:
<br />
HWND hWnd = ::GetDlgItem(m_hWnd, nID);<br />
if (hWnd != NULL)<br />
{<br />
int nLen = ::GetWindowTextLength(hWnd);<br />
::GetWindowText(hWnd, rString.GetBufferSetLength(nLen), nLen+1);
rString.ReleaseBuffer();<br />
}<br />
I'm trying to get the value of an edit box for use in a function outside CDialog, which would carry out computations on the value entered by a user. I don't understand why i get these errors.
|
|
|
|
|
aaadetos wrote:
I'm trying to get the value of an edit box for use in a function outside CDialog, which would carry out computations on the value entered by a user.
The function in which you are getting the Text is outside CDialog??
|
|
|
|
|
Yes, it is. The text: numerical data of type double, is to be used as a variable in a math computation in a function outside of CDialog.
|
|
|
|
|
If what i understood is correct ...
you are doing like this....
void CXDialog::Function1()
{
SomeOtherClassObj.YourMathFunction();
}
void CSomeOtherClass::YourMathFunction()
{
GetTheText();
//TODO
}
Think you have to pass the dialog pointer to your function outside the dialog class...
like...
void CXDialog::Function1()
{
SomeOtherClassObj.YourMathFunction(this);
}
void CSomeOtherClass::YourMathFunction(CDialog *pDialog)
{
pDialog -> GetDlgItemText(IDC_WELLRAD,strx);
x = atof((LPCTSTR)strx);
//TODO
}
Or get the Edit control text inside the Dialog class which contains the control and pass the text to your math function...
Hope this will help you ....
|
|
|
|
|
Thanks a lot Dreamz...
I actually decided to add a member function to my dialog's class, viz:
<br />
double CKuchukDlg::getrw(double x)<br />
{<br />
CString strx;<br />
<br />
GetDlgItemText(IDC_WELLRAD,strx);<br />
x = atof(strx);<br />
<br />
return x;<br />
}
i then used the function in my math function, to get the value of the edit box:
<br />
void bessk0(double *x,double *k0,int nSize);<br />
void bessk1(double *x,double *k1, int nSize);<br />
void ei(double *x, double *expi, int nSize);<br />
<br />
void unbound(double *unbd, int nSize)<br />
{<br />
enum{nSize = 100};<br />
double A[nSize],B[nSize],k0[nSize],k1[nSize],s[nSize],expi[nSize],a[nSize],b[nSize];<br />
<br />
<br />
double x=0;<br />
s[0] = 1;<br />
a[0] = x*sqrt(s[0]);<br />
b[0] = 2*sqrt(s[0]);<br />
<br />
bessk0(a,k0,nSize);<br />
bessk1(a,k1,nSize);<br />
ei(b,expi,nSize);<br />
<br />
A[0] = k0[0]/(x*sqrt(s[0])*k1[0]);<br />
B[0] = (1-exp(-2*sqrt(s[0])))/(2*sqrt(s[0]));<br />
<br />
unbd[0]=0.5*(A[0]-B[0]-expi[0]);<br />
<br />
<br />
CKuchukDlg MyClass;<br />
MyClass.getrw(x);<br />
x = MyClass.getrw(x);<br />
<br />
for (int t=1;t<nSize;t++)<br />
{<br />
<br />
s[t] = 2*t*PI;<br />
a[t] = x*sqrt(s[t]);<br />
b[t] = 2*sqrt(s[t]);<br />
<br />
bessk0(a,k0,nSize);<br />
bessk1(a,k1,nSize);<br />
ei(b,expi,nSize);<br />
<br />
A[t] = k0[t]/(x*sqrt(s[t])*k1[t]);<br />
B[t] = (1-exp(-2*sqrt(s[t])))/(2*sqrt(s[t]));<br />
<br />
unbd[t]=0.5*(A[t]-B[t]-expi[t]);<br />
}<br />
}
While the code compiles without error, i still obtain a debug assertion failure in wincore.cpp!!
Is there a better way of calling my getrw(double x) in my math fxn without having this problem?
Thank you.
|
|
|
|
|
aaadetos wrote:
CKuchukDlg MyClass;
MyClass.getrw(x);
x = MyClass.getrw(x);
You have got a dialog displayed already from where you get the Edit control' text.That is an existing instance of the class CKuchukDlg.You have to use the same instance for further operations.
Here what you do is,you have created an instance of CKuchukDlg.But no Dialog window is there for the paticular instance.And you are trying to get the Text from the Edit control.There is no such window to get the Text from.So you are getting the assertion failure.
This why i asked to use "this" poiter.
If you are calling "unbound(double *unbd, int nSize)" from your dialog class
pass the pointer of your "Current Dialog Window" to the function.
void unbound(double *unbd, int nSize,CDialog *pDialog)
{
........
//x = MyClass.getrw(x);
x = pDialog->getrw(x);
........
}
You can call the function like this...
SomeObj.unbound(x,y,this);
Better you can pass the Text from the edit control itself to the function.
void unbound(double *unbd, int nSize,double DataFrom_getrw)
{
........
//x = MyClass.getrw(x);
x = DataFrom_getrw;
........
}
|
|
|
|
|
In your code
CDialog *pDialog;<br />
<br />
pDialog -> GetDlgItemText(IDC_WELLRAD,strx);
you have not assigned a value to pDialog after declaring it and before using it.
pDialog must be assigned as a pointer to your dialog.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)
|
|
|
|
|
Antony M Kancidrowski wrote:
You do not need to cast to CEdit as CWnd will do
i know, but i prefer a most "understandable" code than one that works, but which you cannot debug...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I would like to generate human friendly product keys similar to what Microsoft and many others do. The keys should have the property of being 25 or 30 characters.
I need to be able to generate many individual keys, on the order of 10000 or so probably.
They should be generated in such a way that it is easy to verify that a particular key is one which I generated, but hard for someone else to generate the identical list of keys. I am aware of commerical products that do this, but it seems like something that wouldn't be that hard to reinvent.
It appears to me that this requirement calls for use of an asymmetric crypto algorithm.
Like all locks, this one is intended to help honest people stay honest. I'm not too worried about the hacker with a disassembler, but it ought to be at least challenging for him to generate a valid product key.
Any suggestions, especially pointers to sample code, will be greatly appreciated.
Jim
|
|
|
|
|
this might work:
assuming you're using RSA (or something similar):
1. come up with a public/private key pair.
2. put one of your keys in your app, and one in your license creator.
3. generate a series of short plaintext strings like this: "SomeText_######" , where ###### is an incrementing counter, or a time stamp, or some other unique value (just to ensure that no two codes are the same). the actual content doesn't matter to the algorithm, only that the form of the string can be verified when decoded.
4. encrypt each of those strings with your license creator key. then output them as hex strings: a0b4-d3ee-091c-etc. the code length will depend on how big the input data was.
5. distribute those keys to your users.
6. when your app gets a license code, decrypt it using the key from #2.
7. if the decrypted code matches the form from #3, it's a valid license code.
take a look at crypto++[^].
Software | Cleek
|
|
|
|
|
That's a good idea, but I have a question about step #5, "distribute those keys to your users".
I would like to have a fixed length key of no more than 30 characters, similar to what microsoft does. I'm not sure that's feasable if the key is just hex strings. I guess I don't grock the relationship between the lenght of the plantext and the lenght of the cyphertext.
Perhaps I should encode the key with a base 26 system.
I already incorporate parts of crypto++ in my app for symmetric encryption, it is an excellent product.
|
|
|
|
|
Jim Howard wrote:
I guess I don't grock the relationship between the lenght of the plantext and the lenght of the cyphertext.
i believe RSA requires the block size to be the same as the key length. so, a 32 byte code string, based on 16 hex numbers, gives you a 128-bit key - not very big.
Jim Howard wrote:
Perhaps I should encode the key with a base 26 system
or base32. it gives you an extra byte of data for every 8 code charaters vs base16. (8 chars b32 = 40 bits. 8 chars b16=32 bits)
Software | Cleek
|
|
|
|
|
I search to know (in C++ & MFC) when a windows is finished to be move or resizing. To repaint it only at the end, not durin event.
Can you help me
Thank
Thierry
|
|
|
|
|