对某个特定文件进程挂上线程钩子,想要阻止其保存操作假如我的文件名是演示.dochwnd = FindWindowByPart("演示");//挂钩子时先通过这个方法得到当前窗口句柄
g_hWriteHook = ::SetWindowsHookEx( WH_CALLWNDPROC , CallWndProc ,(HINSTANCE)g_hInst, GetWindowThreadProcessId(hwnd,NULL));//然后根据窗口句柄返回的线程号挂上线程钩子
如果这样简单的拦截保存操作,是可以达到目的,对于TXT上没有bug,但是如果是word就存在问题了,虽然是线程钩子,如果这时再开一个其他的word文档比如A.doc,那么这个A.doc同样也不能保存,即使我对他并没有挂钩子。为了区分不同的文件,拦截他们的writefile,我又HOOK了Createfile,先得到演示.doc的文件句柄,然后在writefile api中判断一次,如果是对演示.doc句柄的writefile则拦截,否则放行
BOOL _stdcall Replace_WriteFile(         //替换系统的Writefile
HANDLE hFile,                    // handle to file to write to
LPCVOID lpBuffer,                // pointer to data to write to file
DWORD nNumberOfBytesToWrite,     // number of bytes to write
LPDWORD lpNumberOfBytesWritten,  // pointer to number of bytes written
LPOVERLAPPED lpOverlapped        // pointer to structure for overlapped I/O
)
{
BOOL res = NULL; //操作成功完成返回非零值 __try 
{
if(hFile == g_hFile) //g_hFile是程序中得到的演示.doc的句柄
{
::MessageBox(NULL,"截获保存","成功",NULL);

}
else
{
        res=Real_WriteFile( hFile,
                                            lpBuffer,
                                            nNumberOfBytesToWrite,
                                            lpNumberOfBytesWritten,
                                            lpOverlapped ); }

__finally 
{};
return res;
}
但是这样虽然可以保证了可以区分开不同的文件了,但是造成的问题是如果对这个文件的另存为操作就阻止不了了,有没有兄弟们帮帮忙,应该怎么解决?