在MFC工程中,OnBeforeNavigate2是被谁隐式调用的??对于这类隐式调用函数应该怎样查看是谁调用的它?
2个回答
展开全部
对于MFC的类,源码在C:\Program Files\Microsoft Visual Studio\VC98\MFC\路径下,你要查看的OnBeforNavigate2是CHtmlView的一个虚函数,它的定义在AFXHTML.H,和VIEWHTML.CPP中,你在上面的路径下搜索这两个文件就可以了。
void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
VARIANT* Flags, VARIANT* TargetFrameName,
VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
ASSERT(V_VT(URL) == VT_BSTR);
ASSERT(V_VT(TargetFrameName) == VT_BSTR);
ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
ASSERT(V_VT(Headers) == VT_BSTR);
ASSERT(Cancel != NULL);
USES_CONVERSION;
VARIANT* vtPostedData = V_VARIANTREF(PostData);
CByteArray array;
if (V_VT(vtPostedData) & VT_ARRAY)
{
// must be a vector of bytes
ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
vtPostedData->vt |= VT_UI1;
COleSafeArray safe(vtPostedData);
DWORD dwSize = safe.GetOneDimSize();
LPVOID pVoid;
safe.AccessData(&pVoid);
array.SetSize(dwSize);
LPBYTE lpByte = array.GetData();
memcpy(lpByte, pVoid, dwSize);
safe.UnaccessData();
}
// make real parameters out of the notification
CString strTargetFrameName(V_BSTR(TargetFrameName));
CString strURL = V_BSTR(URL);
CString strHeaders = V_BSTR(Headers);
DWORD nFlags = V_I4(Flags);
// notify the user's class
OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
array, strHeaders, Cancel);
}
查看源码,得知是CHtmlView的BeforeNavigate2调用了OnBeforeNavigate2,在查看BeforeNavigate2的引用,
ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
得知该函数为一个事件响应。
有了源码,就没有秘密,更深的可以自己去挖掘了
void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
VARIANT* Flags, VARIANT* TargetFrameName,
VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
ASSERT(V_VT(URL) == VT_BSTR);
ASSERT(V_VT(TargetFrameName) == VT_BSTR);
ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
ASSERT(V_VT(Headers) == VT_BSTR);
ASSERT(Cancel != NULL);
USES_CONVERSION;
VARIANT* vtPostedData = V_VARIANTREF(PostData);
CByteArray array;
if (V_VT(vtPostedData) & VT_ARRAY)
{
// must be a vector of bytes
ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
vtPostedData->vt |= VT_UI1;
COleSafeArray safe(vtPostedData);
DWORD dwSize = safe.GetOneDimSize();
LPVOID pVoid;
safe.AccessData(&pVoid);
array.SetSize(dwSize);
LPBYTE lpByte = array.GetData();
memcpy(lpByte, pVoid, dwSize);
safe.UnaccessData();
}
// make real parameters out of the notification
CString strTargetFrameName(V_BSTR(TargetFrameName));
CString strURL = V_BSTR(URL);
CString strHeaders = V_BSTR(Headers);
DWORD nFlags = V_I4(Flags);
// notify the user's class
OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
array, strHeaders, Cancel);
}
查看源码,得知是CHtmlView的BeforeNavigate2调用了OnBeforeNavigate2,在查看BeforeNavigate2的引用,
ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
得知该函数为一个事件响应。
有了源码,就没有秘密,更深的可以自己去挖掘了
追问
谢谢。请问如何查看BeforeNavigate2的引用
追答
如果在vc下,右键,点击find reference即可,也可以查找ctrl+f。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询