初始化MyClass中:
SetWindowLong(m_parentWnd->GetSafeHwnd(),GWL_WNDPROC,(LONG)ParentWndProc);
SetWindowLong(m_parentWnd->GetSafeHwnd(),GWL_USERDATA,(LONG)this);
想要在MyClass中处理父窗口的WM_SIZE消息,所以改变了父窗口的消息处理函数,换成了MyClass中定义的全局函数ParentWndProc,处理完WM_SIZE我还要给父窗口把消息发回去,所以又把自己和父窗口句柄关联起来,为了能在ParentWndProc中用的自己。如下:LRESULT CALLBACK ParentWndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam, 
LPARAM lParam)
{
MyClass* hChildWnd=NULL;
WNDPROC oldProc=NULL;
oldProc=(WNDPROC)GetWindowLong(hwnd,GWL_WNDPROC);
switch (uMsg) 

case WM_SIZE:
hChildWnd=(MyClass*)GetWindowLong(hwnd,GWL_USERDATA);
hChildWnd->OnChangeWindowSize();
break;
}
return CallWindowProc(oldProc,hwnd,uMsg,wParam,lParam);
}可是编译可以通过,程序执行到CallWindowProc就崩溃了。
一头雾水阿,高手们指教一下吧!

解决方案 »

  1.   

    Public Function SubWndProc( _
             ByVal hWnd As Long, _
             ByVal Msg As Long, _
             ByVal wParam As Long, _
             ByVal lParam As Long) As Long         On Error Resume Next         'Get pointer to the control's VTable from the
             'window's UserData section. The VTable is an internal
             'structure that contains pointers to the methods and
             'properties of the control.
             ptrObject = GetWindowLong(hWnd, GWL_USERDATA)         'Copy the memory that points to the VTable of our original
             'control to the shadow copy of the control you use to
             'call the original control's WindowProc Function.
             'This way, when you call the method of the shadow control,
             'you are actually calling the original controls' method.
             CopyMemory ctlShadowControl, ptrObject, 4         'Call the WindowProc function in the instance of the UserControl.
             SubWndProc = ctlShadowControl.WindowProc(hWnd, Msg, _
                wParam, lParam)         'Destroy the Shadow Control Copy
             CopyMemory ctlShadowControl, 0&, 4
             Set ctlShadowControl = Nothing
          End Function
    看看这个可能对你有帮助吧
      

  2.   

    GetWindowLong用错地方了http://www.vckbase.com/document/viewdoc/?id=1009
      

  3.   

    CallWindowProc 的第一个参数是一个枚举值,应该是SetWindowLong得来的 成员
      

  4.   

    现在好了,我在子窗口的析构函数里把父窗口的原处理函数set回去就OK了。结了~