假设我定义了下面这个类
class a
{
public:
    a()
     {
         
         wndclass.lpfnWndProc =WndProc;/****如何注册这个WndProc回调,并且
                 数据类型一致,可以正常工作?????
         ****/
      
     }
    LRESULT CALLBAKC WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM  lParam)  
   {
        ...
        return 0;
   }       
private:
    WNDCLASS wndclass;
};问题都在上面了,请大家帮忙多多UP,分不够在+.

解决方案 »

  1.   

    1声明回调函数类型 typedef int (WINAPI *PFCALLBACK)(int Param1,int Param2) ;
    2声明函数原形int WINAPI CBFunc(int Param1,int Param2);
    3.调用回调函数的函数我把它放到了DLL里
    4 在你的程序里int WINAPI CBFunc(int Param1,int Param2){写实现部分  } 
      

  2.   

    我是要想在类中生成个窗体,然后窗体生成后,在类的内部接收Windows消息.请问应该如何做?不是简单的实现个回调函数,而是在注册窗体类RegisterClass(.....)的时候,将WndClass结构中的lpfnWndProc指定为自定义类中的一个内部函数。使用的只是标准c++和win32 APITo vcforever和carbon107你们的方法具体怎么实现啊?
      

  3.   

    1、将WndProc 改为static类型
    2、定义class a 的一个全局指针 a *pwnd;并在构造函数中对其赋值this;
    3、在WndProc中通过全局指针调用真正的处理函数。
    class a;
    a *pwnd=NULL;
    class a
    {
    public:
        a()
         {
             
             wndclass.lpfnWndProc =WndProc;/****如何注册这个WndProc回调,并且
                     数据类型一致,可以正常工作?????
             ****/
             pwnd=this; // 给全局指针赋值。
          
         }
        LRESULT static CALLBAKC WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM  lParam)  
       {
            ...
            pwnd->...//此处真正调用处理函数。它可以为任何一个内部函数。
            return 0;
       }       
    private:
        WNDCLASS wndclass;
    };
    祝你成功!
      

  4.   

    to: broadoceans(broadoceans) 编译的时候出错,这个方法好象不行啊?error C2440: '=' : cannot convert from 'long (__cdecl *)(struct HWND__ *,unsigned int,unsigned int,long)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned in
    t,long)'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    Error executing cl.exe.
      

  5.   

    请问是哪一行出错的,
    应该为:static void WINAPI WndProc(....)
    因为WINAPI即为__stdcall
      

  6.   

    解决了,谢谢大家,现在用win32 SDK自己写类的太少了,很高兴在这里认识大家,以后多多帮助!!!!分是少了点,我加到100吧.