|
void EditorBasePage::DoDataExchange(CDataExchange* pDX)
{
DDV_MinMaxInt(pDX, m_nOSDItemPosX, 0, 200);
}
The above is the validation done by MFC generated code for an edit control
So any violation of data within the range(0 to 200) will be warned automatically by windows.
But windows do not highlight the edit control which was validated.
Whenever the data violation occurs,I need to set the caret selecting all the text in that particular control .
I know that SetFocus() and followed by SetSel(NULL,-1, NULL) will be do the job .But i have lot of edit boxes & I would like to know if
there are any means this will be automatically taken care by any macro.
laiju
|
|
|
|
|
DDV_MinMaxInt() only validates when the OK button is clicked. I find it better to not enable the OK button until all requirements have been met. Something like:
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
ON_EN_CHANGE(IDC_EDIT1, UpdateControls)
ON_EN_CHANGE(IDC_EDIT2, UpdateControls)
ON_EN_CHANGE(IDC_EDIT3, UpdateControls)
END_MESSAGE_MAP()
void CMyDlg::UpdateControls( void )
{
bool bEnable = true;
bEnable &= (m_edit1.GetWindowTextLength() > 0);
bEnable &= (m_edit2.GetWindowTextLength() > 0);
bEnable &= (m_edit3.GetWindowTextLength() > 0);
CString str;
m_edit3.GetWindowText(str);
bEnable &= (atoi(str) >= 0 && atoi(str) <= 200);
m_btnOK.EnableWindow(bEnable);
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
thanx a lot for ur suggestions i shall take them
laiju
|
|
|
|
|
Dear all,
I want to write my own DHCP client.But I do not know how to start. Is this protocol could be programmed in high layer or below layer. Anyone has any idea about that or could you show me if there any sourc code of that.
|
|
|
|
|
How can i get RTP and RTCP implentation for windows
|
|
|
|
|
Hi fellow developers,
I've writing a handler for WM_CHAR
What I want to do if the cut, copy or paste is used. How programatically examine what text ins in clipboard.
You help would be greatful if someone could provide me with code.
Thanks Alton
|
|
|
|
|
|
try these Api's
OpenClipboard :- for Opening Clipboard
IsClipboardFormatAvailable :- Checking the requested Data format available.
SetClipboardData/GetClipboardData :- For Geting and Setting data into or from Clipboard
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I´am working on a project where i have to query some values from a database.
I have to convert those values into letters from 'a' to 'z'.
example:
value: letter
1 -> 'a'
2 -> 'b'
3 -> 'c'
...
27 -> 'aa'
28 -> 'ab'
29 -> 'ac'
The letters can go up to 'zzzz'
Can anybody help me with this stupid thing?
P.
|
|
|
|
|
Maybe something like that:
int Number = 57;
char szString[255];
strcpy(szString,"");
while (true)
{
if (Number>=27)
{
strcat(szString,"a");
Number -= 26;
}
else
{
char Temp;
Temp = Number + 97;
int StrLen = strlen(szString);
szString[StrLen] = Temp;
szString[StrLen+1] = '\0';
break;
}
}
Ok, I didn't tested it so there could be some mistakes but this gives you the general idea
|
|
|
|
|
you code won't work because you consider that if (Number>=27) only...
but if Number == 53 , the result must be "ba" , etc...
as P-Rex said, there are until "zzzz" possibilities, that means 26^4 = 456976 cases...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I think you didn't understand completely my code
For exemple if Number == 53, the result must be "ab" and not "ba".
Thus in my code, if (Number >= 27), I DON'T jump out of the loop but comes once again in the loop, thus adding 'b' to the already existing string (that contains 'a').
Is it a little bit clearer ?
[EDIT] Sorry, I don't add 'b' but 'z' because 53-27 = 26 that corresponds to 'z'
[EDIT2] After 2 minutes of reflexion, I see that there effectively a problem in the code . There will only be 'a' in the begining of the string... I must not subtract but rather divide by 26... But I think the other solutions are good
|
|
|
|
|
You sound like you have it. But in case you haven't thought of this, you can imagine you are working with a base 27 system of numbers and you are converting from decimal.
Begin by checking if your value is greater than (27^3+1) if it is get the mod of your input number by (27^3+1 because a is 1), that's your first digit which falls between 0 and 26. then subtract that number off your working total. Then check if the remainder is bigger than (27^2+1). If it is, then mod by (27^2+1), that's your second digit. And so on. Since you are working with a-z just add the value of the char('a') to each mod and save yourself a switch statement. One for loop of four iterations should do it.
|
|
|
|
|
<br />
CString str;<br />
int number = 53;<br />
<br />
do<br />
{<br />
number--;<br />
str.Insert(0, 'a' + (number % 26));<br />
number /= 26;<br />
}<br />
while (number > 0);<br />
<br />
TRACE(_T("str: %s"), str);<br />
|
|
|
|
|
Thanks, you are my hero.
I didn´t thought that this is so easy
Pascal
|
|
|
|
|
As he properly realized, going from a number to a 'A' to 'ZZZZ' representation is the same as printing the number base 26 where the digits are the letters 'A' - 'Z'. If you wanted to write a number converter to print that value as decimal, then just change the / 26 to / 10 and the initial character from 'A' to '0'.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
<font color=blue>int</font> iVal = 453; <font color=green>
<font color=blue>char</font> Result[5] = <font color=gray>""</font>;
<font color=blue>if</font> (iVal >= 17577) { <font color=green>
Result[0] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[0] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 677) { <font color=green>
Result[1] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[1] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 27) { <font color=green>
Result[2] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[2] = <font color=gray>'\0'</font>;
}
<font color=blue>if</font> (iVal >= 1) { <font color=green>
Result[3] = (iVal % 26) - 1 + <font color=gray>'A'</font>;
}
<font color=blue>else</font> {
Result[3] = <font color=gray>'\0'</font>;
}
Result[4] = <font color=gray>'\0'</font>;
<font color=green>
<font color=blue>for</font> (int</font> i = 0, i < 4, i++) {
<font color=blue>if</font> (Result[1] == <font color=gray>'\0'</font>) {
Result[i] = Result[i+1];
}
}
i didnot tested however...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
|
|
What value is represented by '0' ?
If you know that, then you have a base 26 system.
See, everything goes up to 26, then it carries over one place.
You are just mapping a base 26 numeric system to letters.
|
|
|
|
|
Sometimes when calling a method "BeginMessage" on an out of process COM component I get the error "The Server Threw an Exception".
I want to use SetUnhandledExceptionFilter in the COM component to set up my own handler "TopLevelHandler" for this error so that I can write a minidump file when it occurs.
My problem is that the handler I set up never gets triggered I just continue to receive the original error "The Server Threw an Exception".
Why wont the COM Component trigger my handler? Is it because there is another global handler that overrides mine? I've noticed that the debugger also never breaks in when the error occurs.
Something clever
|
|
|
|
|
I'm currently reading in a binary file which contains hexadecimal data, however I then need to convert this data from hexadecimal into binary (as well as swap the ordering from least significant bit to most significant bit, i.e. if I get (in hex) C9 6F in I need to swap these to 6F C9 and then convert it into binary, i.e. 0110 1111 1100 1001).
Does anyone know if there is a system call for doing this (or a standard algorithm). I've looks at htons (and other methods) but they rely on the data type being 'short' whereas the data read in from the file is stored as a 'char' in an array.
TIA,
Andy
|
|
|
|
|
Hi Andy,
How do you want to store the binary? So you want a string that reads "0110 1111 1100 1001"? or is it in a 16-bit variable?
As for swapping the bytes, store the bytes in array achOrig, then just bit shift them:
short int w16Bits = (achOrig[0] << 8) | achOrig[1];
Now you will have w16Bits = 6F C9 (in memory)
regards,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Thanks for the bit shift example.
The binary data will eventually get displayed on the screen but we will also be processing the data depending on what type it was originally (i.e. integer, sound, etc...), so if you could give me an example of how to do both types that would be great.
cheers,
Andy
|
|
|
|