/* Threads in an app. */ /* Threads have to be defined as static/global elements. They function in there own thread so have to be static class members or global. */ /* You'll most likely want to pass in some values. Best way to do it is pass in a struct. */ typedef struct tagTHREADPARMS { volatile bool m_bTerminateThread;//Note this is volitile! char sDBName[MAX_PATH]; //Name for something? HWND hWnd;//HWND that you may want to fire messages back to. }MyThreadData; /*Define the thread prototype.*/ /*A class based prototype.*/ static UINT MyThreadFunc(LPVOID lpv); /*A global based prototype.*/ UINT MyThreadFunc(LPVOID lpv); /*Creating the thread.*/ MyThreadData * ptp = new MyThreadData; ptp->m_bTerminateThread = FALSE; strcpy( ptp->sDBName, "SomeName" ); hWnd = this //Some window? AfxBeginThread( MyThreadFunc, ptp ); /* Implementation for the thread. */ UINT CDATSCatDlg::ThreadCreateDBFromFolderSpec(LPVOID lpv) { ThreadData* ptp = (ThreadData*) lpv; HWND hWnd = ptp->hWnd; /*Do some work with the thread.*/ /*Delete the struct as we are finished in the thread.*/ delete ptp; /*Optionaly(good idea!)let the owning app know the thread is finished.*/ ::PostMessage (hWnd, USER_THREAD_FINISHED_MSG, (WPARAM)THREAD_FULL_UPDATE, 0); return 0; }