Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Change value to a thread Pin
Victor Nijegorodov29-May-19 5:28
Victor Nijegorodov29-May-19 5:28 
GeneralRe: Change value to a thread Pin
_Flaviu29-May-19 21:23
_Flaviu29-May-19 21:23 
GeneralRe: Change value to a thread Pin
Victor Nijegorodov29-May-19 23:01
Victor Nijegorodov29-May-19 23:01 
GeneralRe: Change value to a thread Pin
_Flaviu29-May-19 23:23
_Flaviu29-May-19 23:23 
GeneralRe: Change value to a thread Pin
Victor Nijegorodov30-May-19 0:46
Victor Nijegorodov30-May-19 0:46 
GeneralRe: Change value to a thread Pin
_Flaviu29-May-19 23:26
_Flaviu29-May-19 23:26 
GeneralRe: Change value to a thread Pin
leon de boer30-May-19 1:30
leon de boer30-May-19 1:30 
GeneralRe: Change value to a thread Pin
_Flaviu30-May-19 21:08
_Flaviu30-May-19 21:08 
Here is what I've done:
C++
// TestFileView.h : interface of the CTestFileView class

protected:
	CEvent m_event;
	CString m_sFolder;
	CWinThread* m_pWinThread;

C++
/*static*/UINT CTestFileView::FilesWatchDogThread(LPVOID lpParam)
{
	CTestFileView* pView = (CTestFileView*)lpParam;

	if (NULL == pView->GetSafeHwnd())
		return 1;

	HANDLE hChange = FindFirstChangeNotification(pView->GetFolder(), FALSE,	FILE_NOTIFY_CHANGE_FILE_NAME);

	if (INVALID_HANDLE_VALUE == hChange)
		return 1;

	HANDLE aHandles[2];
	aHandles[0] = hChange;
	aHandles[1] = pView->m_event.m_hObject;

	BOOL bContinue = TRUE;
	while (bContinue)
	{
		DWORD dwResult = WaitForMultipleObjects(2, aHandles, FALSE, INFINITE);
		switch (dwResult)
		{
		case WAIT_OBJECT_0:
			::PostMessage(pView->GetSafeHwnd(), WMU_NOTIFY_FOLDERCHANGED, 0, (LPARAM)0);
			FindNextChangeNotification(hChange);
			break;
		case WAIT_OBJECT_0 + 1:
			bContinue = FALSE;
			break;
		}
	}

	FindCloseChangeNotification(hChange);

	return 0;
}

and
C++
void CTestFileView::StopThread()
{
	m_event.SetEvent();
	WaitForSingleObject(&m_event, INFINITE);
}

and
C++
void CTestFileView::OnEditStartthread()
{
	// TODO: Add your command handler code here

	m_event.ResetEvent();
	m_sFolder.Format(_T("D:\\Tempx\\"));
	m_pWinThread = AfxBeginThread(&CTestFileView::FilesWatchDogThread, (LPVOID)this, THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED, 0, NULL);
}

there is remain one thing to do: to change the folder (m_sFolder) how can I complete this with CreateEvent/SetEvent ?
GeneralRe: Change value to a thread Pin
_Flaviu30-May-19 22:12
_Flaviu30-May-19 22:12 
GeneralRe: Change value to a thread Pin
Victor Nijegorodov30-May-19 22:39
Victor Nijegorodov30-May-19 22:39 
GeneralRe: Change value to a thread Pin
_Flaviu30-May-19 23:57
_Flaviu30-May-19 23:57 
GeneralRe: Change value to a thread Pin
Victor Nijegorodov31-May-19 0:01
Victor Nijegorodov31-May-19 0:01 
QuestionKnow when a files has been copied Pin
_Flaviu28-May-19 5:36
_Flaviu28-May-19 5:36 
AnswerRe: Know when a files has been copied Pin
Richard MacCutchan28-May-19 5:50
mveRichard MacCutchan28-May-19 5:50 
AnswerRe: Know when a files has been copied Pin
Victor Nijegorodov28-May-19 20:37
Victor Nijegorodov28-May-19 20:37 
AnswerRe: Know when a files has been copied Pin
Dave Kreskowiak31-May-19 2:49
mveDave Kreskowiak31-May-19 2:49 
QuestionI have 3rd party . OCX file. which loads in HTML scripts and do desired work Pin
Gaurav__Kapoor26-May-19 22:12
Gaurav__Kapoor26-May-19 22:12 
AnswerRe: I have 3rd party . OCX file. which loads in HTML scripts and do desired work Pin
Richard MacCutchan26-May-19 22:35
mveRichard MacCutchan26-May-19 22:35 
GeneralRe: I have 3rd party . OCX file. which loads in HTML scripts and do desired work Pin
Gaurav__Kapoor27-May-19 2:17
Gaurav__Kapoor27-May-19 2:17 
GeneralRe: I have 3rd party . OCX file. which loads in HTML scripts and do desired work Pin
Richard MacCutchan27-May-19 3:40
mveRichard MacCutchan27-May-19 3:40 
QuestionClever macro to handle consecutive addresses with built-in static_assert Pin
arnold_w24-May-19 22:54
arnold_w24-May-19 22:54 
AnswerRe: Clever macro to handle consecutive addresses with built-in static_assert Pin
Stefan_Lang26-May-19 22:15
Stefan_Lang26-May-19 22:15 
Question"A rose by any other name would smell as sweet" - so what is the BEST name for "open_dev" function return? Pin
Vaclav_19-May-19 16:54
Vaclav_19-May-19 16:54 
AnswerRe: "A rose by any other name would smell as sweet" - so what is the BEST name for "open_dev" function return? Pin
Richard MacCutchan19-May-19 21:28
mveRichard MacCutchan19-May-19 21:28 
AnswerRe: "A rose by any other name would smell as sweet" - so what is the BEST name for "open_dev" function return? Pin
leon de boer20-May-19 3:01
leon de boer20-May-19 3:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.