Følgende lille c-program virker med GCC og BorlandC.
Det skal kompileres som C og ikke C++!
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <windows.h>
HHOOK MouseHook;
HMODULE DllModule;
LRESULT __declspec(dllexport) LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION)
{
KBDLLHOOKSTRUCT *HookStruct = (KBDLLHOOKSTRUCT *)lParam;
if(HookStruct->vkCode == VK_NEXT)
{
return TRUE;
}
}
return CallNextHookEx(MouseHook, nCode, wParam, lParam);
}
void InstallHook(void)
{
FARPROC proc;
char Fn[256];
if(MouseHook)
return;
GetModuleFileName(0, Fn, sizeof(Fn));
if((DllModule = LoadLibrary(Fn)) == 0)
{
MessageBox(0, "Failed to find load lib", "NG27", MB_OK);
return;
}
#ifdef __BORLANDC__
proc = GetProcAddress(DllModule, "_LowLevelKeyboardProc");
#else
proc = GetProcAddress(DllModule, "LowLevelKeyboardProc");
#endif
if(!proc)
{
MessageBox(0, "Failed to find hook proc", "NG27", MB_OK);
return;
}
MouseHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC )proc, DllModule, 0);
if(!MouseHook)
{
MessageBox(0, "Failed to install Hook", "NG27", MB_OK);
return;
}
}
void UnInstallHook(void)
{
if(MouseHook)
UnhookWindowsHookEx(MouseHook);
MouseHook = 0;
if(DllModule)
FreeLibrary(DllModule);
DllModule = 0;
}
int main()
{
InstallHook();
MessageBox(0, "Hit Ok to close", "PageDown Remover", MB_OK);
UnInstallHook();
return 1;
}
Hvis du bruger en anden kompiler finder vi nok også ud af det.
Hvilket OS bruger du?
Hvis/når du får det til at virke kan vi forbedre brugerfladen.