|
Hi,
in my code i have to take astring from edit box, then it should read each and every character in string, and find the decimal number of each ASCII character and ,for this i used the fallowing code but it doesn't worked..
**
UpdateData(TRUE);
int Length = m_strEdit1.GetLength();//m_strEdit1 is member variable of editbox
TRACE( "Stringlength: %i\n", Length );
int i = 0;
int q;
int p;
while( i < Length)
{
char c = m_strEdit1[ i ];
TRACE( "%c ASCII %i hex %x\n", c, c, c );
q=atoi(c);
p=int(c);
++i;
}
*****
can you please help me how to do this..
Thanking you.
sheshidar patnam
|
|
|
|
|
I haven't tested it but shouldn't this work?
int i;<br />
int length = str.GetLength();<br />
int p;<br />
for (i = 0; i < length; i++)<br />
{<br />
p = str[i];<br />
TRACE("%i\n",p);<br />
}
this is this.
|
|
|
|
|
Thx very much my friend..
|
|
|
|
|
Simply:
char c = m_strEdit1[ i ];<br />
int AsciiValue = (int)c;
The atoi function will try to transform a string representing an integer value (for example the string "123456" ) to its integer value (thus to the integer 123456 ). If you want to get the ASCII value of a char, just cast it to an integer because the character IS the ASCII number
|
|
|
|
|
sheshidar wrote: int Length = m_strEdit1.GetLength();//m_strEdit1 is member variable of editbox
TRACE( "Stringlength: %i\n", Length );
int i = 0;
int q;
int p;
while( i < Length)
{
char c = m_strEdit1[ i ];
TRACE( "%c ASCII %i hex %x\n", c, c, c );
q=atoi(c);
p=int(c);
++i;
}
change above code to :-
m_strEdit1.GetLength();
TRACE( "Stringlength: %i\n", Length );<br />
int i = 0;<br />
int q;<br />
int p;<br />
while( i < Length)<br />
{<br />
char c = m_strEdit1[ i ];<br />
TRACE( "%c ASCII %i hex %x\n", c, c, c );<br />
p=int(c)-41;
++i;<br />
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi, I discovered that PlaySound does return TRUE on Windows XP systems even when the given filename does not exist. So you get a TRUE return value and GetLastError returns 2 (file not found).
However this problem is Windows XP specific for me, on a old Win9x this does not happen? I wonder if this is a known bug ... more code details needed?
/M
-- modified at 6:40 Monday 5th December, 2005
|
|
|
|
|
Here some code to reproduce the problem I described:
#include <mmsystem.h>
void CTestsoundDlg::OnOK()
{
CString sOutput;
CString sFileName = "soundfile.wav";
if(!PlaySound(sFileName, NULL, SND_FILENAME + SND_ASYNC + SND_NODEFAULT))
{
sOutput.Format("Playing sound file '%s' failed... %s (returned %d)",
(LPCSTR)sFileName, GetLastError()==ERROR_SUCCESS?"OK":"ERROR", GetLastError());
} else {
sOutput.Format("Playing sound file '%s' sucessfull... %s (returned %d)",
(LPCSTR)sFileName, GetLastError()==ERROR_SUCCESS?"OK":"ERROR", GetLastError());
}
m_list.AddString(sOutput);
m_list.AddString("");
}
A possible workaround that works for Win9x and WinXP, please comment.
void CTestsoundDlg::OnOK()
{
CString sOutput;
CString sFileName = "soundfile.wav";
SetLastError(ERROR_SUCCESS);
PlaySound(sFileName, NULL, SND_FILENAME + SND_ASYNC + SND_NODEFAULT);
if(GetLastError()!=ERROR_SUCCESS)
{
sOutput.Format("Playing sound file '%s' failed... %s (returned %d)",
(LPCSTR)sFileName, GetLastError()==ERROR_SUCCESS?"OK":"ERROR", GetLastError());
} else {
sOutput.Format("Playing sound file '%s' sucessfull... %s (returned %d)",
(LPCSTR)sFileName, GetLastError()==ERROR_SUCCESS?"OK":"ERROR", GetLastError());
}
m_list.AddString(sOutput);
m_list.AddString("");
}
|
|
|
|
|
Does sndPlaySound() behave any differently?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I haven't tried. I am now checking the file access myself before calling PlaySound.
|
|
|
|
|
I had some weird problems with sound capture and playback functions on a PC which has Realtek AC97 audio on the motherboard. I solved them by installing the latest (unsigned) audio drivers. The last official (signed) drivers did not fix the problem.
Another thought - MSDN help on PlaySound says "If it cannot find the specified sound, PlaySound uses the default system event sound entry instead. If the function can find neither the system default entry nor the default sound, it makes no sound and returns FALSE." So if the default sound exists, you will not get a FALSE return even if the sound file does not exist.
And another thought - are you sure the GetLastError() value of 2 is a result of the PlaySound function? MSDN help on GetLastError says "If the function is not documented to set the last-error code, the value returned by this function is simply the most recent last-error code to have been set; some functions set the last-error code to 0 on success and others do not." And PlaySound's MSDN documentation does not say anything about error codes, so . . .
You could try GetLastError() before and after PlaySound(), to see if PlaySound is setting the last error code to 2, or if this is left over from some previous error.
|
|
|
|
|
Thanks for the feedbacks!
MSDN is a bit ambigous here? Should it return TRUE or FALSE when no sound is played, I interpreted that TRUE indicates a sound is played and could be dead wrong.
About GetLastError, I am setting it to 0 (ERROR_SUCESS) before calling the API function... please see code snippet I posted. This way I make sure that an error code indicates an error from PlaySound() and not from a previous API call. As you said the PlaySound documentation doesn't say anything about setting error code on sucess. Well, the code snippet I posted looks like a dirty hack and I decided to test file access before calling PlaySound()...
...here my new (pseudo) code:
<br />
MyFileClass file;<br />
if(file.open(sFileName)) <br />
PlaySoundFromFile(sFileName);<br />
else<br />
PlaySoundFromResource();<br />
Cheers, Moak
|
|
|
|
|
Yeah - MSDN documentation of API functions is not great.
What will PlaySound() return if your file is not present and you have specified SND_NODEFAULT? Good question. I have no idea!
The MSDN documentation for PlaySound does not mention LASTERROR - this may mean that it does not set LASTERROR even if there is an error. I guess this value is set by the lower-level OpenFile function which PlaySound invokes. Maybe PlaySound only returns FALSE if the actual sound-playing routine fails, not if a lower-level file function fails?
The MSDN info on GetLastError indicates that on Win9x, some 16-bit functions (including some multimedia functions) do not set the LASTERROR value, so it seems unsafe to depend on GetLastError under Win9x. This indicates your new approach might be better.
One comment on your new pseudo-code - if you open the file to check that it exists, you probably need to close it before doing PlaySound.
|
|
|
|
|
hi
I'm facing this problem for very long time, could anyone please help in finding the reason to why arrow keys are unable to focus on the help key from OK and Cancel button in C property sheet and when we do not have Active Control X also.
simhadri
|
|
|
|
|
hi
I'm facing this problem for very long time, could anyone please help in finding the reason to why arrow keys are unable to focus on the help key from OK and Cancel button in C property sheet and when we do not have Active Control X also.
|
|
|
|
|
Hi all,
Is there any way to automate ms-paint?
if yes, please guide.
Regards,
Ankush Mehta
|
|
|
|
|
About the only automated thing I know you can do with it is open and print. Other than that, I do not know of its having a COM interface.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Hi David,
i exactly want to open & print only. Please Help. A Code snippet will be highly appreciated.Expecting a reply soon!
Regards,
Ankush Mehta
|
|
|
|
|
Ankush Mehta wrote: i exactly want to open & print only.
You can use ShellExecute() with the open and print verbs.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
hi ..
i need to know how to call the OnDraw() from a classs that is outside..
the view class... i tried out with view class object but its not working..
Any suggestions with a sample code..
Thanks in advance..
vj
|
|
|
|
|
You can call OnDraw() from outside the class, but you will need a pointer to the view object. The pointer can be like:
CMyView* pView;<br />
pView = ... the view object's pointer.<br />
Then you can use:
pView->RedrawWindow();<br />
pView->Invalidate();
this is this.
|
|
|
|
|
hi tried as you said but its still says "Invalid Identifier"...
|
|
|
|
|
Where exactly outside of the view are you trying to access the view? Is it your own class? Is it from a thread? Is it from mainframe? Is it from the document?
If it is a separate class, then I could suggest:
class CMyClass<br />
{<br />
...<br />
public:<br />
CView* m_pView;<br />
};<br />
CMyClass Object;
Now you need to initialize the pointer to the proper value.
If you are calling it from the view then:
Object.m_pView = this;
etc.
this is this.
|
|
|
|
|
Hi, I have problem When executing my MFC application. It makes rebuild all and no problem. When I click on '!' Execute Program. It doesn't give any response. It doesn't give any error. The dialog does not appear. I am using Microsoft Visual Studio 6.0. What can be the problem?
|
|
|
|
|
You have not provided enough info like: is the code your own? What configuration is it (release/debug) ? Is it dialog-based, is it command-line based? etc.
There could be a dynamic library missing etc; the program tries to open non-existent files; Windows does not like your program because you are accessing un-allocated memory, and is shutting down your program without notice; You are allocating too much memory in static objects, which is not available;
It could be something else also.
this is this.
|
|
|
|
|
MuratMetu wrote: The dialog does not appear.
Does the dialog have any ActiveX controls on it?
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|