?? kbdll.cpp
字號:
// Kbdll.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include <afxdllx.h>
#include "Kbdll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static AFX_EXTENSION_MODULE KbdllDLL = { NULL, NULL };
#define DLLEXPORT _declspec (dllexport)
/*extern "C" DLLEXPORT LRESULT WINAPI KeyboardHookProc(
int nCode,WPARAM wParam,LPARAM lParam);*/
extern "C" DLLEXPORT LRESULT WINAPI
GetMsgHookProc(int nCode,WPARAM wParam,LPARAM lParam);
//在win32 dll中,每個進程獲得其實例的全局變量拷貝。掛鉤程序要訪問
//全局變量,而且這些變量應裝入dll的所有進程之間共享。通過指定
//#progma data_seg指令和指定在def文件中的SECTION部分中的共享段可以
//作到著一點
#pragma data_seg(".sdata")
// HHOOK glhHook=NULL;//hook handle
HHOOK glhHook2=NULL;//hook handle
HINSTANCE glhInstance=NULL;//instance of dll
BOOL changed=FALSE;
#pragma data_seg()
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("KBDLL.DLL Initializing!\n");
// Extension DLL one-time initialization
if (!KbdllDLL.bInitialized)
{
AfxInitExtensionModule(KbdllDLL, hInstance);
// if (!AfxInitExtensionModule(KbdllDLL, hInstance))
// return 0;
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(KbdllDLL);
glhInstance=hInstance;
}
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("KBDLL.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(KbdllDLL);
}
return 1; // ok
}
CKbHook::CKbHook()
{
}
CKbHook::~CKbHook()
{
Stop();//uninstall mouse hook
}
HHOOK CKbHook::Start()
{
glhHook2=SetWindowsHookEx(WH_GETMESSAGE,GetMsgHookProc,glhInstance,0);
// glhHook=SetWindowsHookEx(WH_KEYBOARD,KeyboardHookProc,glhInstance,0);
return glhHook2;
}
BOOL CKbHook::Stop()
{
BOOL bResult=FALSE;
//uninstall mouse hook if currently active
/* if(glhHook)
{
bResult=UnhookWindowsHookEx(glhHook);
if(bResult)
{
//initalize variables
glhHook=NULL;
}
}*/
if(glhHook2)
{
bResult=UnhookWindowsHookEx(glhHook2);
if(bResult)
{
//initalize variables
glhHook2=NULL;
}
}
return bResult;
}
/*extern "C" DLLEXPORT LRESULT WINAPI
KeyboardHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
BOOL bNextProc=FALSE;
LRESULT lResult=0;
HWND hWndTarget=NULL;
if(!hWndTarget)
hWndTarget=::GetActiveWindow();
bNextProc=TRUE;
if(bNextProc)
lResult=CallNextHookEx(glhHook,nCode,wParam,lParam);
return(lResult);
}*/
extern "C" DLLEXPORT LRESULT WINAPI
GetMsgHookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
BOOL bStopMessage=FALSE;
MSG * msg=(MSG * ) lParam;
if(nCode<0)
return CallNextHookEx(glhHook2,nCode,wParam,lParam);
else
{
HWND hWndTarget=::GetActiveWindow();
switch(msg->message)
{
case WM_CHAR:
if(((char)(msg->wParam)=='-')&&(changed==FALSE))
{
msg->wParam=(WPARAM)'_';
changed=TRUE;
}
else
{
if(((char)(msg->wParam)=='_')&&(changed==FALSE))
{
msg->wParam=(WPARAM)'-';
changed=TRUE;
}
}
break;
default:
break;
}
}
changed=FALSE;
return CallNextHookEx(glhHook2,nCode,wParam,lParam);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -