我准备写一套简单的换肤控件,我准备让换肤控件都从MFC相应的类派生。比如CSkinBtn从CButton派生,等等。然后,我用勾子勾住主线程的消息,在钩子函数中,本来想通过子类化来实现换肤,。。HookProc()

   
   CString strName = GetClassName(hWnd);
   。。
   if(strName。CompareNoCase(_T("Button"))//假设button是CButton的窗口类名
   {
       CSkinBtn* pBtn = new CSKinBtn;
        pBtn->SubClassWindow(hWnd);  
    }    
    。。
}可是发现这样子类化做法行不通,pBtn->SubClassWindow函数会异常,我分析了一下,有以下原因:
1。所有的MFC的控件的窗口过程都是一样的,是AfxWndProc,CSkinBtn从CButton派生,窗口过程
也是AfxWndProc
2。一个窗口句柄只能Attach在一个CWnd派生的类上请问有什么方法能解决 这个问题? 我看到有一些资料上说有办法解决的,不知是怎么做的??

解决方案 »

  1.   

    http://search.csdn.net/Expert/topic/1867/1867827.xml?temp=.3940393
      

  2.   

    不一样的, 我要 子类化的空件本身是通过mfc类创建的,如CButton。Create()
    之所一不能子类化的原因 如我上面所说的。下面这段话可参考:The first time I saw the CWnd class documentation I found it great. A very good wrapper for W32 API into the C++ context. But as time goes on, certain choice MFC developers did in the past becomes no more suitable for what the enhancement of the language had been. In particular, there is no possibility to subclass a Windows “window” more than once by a CWnd object. The problem has been solved in a variety of ways (I remember Paul Di Lascia, from Microsoft)
      

  3.   

    我有现在的例子;
    Hook WH_CALLWNDPROC
      

  4.   

    能发我一份吗???max_welcom@sohu。com,谢谢