📄 test3.cpp
字号:
// test3.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "test3.h"
#include "winuser.h"
#include <tlhelp32.h>
#define DllExport _declspec(dllexport)
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma data_seg(".SHARDAT")
static HHOOK hkb = NULL;
#pragma data_seg()
HINSTANCE hins;
CFile m_pfile;
HWND hcaretWnd = NULL;
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CTest3App
BEGIN_MESSAGE_MAP(CTest3App, CWinApp)
//{{AFX_MSG_MAP(CTest3App)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL DllExport GetProtel()
{
/* HANDLE m_handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
PROCESSENTRY32* Info = new PROCESSENTRY32;
Info->dwSize = sizeof(PROCESSENTRY32);
if(::Process32First(m_handle,Info))
{
while(::Process32Next(m_handle,Info)!=FALSE)
{
CString ss;
ss=Info->szExeFile;
ss.MakeLower();
if(ss.Find("client99se") != -1)
{
DWORD dwResult = Info->th32ProcessID;
if(Info)
{
delete Info;
}
return dwResult;
}
}
::CloseHandle(m_handle);
if(Info)
{
delete Info;
}
}
return -1;
*/
DWORD pid;
HANDLE hProcess;
char szProcessName[256];
HWND hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, &pid);
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
typedef DWORD (CALLBACK * GetModuleBaseName)(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to module to find filename for
LPTSTR lpFilename, // pointer to buffer to receive module path
DWORD nSize // size of buffer, in characters
);
typedef BOOL (CALLBACK *EnumProcessModules)(
HANDLE hProcess, // handle to the process
HMODULE * lphModule, // array to receive the module handles
DWORD cb, // size of the array
LPDWORD lpcbNeeded // receives the number of bytes returned
);//定义回调函数的地址
HINSTANCE hPsDll = LoadLibrary("PSAPI.DLL");
GetModuleBaseName pGetModuleBaseName =
(GetModuleBaseName)GetProcAddress(hPsDll, "GetModuleBaseNameA");
EnumProcessModules pEnumProcessModules =
(EnumProcessModules)GetProcAddress(hPsDll, "EnumProcessModules");
if ( pEnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
if(pGetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName)/sizeof(TCHAR)))
{
_strlwr(szProcessName);
if(strstr(szProcessName, "client99se"))
{
return TRUE;
}
}
}
}
return FALSE;
}
BOOL DllExport b_Focus()
{
HWND hWnd;
GUITHREADINFO* Info = new GUITHREADINFO;
Info->cbSize = sizeof(GUITHREADINFO);
if(::GetGUIThreadInfo(NULL,Info) == 0)
return FALSE;
hWnd = Info->hwndCaret;
if(hWnd == hcaretWnd)
{
return TRUE;
}
else
{
hcaretWnd = hWnd;
return FALSE;
}
}
LRESULT DllExport CALLBACK LowLevelMouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
CString str;
DWORD pid;
if(nCode == HC_ACTION)
{
if(wParam == WM_MOUSEMOVE)
{
return CallNextHookEx(hkb, nCode, wParam, lParam );
}
{
HWND hWnd = GetForegroundWindow();
GetWindowThreadProcessId(hWnd, &pid);
if(wParam == WM_MOUSEWHEEL)
{
PMSLLHOOKSTRUCT pMSLLHook = (PMSLLHOOKSTRUCT)lParam;
TRACE("WHELL Action !\n");
str.Format("MouseData is 0x%x", (short)HIWORD(pMSLLHook->mouseData));
TRACE(str);
if(!GetProtel())
{
return CallNextHookEx(hkb, nCode, wParam, lParam );
}
if((short)HIWORD(pMSLLHook->mouseData) > 0)
{
PostMessage(hWnd, WM_KEYDOWN, 0x21, 0);
}
else
{
PostMessage(hWnd, WM_KEYDOWN, 0x22, 0);
}
}
else if(wParam == WM_MBUTTONDOWN)
{
if(!GetProtel())
{
return CallNextHookEx(hkb, nCode, wParam, lParam );
}
PostMessage(hWnd, WM_KEYDOWN, 106, 0);
PostMessage(hWnd, WM_KEYUP, 106, 0);
PostMessage(hWnd, WM_KEYDOWN, VK_END, 0);
/* if(GetAsyncKeyState(VK_RBUTTON))
{
PostMessage(hWnd, WM_KEYDOWN, 0x23, 0);
}
else
{
PostMessage(hWnd, WM_KEYDOWN, 0x24, 0);
}
*/ }
else if(wParam == WM_RBUTTONDOWN)
{
if(!GetProtel())
{
return CallNextHookEx(hkb, nCode, wParam, lParam );
}
if(GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
PostMessage(hWnd, WM_KEYDOWN, ' ', 0);
return TRUE;
}
}
else if(wParam == WM_RBUTTONUP)
{
if(!GetProtel())
{
return CallNextHookEx(hkb, nCode, wParam, lParam );
}
if(GetAsyncKeyState(VK_LBUTTON))
{
// PostMessage(hWnd, WM_KEYDOWN, ' ', 0);
return TRUE;
}
}
}
}
LRESULT RetVal = CallNextHookEx(hkb, nCode, wParam, lParam );
return RetVal;
}
BOOL DllExport installhook()
{
hkb = SetWindowsHookEx(14,(HOOKPROC)LowLevelMouseProc,hins,0);
return TRUE;
}
BOOL DllExport UnHook()
{
BOOL unhooked = UnhookWindowsHookEx(hkb);
return unhooked;
}
BOOL CTest3App::InitInstance ()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hins=AfxGetInstanceHandle();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTest3App construction
CTest3App::CTest3App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CTest3App object
CTest3App theApp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -