Why can't my WndProc be in a class?

前端 未结 3 632
清酒与你
清酒与你 2021-02-05 18:29

This seems like it should be pretty straightforward. I have my class:

class Simple
{
public:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA         


        
3条回答
  •  鱼传尺愫
    2021-02-05 19:14

    // Header  
    class Foo   
    {  
    public:
      Foo();   
    
      ~Foo();  
    
      static LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
    
    private:
      LRESULT CALLBACK MyWinProc(HWND, UINT, WPARAM, LPARAM);
    
      static Foo *m_pInstance;
    }
    
    // Implementation
    
    #include "Foo.h"
    
    Foo * Foo::m_pInstance = NULL;
    
    Foo::Foo()
    {  
      m_pInstance = this;   
    }  
    
    Foo::~Foo()
    {
    }
    
    LRESULT CALLBACK Foo::WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)  
    {  
      return m_pInstance->MyWinProc(hWnd, message, wParam, lParam);  
    }  
    
    LRESULT CALLBACK Foo::MyWinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)  
    {  
      return DefWindowProc(hWnd, message, wParam, lParam);  
    }  
    

提交回复
热议问题