初始化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就崩溃了。
一头雾水阿,高手们指教一下吧!
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就崩溃了。
一头雾水阿,高手们指教一下吧!
解决方案 »
- OnTimer相同的函数调用两次为什么只执行了最后一次?
- VC2005 智能设备 使用ActiveX
- 用vc在已知的数据源中创建Oracle表(比较有难度哦,高手来看看哈)
- 送分——————怎么样把程序需要的数据放到程序可执行文件中??????
- 基于Visual C++.NET的GDI+开发教程
- ------------看过好些资料了,但还是不知道该如何去创建这样的对话框------------
- 关于用VC做橡皮擦
- (求助)一个关于在ActiveX空间内,创建线程的操作
- 求教高手:请问ASP中如何调用、设置winsock而实现不间断的连接,使页面无需刷新?????
- 用汇编语言写WINDOWS程序,是不是非常难??
- 如何隐藏对话框
- 多线程中用Mutex互斥访问资源的问题
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
看看这个可能对你有帮助吧