March 12th, 2014, 08:02 PM
MFC CDC HDC issue
I am a bit of a noob so go easy here
I am creating an MFC app with a main window class CDataDlg.
The .h file has public method declaration:
static void CDataDlg::toScreen();
This is a simple routine to dump some buffered context to screen via BitBlt:
CDC* pDC = GetDC();
BitBlt(pDC->GetSafeHdc(),0,0,width,height, hdcMem, 0, 0, SRCCOPY);
The idea is to draw a picture directly on main window background.
This worked great, so long as the method was not static. Of course, once I made it static (as explained above), I lost the ability to call GetDC().
I tried the following:
hWnd = AfxGetApp()->m_pMainWnd->m_hWnd;
CWnd* mycw = FromHandlePermanent(hWnd);
CDC* pDC = mycw->GetDC();
But that fails miserably because mycw ends up NULL. In general, this chain of seeking a drawing context is very fishy to me. Any recommendations?
March 13th, 2014, 02:07 AM
Re: MFC CDC HDC issue
Never mind. toScreen() was being spun off as a new worker thread. It somehow worked with drawing on CDC until I made it static but it should not have worked at all. Moved it into main UI thread and it all works.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!