My app is so compute bound that it can run for on the order of a minute. During that time, it is drawing to the screen, but you cannot stop it. The message pumps have stopped, I presume. I have solved the painting problem but not the printing problem, so I'll give you the gist of painting. I start the worker thread in OnPaint and pass the thread parms the "this" pointer and HWND hwnd. The hwnd comes from GetSafeHwnd(). OnPaint is now done and returns.
I've learned not to use CDC In the worker (painter) thread, I do this:
HDC hdc = GetDC(ps->hwnd); DrawAll(hdc); ReleaseDC(ps->hwnd);
return;
OnPrint() is similar to OnPaint() but is a tad more complicated. The starter thread looks like this:
void CMyView::StartPrinterThread(CDC* pdc, CPrintInfo* pInfo)
{
PrintParam.pv = (CMyView*)this;
CMyDoc* pDoc = GetDocument();
PrintParam.pInfo = pInfo;
pDoc->m_bStopThread = FALSE; ResetEvent(pDoc->m_hevPrinter);
AfxBeginThread(PrinterThread,&PrintParam);
WaitForSingleObject(pDoc->m_hevPrinter, INFINITE);
}
static UINT PrinterThread(LPVOID pParam)
{
CPrintInfo* pInfo;
HDC hdc;
RECT rcl;
POINT Org;
PRINTPARMSTRUCT* ps = (PRINTPARMSTRUCT*)pParam;
CMyDoc* pDoc = ps->pv->GetDocument();
pInfo = ps->pInfo;
hdc = pInfo->m_pPD->m_pd.hDC;
SetMapMode(hdc, MM_LOENGLISH);
rcl = pInfo->m_rectDraw;
...
SetEvent(pDoc->m_hevPrinter); DrawAll(hdc); return 0;
}
My app actually runs as expected but for a small detail. The print preview page and the printed page are blank. I hope it is something small that I am missing.
Tom Stokes