📄 vnchooks.cpp
字号:
// Process the hook only if the Veneto window is valid
if (hVeneto != NULL)
{
MSG *msg = (MSG *) lParam;
// Only handle application messages if they're being removed:
if (wParam & PM_REMOVE)
{
// Handle the message
HookHandle(msg->message, msg->hwnd, msg->wParam, msg->lParam);
}
}
}
// Call the next handler in the chain
return CallNextHookEx (hGetMsgHook, nCode, wParam, lParam);
}
// Hook procedure for DialogMessageProc hook
LRESULT CALLBACK DialogMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Do we have to handle this message?
if (nCode >= 0)
{
// Process the hook only if the Veneto window is valid
if (hVeneto != NULL)
{
MSG *msg = (MSG *) lParam;
// Handle the message
HookHandle(msg->message, msg->hwnd, msg->wParam, msg->lParam);
}
}
// Call the next handler in the chain
return CallNextHookEx (hGetMsgHook, nCode, wParam, lParam);
}
// Hook procedure for LowLevel Keyboard filtering
#ifdef WH_KEYBOARD_LL
LRESULT CALLBACK LowLevelKeyboardFilterProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
if (nCode == HC_ACTION)
{
// Is this keyboard event "real" or "injected"
// i.e. hardware or software-produced?
KBDLLHOOKSTRUCT *hookStruct = (KBDLLHOOKSTRUCT*)lParam;
if (!(hookStruct->flags & LLKHF_INJECTED)) {
// Message was not injected - reject it!
return TRUE;
}
}
// Otherwise, pass on the message
return CallNextHookEx(hLLKeyboardHook, nCode, wParam, lParam);
}
LRESULT CALLBACK LowLevelKeyboardPriorityProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
// do we have a target window handle?
if (nCode == HC_ACTION && hKeyboardPriorityWindow != NULL)
{
// Is this keyboard event "real" or "injected"
// i.e. hardware or software-produced?
KBDLLHOOKSTRUCT *hookStruct = (KBDLLHOOKSTRUCT*)lParam;
if (!(hookStruct->flags & LLKHF_INJECTED)) {
// Message was not injected - send RFB_LOCAL_KEYBOARD msg!
// Remote event will be blocked
PostMessage(
hKeyboardPriorityWindow,
LocalKeyboardMessage,
0,
0
);
}
}
// Otherwise, pass on the message
return CallNextHookEx(hLLKeyboardPrHook, nCode, wParam, lParam);
}
#endif
// Hook procedure for LowLevel Mouse filtering
#ifdef WH_MOUSE_LL
LRESULT CALLBACK LowLevelMouseFilterProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
if (nCode == HC_ACTION)
{
// Is this mouse event "real" or "injected"
// i.e. hardware or software-produced?
MSLLHOOKSTRUCT *hookStruct = (MSLLHOOKSTRUCT*)lParam;
if (!(hookStruct->flags & LLMHF_INJECTED)) {
return TRUE;
}
}
// Otherwise, pass on the message
return CallNextHookEx(hLLMouseHook, nCode, wParam, lParam);
}
LRESULT CALLBACK LowLevelMousePriorityProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
// do we have a target window handle?
if (nCode == HC_ACTION && hMousePriorityWindow != NULL)
{
// Is this mouse event "real" or "injected"
// i.e. hardware or software-produced?
MSLLHOOKSTRUCT *hookStruct = (MSLLHOOKSTRUCT*)lParam;
if (!(hookStruct->flags & LLMHF_INJECTED)) {
// Message was not injected - send RFB_LOCAL_MOUSE msg!
// Remote event will be blocked
PostMessage(
hMousePriorityWindow,
LocalMouseMessage,
0,
0
);
}
}
// Otherwise, pass on the message
return CallNextHookEx(hLLMousePrHook, nCode, wParam, lParam);
}
#endif
LRESULT CALLBACK KeyboardPriorityProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
// do we have a target window handle?
if (nCode == HC_ACTION && hKeyboardPriorityWindow != NULL)
{
PostMessage(
hKeyboardPriorityWindow,
LocalKeyboardMessage,
0,
0
);
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
LRESULT CALLBACK MousePriorityProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Are we expected to handle this callback?
// do we have a target window handle?
if (nCode == HC_ACTION && hMousePriorityWindow != NULL)
{
if ( (wParam == WM_LBUTTONDOWN) || (wParam == WM_RBUTTONDOWN) || (wParam == WM_MBUTTONDOWN) || (wParam == WM_MOUSEMOVE) )
PostMessage(
hMousePriorityWindow,
LocalMouseMessage,
0,
0
);
}
return CallNextHookEx(hMouseHook, nCode, wParam, lParam);
}
char * NameFromPath(const char *path)
{
int x;
int l = strlen(path);
char *temp = NULL;
// Find the file part of a filename
for (x=l-1; x>0; x--)
{
if (path[x] == '\\')
{
temp = strdup(&(path[x+1]));
break;
}
}
// If we didn't fine a \ then just return a copy of the original
if (temp == NULL)
temp = strdup(path);
return temp;
}
/////////////////////////////////////////////////////////////////////////////
// Initialise / Exit routines.
// These functions handle the update settings for any apps used with WinVNC.
static const TCHAR szSoftware[] = "Software";
static const TCHAR szCompany[] = "ORL";
static const TCHAR szProfile[] = "VNCHooks";
HKEY GetRegistryKey()
{
HKEY hAppKey = NULL;
HKEY hSoftKey = NULL;
HKEY hCompanyKey = NULL;
if (RegOpenKeyEx(HKEY_CURRENT_USER, szSoftware, 0, KEY_WRITE|KEY_READ,
&hSoftKey) == ERROR_SUCCESS)
{
DWORD dw;
if (RegCreateKeyEx(hSoftKey, szCompany, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hCompanyKey, &dw) == ERROR_SUCCESS)
{
RegCreateKeyEx(hCompanyKey, szProfile, 0, REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL,
&hAppKey, &dw);
}
}
if (hSoftKey != NULL)
RegCloseKey(hSoftKey);
if (hCompanyKey != NULL)
RegCloseKey(hCompanyKey);
return hAppKey;
}
HKEY GetModuleKey(const char *proc_name)
{
HKEY hModule = NULL;
// Work out the registry key to save this under
sModulePrefs = (char *) malloc(strlen(sPrefSegment) + strlen(proc_name) + 1);
if (sModulePrefs == NULL)
return FALSE;
sprintf(sModulePrefs, "%s%s", sPrefSegment, proc_name);
// Check whether the library's entry exists!
HKEY hAppKey = GetRegistryKey();
if (hAppKey == NULL)
return NULL;
// Attempt to open the section for this application
if (RegOpenKeyEx(hAppKey,
sModulePrefs,
0, KEY_WRITE|KEY_READ,
&hModule
) != ERROR_SUCCESS)
{
// Cut off the app directory and just use the name
char *file_name = NameFromPath(proc_name);
if (file_name == NULL)
{
RegCloseKey(hAppKey);
return NULL;
}
// Adjust the moduleprefs name
sprintf(sModulePrefs, "%s%s", sPrefSegment, file_name);
free(file_name);
// Now get the module key again
DWORD dw;
if (RegCreateKeyEx(hAppKey,
sModulePrefs,
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE|KEY_READ,
NULL,
&hModule,
&dw) != ERROR_SUCCESS)
{
// Couldn't find/create the key - fail!
RegCloseKey(hAppKey);
return NULL;
}
}
// Close the application registry key
RegCloseKey(hAppKey);
return hModule;
}
int GetProfileInt(LPTSTR key, int def)
{
DWORD type;
DWORD value;
ULONG size = sizeof(value);
if (RegQueryValueEx(
hModuleKey,
key,
NULL,
&type,
(unsigned char *)&value,
&size) == ERROR_SUCCESS)
{
// Is the value of the right type?
if (type != REG_DWORD)
{
return def;
}
else
{
return value;
}
}
else
{
return def;
}
}
void WriteProfileInt(LPTSTR key, int value)
{
RegSetValueEx(
hModuleKey,
key,
0,
REG_DWORD,
(unsigned char *)&value,
sizeof(value));
}
BOOL InitInstance()
{
// Create the global atoms
VNC_WINDOWPOS_ATOM = GlobalAddAtom(VNC_WINDOWPOS_ATOMNAME);
if (VNC_WINDOWPOS_ATOM == NULL)
return FALSE;
VNC_POPUPSELN_ATOM = GlobalAddAtom(VNC_POPUPSELN_ATOMNAME);
if (VNC_POPUPSELN_ATOM == NULL)
return FALSE;
// Get the module name
char proc_name[_MAX_PATH];
DWORD size;
// Attempt to get the program/module name
if ((size = GetModuleFileName(
GetModuleHandle(NULL),
(char *) &proc_name,
_MAX_PATH
)) == 0)
return FALSE;
// Get the key for the module
hModuleKey = GetModuleKey(proc_name);
if (hModuleKey == NULL)
return FALSE;
// Read in the prefs
prf_use_GetUpdateRect = GetProfileInt(
"use_GetUpdateRect",
TRUE
);
prf_use_Timer = GetProfileInt(
"use_Timer",
FALSE
);
prf_use_KeyPress = GetProfileInt(
"use_KeyPress",
TRUE
);
prf_use_LButtonUp = GetProfileInt(
"use_LButtonUp",
TRUE
);
prf_use_MButtonUp = GetProfileInt(
"use_MButtonUp",
TRUE
);
prf_use_RButtonUp = GetProfileInt(
"use_RButtonUp",
TRUE
);
prf_use_Deferral = GetProfileInt(
"use_Deferral",
#ifdef HORIZONLIVE
FALSE // we use full screen polling anyway
#else
TRUE
#endif
);
return TRUE;
}
BOOL ExitInstance()
{
// Free the created atoms
if (VNC_WINDOWPOS_ATOM != NULL)
{
GlobalDeleteAtom(VNC_WINDOWPOS_ATOM);
VNC_WINDOWPOS_ATOM = NULL;
}
if (VNC_POPUPSELN_ATOM != NULL)
{
GlobalDeleteAtom(VNC_POPUPSELN_ATOM);
VNC_POPUPSELN_ATOM = NULL;
}
// Write the module settings to disk
if (sModulePrefs != NULL)
{
WriteProfileInt(
"use_GetUpdateRect",
prf_use_GetUpdateRect
);
WriteProfileInt(
"use_Timer",
prf_use_Timer
);
WriteProfileInt(
"use_KeyPress",
prf_use_KeyPress
);
WriteProfileInt(
"use_LButtonUp",
prf_use_LButtonUp
);
WriteProfileInt(
"use_MButtonUp",
prf_use_MButtonUp
);
WriteProfileInt(
"use_RButtonUp",
prf_use_RButtonUp
);
WriteProfileInt(
"use_Deferral",
prf_use_Deferral
);
free(sModulePrefs);
sModulePrefs = NULL;
}
// Close the registry key for this module
if (hModuleKey != NULL)
RegCloseKey(hModuleKey);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -