MFC CDC HDC issue
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: MFC CDC HDC issue

  1. #1
    Join Date
    Mar 2014
    Posts
    2

    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?

  2. #2
    Join Date
    Mar 2014
    Posts
    2

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center