-
-
[求助]求助关于鼠标钩子的问题(附源码)
-
发表于:
2009-8-31 17:16
4352
-
源码如下:
#include "stdafx.h"
#include "windows.h"
#include "fstream.h"
HHOOK g_hook = 0;
HINSTANCE g_Hinstance;
BOOL Start = TRUE;
bool WINAPI StopHook();
extern "C" __declspec(dllexport) LRESULT __stdcall /*CALLBACK*/ MouseHookProc(int nCode,WPARAM wParam, LPARAM lParam)
{
if(nCode >= 0)
{
if(Start)
{
Start = FALSE;
ofstream of("c:\\1.txt");
of<<"abcd"<<endl;
of.close();
}
}
return CallNextHookEx(g_hook,nCode,wParam,lParam);
}
BOOL WINAPI StartHook()
{
if(g_hook != NULL)
{
return FALSE;
}
g_hook = SetWindowsHookEx(WH_MOUSE,MouseHookProc,g_Hinstance,NULL);
if(g_hook == NULL)
{
ExitProcess(0);
}
return TRUE;
}
BOOL WINAPI StopHook()
{
if(UnhookWindowsHookEx(g_hook) == 0)
{
return FALSE;
}
g_hook = NULL;
return TRUE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
g_Hinstance = hInstance;
MSG msg;
BOOL bRet;
StartHook();
while((bRet = GetMessage(&msg,NULL,0,0)) != 0)
{
if(bRet != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
不能解决的问题:
该程序在cmd.exe下,输入程序名字回车运行可以在C盘下生成1.txt测试文件。
而双击运行或者其他的方式运行,不能在c盘下生成测试的1.txt文件。
恳请各位大侠指点指点,程序应该怎么改。。。
谢谢了
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课