Skip to content

Instantly share code, notes, and snippets.

@nibasya
Created March 25, 2020 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibasya/f3fc0597861335fcec09addadd6ca5f6 to your computer and use it in GitHub Desktop.
Save nibasya/f3fc0597861335fcec09addadd6ca5f6 to your computer and use it in GitHub Desktop.
An example of user interface thread implementation
#include "pch.h"
#include "ShowOfflineFiles.h"
#include "ShowOfflineFilesDoc.h"
#include "CFindStatusDlg.h"
#include "CFindStatusDlgThread.h"
// CFindStatusDlgThread
IMPLEMENT_DYNCREATE(CFindStatusDlgThread, CWinThread)
CFindStatusDlgThread::CFindStatusDlgThread():
m_pDoc(NULL), m_hParent(NULL)
{
}
CFindStatusDlgThread::~CFindStatusDlgThread()
{
}
BOOL CFindStatusDlgThread::InitInstance()
{
ASSERT(m_pDoc != NULL);
CFindStatusDlg* &pDlg = m_pDoc->m_pFindStatusDlg;
pDlg->m_hParent = m_hParent;
m_pMainWnd = pDlg;
pDlg->DoModal();
return TRUE;
}
int CFindStatusDlgThread::ExitInstance()
{
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CFindStatusDlgThread, CWinThread)
END_MESSAGE_MAP()
void CShowOfflineFilesDoc::OnFind()
{
/* Snip */
CFindStatusDlgThread* pThread = DYNAMIC_DOWNCAST(CFindStatusDlgThread, AfxBeginThread(RUNTIME_CLASS(CFindStatusDlgThread), 0, 0, CREATE_SUSPENDED));
ASSERT(pThread);
pThread->m_pDoc = this;
pThread->m_hParent = AfxGetMainWnd()->m_hWnd;
pThread->ResumeThread();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment