请教回掉函数问题
<p>WNDPROC procOld;<br/>LRESULT CALLBACK NewAcadWndProc(<br/> HWND hwnd, // handle to window<br/> UINT uMsg, // message identifier<br/> WPARAM wParam, // first message parameter<br/> LPARAM lParam // second message parameter<br/>);<br/>class CmyToolbar2App : public AcRxArxApp {</p><p>public:<br/>LRESULT CALLBACK NewAcadWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) <br/>{ <br/>switch(iMsg) <br/>{ <br/>case WM_MOUSEMOVE: <br/>//lParam = MAKELPARAM(200,200);//禁止移动光标 <br/>break; <br/>case WM_LBUTTONDOWN: <br/>AfxMessageBox("WM_LBUTTONDOWN");//响应鼠标左键 <br/>break; <br/>case WM_MOUSEWHEEL: <br/>AfxMessageBox("WM_MOUSEWHEEL");//响应鼠标滚动 <br/>break; <br/>default: <br/>break; <br/>} <br/>return ::CallWindowProc(procOld, hwnd, iMsg, wParam, lParam); <br/>} <br/> CmyToolbar2App () : AcRxArxApp () {}</p><p> virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<br/> AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;</p><p> procOld = (WNDPROC)::SetWindowLong(acedGetAcadDwgView()->GetSafeHwnd(),GWL_WNDPROC, (LONG)NewAcadWndProc); <br/> CAcModuleResourceOverride resOverride;</p><p> return (retCode) ;<br/> }<br/>} ;<br/> </p><p>这一行有错误:<br/> procOld = (WNDPROC)::SetWindowLong(acedGetAcadDwgView()->GetSafeHwnd(),GWL_WNDPROC, (LONG)NewAcadWndProc); <br/> CAcModuleResourceOverride resOverride; <br/>包错信息:</p><p>e:\AutoCad二次开发\我的演示\myToolbar2\acrxEntryPoint.cpp(96) : error C2440: “类型转换” : 无法从“LRESULT (__stdcall CmyToolbar2App::* )(HWND,UINT,WPARAM,LPARAM)”转换为“LONG”<br/> 转换是有效的标准转换,可以隐式执行或通过使用 static_cast、C 样式转换或函数样式转换执行 </p><p><br/>相似的回掉函数在MFC工程中却没有报错 </p> <p>问题解决,代码如下:</p><p>WNDPROC procOld;<br/>LRESULT CALLBACK NewAcadWndProc(<br/> HWND hwnd, // handle to window<br/> UINT uMsg, // message identifier<br/> WPARAM wParam, // first message parameter<br/> LPARAM lParam // second message parameter<br/>);</p><p>LRESULT CALLBACK NewAcadWndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) <br/>{ <br/>switch(iMsg) <br/>{ <br/>case WM_MOUSEMOVE: <br/>//lParam = MAKELPARAM(200,200);//禁止移动光标 <br/>break; <br/>case WM_LBUTTONDOWN: <br/>AfxMessageBox("WM_LBUTTONDOWN");//响应鼠标左键 <br/>break; <br/>case WM_MOUSEWHEEL: <br/>AfxMessageBox("WM_MOUSEWHEEL");//响应鼠标滚动 <br/>break; <br/>default: <br/>break; <br/>} <br/>return ::CallWindowProc(procOld, hwnd, iMsg, wParam, lParam); <br/>} <br/><br/>class CmyToolbar2App : public AcRxArxApp {</p><p>public:<br/> CmyToolbar2App () : AcRxArxApp () {}</p><p> virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {<br/> AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;</p><p> procOld = (WNDPROC)::SetWindowLong(acedGetAcadDwgView()->GetSafeHwnd(),GWL_WNDPROC, (LONG)NewAcadWndProc); <br/> CAcModuleResourceOverride resOverride;</p><p> return (retCode) ;<br/> }<br/>} ;</p>
页:
[1]