Q
qfgj
Unregistered / Unconfirmed
GUEST, unregistred user!
// ChinarenMU.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include <afxdllx.h>
#include "ChinarenMU.h"
//#include <windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma data_seg("sharedata")
HHOOK glhHook=NULL;
HINSTANCE glhInstance=NULL;
UINT KeyPressed;
UINT AutoTalkFlag;
HWND hwndmu;
HHOOK hHook;
HINSTANCE pHinstance;
bool bs=false;
WNDPROC oldproc;
#pragma data_seg()
void __declspec(dllexport) WINAPI InstallHook(BOOL,DWORD);
BOOL WINAPI UnInstallHook();
LRESULT CALLBACK HookProc(int ,WPARAM ,LPARAM);
LRESULT CALLBACK MyMsgProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam);
bool __stdcall winmu(void);
BOOL WINAPI UnInstallHook();
static AFX_EXTENSION_MODULE ChinarenMUDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CHINARENMU.DLL Initializing!/n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(ChinarenMUDLL, hInstance))
return 0;
//new CDynLinkLibrary(ChinarenMUDLL);
pHinstance = hInstance;
}
else
if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("CHINARENMU.DLL Terminating!/n");
// Terminate the library before destructors are called
//AfxTermExtensionModule(ChinarenMUDLL);
}
return 1;
// ok
}
void __declspec(dllexport) WINAPI InstallHook(BOOL IsHook,DWORD dwThreadId)
{
if(IsHook)
{
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)HookProc,pHinstance,dwThreadId);
}
else
{
UnInstallHook();
}
}
LRESULT CALLBACK HookProc(int ncode,WPARAM wparam,LPARAM lparam)
{
if(ncode<0)
return CallNextHookEx(hHook,ncode,wparam,lparam);//用一个bool变量让我们的winmu()只调用一次
if (!bs) winmu();
bs=true;
return CallNextHookEx(hHook,ncode,wparam,lparam);
}
bool __stdcall winmu(void)
{
long style;
long exstyle;
DEVMODE devmode;
hwndmu=GetForegroundWindow();
if(EnumDisplaySettings(0, 0, &devmode))
{
devmode.dmPelsWidth=1024;
devmode.dmPelsHeight=768;
devmode.dmBitsPerPel=32;
devmode.dmDisplayFrequency=75;
ChangeDisplaySettings(&devmode,0);
}
//修改窗体的style属性
style= GetWindowLong(hwndmu,GWL_STYLE);
style=style | WS_CAPTION
SetWindowLong(hwndmu,GWL_STYLE,style);//修改窗体的exstyle属性
exstyle=GetWindowLong(hwndmu,GWL_EXSTYLE);
exstyle=exstyle | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
SetWindowLong(hwndmu,GWL_EXSTYLE,exstyle);//设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的//当然最好是先用AdjustWindowRect函数调整一下大小
SetWindowPos(hwndmu,HWND_NOTOPMOST,0,0,1024,768,SWP_SHOWWINDOW);
ShowWindow(hwndmu,SW_SHOWNORMAL);//修改窗体的回调函数地址到我们自己定义的回调函数
oldproc=(WNDPROC)GetWindowLong(hwndmu,GWL_WNDPROC);
if(SetWindowLong(hwndmu,GWL_WNDPROC,(long)MyMsgProc)==0)
return false;
return true;
}
LRESULT CALLBACK MyMsgProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)
{
//消息过滤
switch (umsg)
{
case WM_ACTIVATEAPP:
case WM_ACTIVATE:
case WM_KILLFOCUS:
case WM_SETFOCUS:
case WM_CLOSE:
return 0;//这里是个关键,把这个计时器kill
case WM_TIMER:
if(wparam==0x3e9)
KillTimer(hwnd,wparam);
break;
}
return CallWindowProc(oldproc,hwnd,umsg,wparam,lparam);
}
BOOL WINAPI UnInstallHook()
{
UnhookWindowsHookEx(hHook);
return TRUE;
}
//
#include "stdafx.h"
#include <afxdllx.h>
#include "ChinarenMU.h"
//#include <windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#pragma data_seg("sharedata")
HHOOK glhHook=NULL;
HINSTANCE glhInstance=NULL;
UINT KeyPressed;
UINT AutoTalkFlag;
HWND hwndmu;
HHOOK hHook;
HINSTANCE pHinstance;
bool bs=false;
WNDPROC oldproc;
#pragma data_seg()
void __declspec(dllexport) WINAPI InstallHook(BOOL,DWORD);
BOOL WINAPI UnInstallHook();
LRESULT CALLBACK HookProc(int ,WPARAM ,LPARAM);
LRESULT CALLBACK MyMsgProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam);
bool __stdcall winmu(void);
BOOL WINAPI UnInstallHook();
static AFX_EXTENSION_MODULE ChinarenMUDLL = { NULL, NULL };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("CHINARENMU.DLL Initializing!/n");
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(ChinarenMUDLL, hInstance))
return 0;
//new CDynLinkLibrary(ChinarenMUDLL);
pHinstance = hInstance;
}
else
if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("CHINARENMU.DLL Terminating!/n");
// Terminate the library before destructors are called
//AfxTermExtensionModule(ChinarenMUDLL);
}
return 1;
// ok
}
void __declspec(dllexport) WINAPI InstallHook(BOOL IsHook,DWORD dwThreadId)
{
if(IsHook)
{
hHook=SetWindowsHookEx(WH_GETMESSAGE,(HOOKPROC)HookProc,pHinstance,dwThreadId);
}
else
{
UnInstallHook();
}
}
LRESULT CALLBACK HookProc(int ncode,WPARAM wparam,LPARAM lparam)
{
if(ncode<0)
return CallNextHookEx(hHook,ncode,wparam,lparam);//用一个bool变量让我们的winmu()只调用一次
if (!bs) winmu();
bs=true;
return CallNextHookEx(hHook,ncode,wparam,lparam);
}
bool __stdcall winmu(void)
{
long style;
long exstyle;
DEVMODE devmode;
hwndmu=GetForegroundWindow();
if(EnumDisplaySettings(0, 0, &devmode))
{
devmode.dmPelsWidth=1024;
devmode.dmPelsHeight=768;
devmode.dmBitsPerPel=32;
devmode.dmDisplayFrequency=75;
ChangeDisplaySettings(&devmode,0);
}
//修改窗体的style属性
style= GetWindowLong(hwndmu,GWL_STYLE);
style=style | WS_CAPTION
SetWindowLong(hwndmu,GWL_STYLE,style);//修改窗体的exstyle属性
exstyle=GetWindowLong(hwndmu,GWL_EXSTYLE);
exstyle=exstyle | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
SetWindowLong(hwndmu,GWL_EXSTYLE,exstyle);//设置窗体的位置,取消其最前端显示,为图简单807,632是我自己随便设的//当然最好是先用AdjustWindowRect函数调整一下大小
SetWindowPos(hwndmu,HWND_NOTOPMOST,0,0,1024,768,SWP_SHOWWINDOW);
ShowWindow(hwndmu,SW_SHOWNORMAL);//修改窗体的回调函数地址到我们自己定义的回调函数
oldproc=(WNDPROC)GetWindowLong(hwndmu,GWL_WNDPROC);
if(SetWindowLong(hwndmu,GWL_WNDPROC,(long)MyMsgProc)==0)
return false;
return true;
}
LRESULT CALLBACK MyMsgProc(HWND hwnd,UINT umsg,WPARAM wparam,LPARAM lparam)
{
//消息过滤
switch (umsg)
{
case WM_ACTIVATEAPP:
case WM_ACTIVATE:
case WM_KILLFOCUS:
case WM_SETFOCUS:
case WM_CLOSE:
return 0;//这里是个关键,把这个计时器kill
case WM_TIMER:
if(wparam==0x3e9)
KillTimer(hwnd,wparam);
break;
}
return CallWindowProc(oldproc,hwnd,umsg,wparam,lparam);
}
BOOL WINAPI UnInstallHook()
{
UnhookWindowsHookEx(hHook);
return TRUE;
}