|
Thanx, that was very useful.
A studier of that sample have to change edt1 to cmb13, though. At least I had to, to make it runnable.
Cheers
Josef Granqvist
Swedish student and Indian trainee
|
|
|
|
|
Is there any single function to determine wether a folder is empty in VC++!
Thanks in advance
emmatty
|
|
|
|
|
emmatty wrote: Is there any single function to determine wether a folder is empty in VC++!
AFAIK, there is no such function... I believe you have to make your own.. you can use CFileFind Class to achieve same...
"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
|
|
|
|
|
There is not direct function in VC++(its not VB)
but
u can try finding the size of the folder but that
u can find if its empty or not
thank you
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Something like:
bool IsFolderEmpty( LPCTSTR lpszFolder )
{
CFileFind fileFind;
CString strFolder(lpszFolder);
bool bFound,
bEmpty = true;
bFound = fileFind.FindFile(strFolder + _T("*.*"));
while (bFound != FALSE)
{
bFound = fileFind.FindNextFile();
if (! fileFind.IsDots())
{
bEmpty = false;
break;
}
}
return bEmpty;
}
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
|
hi
i am converting a MFC ,MDI application to unicode.
when i run the program in release version it runs fine but once i set the config to Unicode Release it just crashes at the start itself.(doesn't even show error msg but abruptly stops the execution of the program)
There are no compile time and linker errors.
i kept breakpoints and arrived at the conclusion that the crash occurs at following lines of code in InitInstance().
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
is there too much of difference between release and unicode version??
how to go abt solving that error....
Thanx in advance
|
|
|
|
|
Hi,
Do you call any other functions from InitInstance(). If yes, check whether you are handling any unicode data.
Bye,
Cool Ju
Dream Ur Destiny
|
|
|
|
|
Is the entry point set to 'wWinMainCRTStartup'? I ended up putting this in builds a long time ago for UNICODE:
#ifdef _UNICODE
#ifdef _AFXDLL
#ifndef _AFXEXT
#ifndef _WINDLL
#ifndef _USRDLL
#ifndef _CONSOLE
#pragma message("Project appears to be an MFC executable, changing entry-point function")
#pragma comment(linker,"/entry:wWinMainCRTStartup")
#endif
#endif
#endif
#endif
#endif
#endif
|
|
|
|
|
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
|
|
|
|