Nææ... vent nu lidt...
Følgende kode jeg lige hurtig biksede sammen virker ikke:
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
HHOOK MouseHook;
void InstallHook(void);
void UnInstallHook(void);
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch(nMsg)
{
case WM_CREATE:
{
InstallHook();
UnInstallHook();
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
}
return DefWindowProc(hwnd, nMsg, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
WNDCLASSEX wndclass;
char*szMainWndClass = "winapi2";
memset (&wndclass, 0, sizeof(WNDCLASSEX));
wndclass.lpszClassName = szMainWndClass;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = MainWndProc;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(NULL, NULL);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
RegisterClassEx (&wndclass);
MSG msg;
HWND hwndMain;
hwndMain = CreateWindow (
szMainWndClass,
"Windows api",
WS_OVERLAPPEDWINDOW,
0,
0,
500,
600,
NULL,
NULL,
hInst,
NULL
);
ShowWindow (hwndMain, SW_HIDE);
UpdateWindow (hwndMain);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HC_ACTION)
{
MSLLHOOKSTRUCT *HookStruct = (MSLLHOOKSTRUCT *)lParam;
std::ofstream File("C:/koord.txt", std::ios::app);
switch(wParam)
{
case WM_LBUTTONDOWN:
break;
case WM_LBUTTONUP:
File << "LBUTTONUP: ";
File << HookStruct->pt.x << ", " << HookStruct->pt.y << std::endl;
break;
case WM_MOUSEMOVE:
break;
case WM_MOUSEWHEEL:
File << "MOUSEWHEEL: ";
break;
case WM_RBUTTONDOWN:
File << "RBUTTONDOWN: ";
break;
case WM_RBUTTONUP:
File << "RBUTTONUP: ";
break;
default:
File << "Unknown: ";
break;
}
}
return CallNextHookEx(MouseHook, nCode, wParam, lParam);
}
void InstallHook(void)
{
if(MouseHook)
return;
MouseHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC )LowLevelMouseProc, GetModuleHandle(0), 0);
if(!MouseHook)
{
MessageBox(0, "Failed to install Hook", "PageDown Remover", MB_OK);
}
}
void UnInstallHook(void)
{
if(MouseHook)
UnhookWindowsHookEx(MouseHook);
MouseHook = 0;
}
Indlæg senest redigeret d. 03.03.2008 17:23 af Bruger #11328