title: HANDLE in place of CWnd*? (MFC)
body: <p>I have a piece of code in an MFC program that looks like this:</p>
  
  <pre><code>    HANDLE newhandle = m_hWnd;    //A
  
      //draw the bitmap image on the window        
      BITMAP* bi = new BITMAP;
      CBitmap bmp;
      bmp.Attach(transferbitmap);
      CClientDC dc(newhandle);      //B
      //...
      //...
      //...
  </code></pre>
  
  <p>On line 'A', I create a HANDLE named newhandle, and set it to <strong>m_hWnd</strong>, <strong>which is of type CWnd*</strong>.  This line alone compiles (using Visual Studio 2010) fine and seems to work.  However, looking at line 'B', when I try to use newhandle in place of m_hWnd, I get the compilation error:</p>
  
  <blockquote>
    <p>error C2664: 'CClientDC::CClientDC(CWnd*)' : cannot convert parameter 1 from 'HANDLE' to 'CWnd*'</p>
  </blockquote>
  
  <p>When I use m_hWnd in place of newhandle, the program compiles and runs fine.</p>
  
  <p>My question(s) is(are), why does the compiler let me set newhandle to a CWnd*, but when I try to use it an error occurs?  Furthermore, is there a way to use a non-MFC window handle to replace m_hWnd, because I'm trying to remove all MFC specific code from the lower levels of my code?</p>