Search This Blog

Saturday, February 7, 2009

Useful Cstring Functions



//For replacing nonprintable and non-ASCII unicode to space
CString RemoveNonPrintableCharWithSpacer(LPCSTR lpText)
{
CString csData;
for(;*lpText!='\0'; lpText++)
{
if(*lpText<0 || *lpText>255)
{
csData += " ";
}
else
{
csData += *lpText;
}
}

return csData;
}



//For counting no of small characters
unsigned int CountSmallCharacters(LPCTSTR lpText)
{
unsigned int nSCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if(*lpText>='a' && *lpText <='z')
nSCharCount++;
}
return nSCharCount;
}



//For counting no of characters
unsigned int CountCharacters(LPCTSTR lpText)
{
unsigned int nCharCount =0;
for(;*lpText!='\0'; lpText++)
{
if( (*lpText>='a' && *lpText <='z') || (*lpText>='A' && *lpText <='Z') )
nCharCount++;
}
return nCharCount;
}

Code to Click Internt Explorer Security warning Dialog Box

//Code to Click Internt Explorer Security warning Dialog Box Automatically

BOOL g_bStopDialogWatcherThread = FALSE; // To Stop & start Thread

UINT WindowWatcher(LPVOID lpParam)
{
g_bStopDialogWatcherThread = FALSE;
while(1)
{
Sleep(300);
HWND hWnd;
HWND hWndWarning = ::FindWindow(NULL,"Internet Explorer");
hWnd=::FindWindowEx(hWndWarning , NULL , "Button","&Yes" );
if(hWnd!=NULL && hWndWarning!=NULL)
{
::SetForegroundWindow(hWndWarning);
::SetFocus(hWnd);
::PostMessage ( hWnd , WM_LBUTTONDOWN , 0 , 0 );
::PostMessage ( hWnd , WM_LBUTTONUP , 0 , 0 );
Sleep(1000);
}

if(g_bStopDialogWatcherThread)
{
break;
}
}
return 1;
}

AfxBeginThread(WindowWatcher,THREAD_PRIORITY_NORMAL,0,0,0);//to start the thread