well if u don't know much threading then you are same as i was a month back. For threading search codeproject articles ( i don't have collection of it to tell you). any way i will paste my code here if you can make sense out of it.
//defined in CMainFrame class
DlgProgress *dlglocprog;
//this type of threading is used forcalling a member function in a seperate thread
//This thread function calls a member function FunctionClients of class MainFrm
DWORD WINAPI PseudoThreadFunction( IN LPVOID vThreadParm )
{
CMainFrame* pThreadParam = ( CMainFrame* ) vThreadParm;
pThreadParam->FunctionClients();
return 1;
}
//This Funnction will call PseudoThreadFunction() as a new thread.
bool CMainFrame::ExecuteLocateThread(void)
{
HANDLE hThread = NULL;
DWORD dwThreadID = 0;
int nTimeout = 5000;
try
{
hThread = CreateThread( NULL, // Pointer to thread security attributes
0, // Initial thread stack size, in bytes
PseudoThreadFunction,
this, // The argument for the new thread is a pointer to your MyThread
0, // Creation flags
&dwThreadID ); // Pointer to returned thread identifier
}
catch( CException* /* pException */ )
{
return false;
}
bool bFinished = false;
do
{
DWORD dwWaitResult = MsgWaitForMultipleObjects(
1,
& hThread,
FALSE,
nTimeout,
QS_ALLEVENTS | QS_SENDMESSAGE);
switch ( dwWaitResult )
{
case WAIT_OBJECT_0 :
case WAIT_ABANDONED_0 :
{
bFinished = true;
break;
}
case WAIT_OBJECT_0 + 1 : // message(s) in queue
{
MSG msg;
while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) == TRUE )
if ( !AfxGetApp( )->PumpMessage( ) )
{
::PostQuitMessage( 0 );
}
break;
}
default :
{
bFinished = true;
}
}
} while ( ! bFinished );
return true;
}
void CMainFrame::FunctionClients(void)
{
for(unsigned short addr=1;addr<256;addr++)
{
vi_Progress=addr;
dlglocprog->IncrementProgress();//Increments the progress value and updates the message
Sleep(10);
}
dlglocprog->EndDialog(0);//ShowWindow(SW_HIDE);//DestroyWindow();//
b_LocateProgress=false;
}
void CMainFrame::OnClientoptionsLocateallactiveclients()
{
// TODO: Add your command handler code here
if(!b_LocateProgress)
{
b_LocateProgress=true;
dlglocprog = new CLocateProgress();
dlglocprog->Create(IDD_LOCATING_CLIENTS);
dlglocprog->ShowWindow(SW_SHOW);
dlglocprog->Ce