title: Creating a WM_USER handler with MFC
body: <p>Though I've had plenty of software experience I've not done a great deal of Windows programming. I'm trying to post a WM_USER message from a thread so that it gets picked up in the main UI thread but I'm having some trouble. This is in C++ using VS2010 and MFC.</p>
  
  <p>I've created a message map thus,</p>
  
  <pre><code>#define WM_MYMSG (WM_USER + 77)
  BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
      ON_MESSAGE(WM_MYMSG, DoSomething)
  END_MESSAGE_MAP()
  </code></pre>
  
  <p>Declared the handler function as follows,</p>
  
  <pre><code>afx_msg LRESULT DoSomething(WPARAM wParam, LPARAM lParam);
  </code></pre>
  
  <p>And written the function body as,</p>
  
  <pre><code>LRESULT CMyApp::DoSomething( WPARAM wParam, LPARAM lParam ) 
  {
      UNREFERENCED_PARAMETER(wParam);
      UNREFERENCED_PARAMETER(lParam);
  
      CallSomeFunction();
      return 0L;
  }
  </code></pre>
  
  <p>As far as I can see this is all in line with what MSDN says as stated here.</p>
  
  <p><a href="http://msdn.microsoft.com/en-gb/library/k35k2bfs(v=vs.100).aspx" rel="nofollow">http://msdn.microsoft.com/en-gb/library/k35k2bfs(v=vs.100).aspx</a></p>
  
  <p>However I'm getting an</p>
  
  <pre><code>error C2440: 'static_cast' : cannot convert from 'LRESULT (__cdecl CMyApp::*)(WPARAM,LPARAM)' to 'LRESULT (__cdecl CWnd::* )(WPARAM,LPARAM)'
  </code></pre>
  
  <p>relating to the line</p>
  
  <pre><code>ON_MESSAGE(WM_AVATAR_SCALE_MSG, DoSomething)
  </code></pre>
  
  <p>Can anyone let me know what the problem is?</p>
  
  <p>Thanks for reading.</p>
  
  <p>Paul</p>