PDA

Ver la Versión Completa : Bloquear mensaje DobleClic del ratón


jhonalone
20-11-2012, 15:32:39
Hola, amigos.
He estado buscando en los foros la forma de hacer un hook para bloquear el mensaje DobleClick del ratón. Lo más parecido que he encontrado es un hook para bloquear el botón derecho, posteado en 2006 por el maestro Domingo Seoane, basándose en código del incomparable moderador Román.
Pero no me funciona, he cambiado los identificadores del mensaje en el código original, pero no lo consigo bloquear.

Código original


if</SPAN> (WParam = WM_RBUTTONDOWN) or</SPAN> (WParam = WM_RBUTTONUP)


Código modificadoif (WParam = WM_LBUTTONDBLCLK) or (WParam = WM_RBUTTONDBLCLK) Codigo completo modificado
unit Hooks;


interface
procedure SetHook;
procedure ReleaseHook;
implementation
uses Windows, Messages;
const
WH_MOUSE_LL = 14;
var
Hook: HHook;
function MouseProc(Code: Integer; WParam, LParam: DWORD): HHook; stdcall;
begin
if Code = HC_ACTION then
begin
if (WParam = WM_LBUTTONDBLCLK) or (WParam = WM_RBUTTONDBLCLK) then
begin
Result:= 1;
Exit;
end;
end;
Result := CallNextHookEx(Hook, Code, WParam, LParam);
end;
procedure SetHook;
begin
Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0);
end;
procedure ReleaseHook;
begin
if Hook <> 0 then UnhookWindowsHookEx(Hook);
end;
initialization
Hook := 0;
finalization
ReleaseHook;
end.


Pongo el código completo por si alguien me puede ayudar y por si puede ser útil par alguien más.

Gracias a a todos, por leerme y por vuestra paciencia.

No sé qué me pasa con el editor, no es el primer post que escribo.

He vuelto a escribir el post completo, espero que se pueda leer.

Lo siento. No utilizo la vista previa, porque una vez que la usé también se descolocó el editor.
Debe ser culpa mía.

escafandra
21-11-2012, 02:41:05
No existen los mensajes WM_LBUTTONDBLCLK y WM_RBUTTONDBLCLK para un Hook de ratón, por eso no te funciona. Deberás medir el tiempo entre dos clicks sucesivos para saber si se trata de un doble click quedaría de esta forma:


unit Hooks;


interface
procedure SetHook;
procedure ReleaseHook;

function clock: integer; cdecl; external 'msvcrt.dll';

implementation
uses Windows, Messages;
const
WH_MOUSE_LL = 14;
var
Hook: HHook;


function DBLClick_Detect: boolean;
const
{$J+}
start: integer = 0;
var
dif: integer;
begin
Result:= false;
if start = 0 then start:= clock();
dif:= clock() - start;
if (dif < GetDoubleClickTime) and (dif > 3) then Result:= true;
start:= clock();
{$J-}
end;

function MouseProc(Code: Integer; WParam, LParam: DWORD): HHook; stdcall;
begin
if Code = HC_ACTION then
begin
if (WParam = WM_LBUTTONDOWN) or (WParam = WM_RBUTTONDOWN) then
begin
if DBLClick_Detect then
begin
Result:= 1;
Exit;
end;
end;
end;
Result := CallNextHookEx(Hook, Code, WParam, LParam);
end;

procedure SetHook;
begin
Hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0);
end;
procedure ReleaseHook;
begin
if Hook <> 0 then UnhookWindowsHookEx(Hook);
end;

initialization
Hook := 0;

finalization
ReleaseHook;

end.



Saludos.

jhonalone
21-11-2012, 14:50:23
Mil millones de gracias, Escafandra. Funcionó perfectamente.
Asombrado me teneis de tanto como sabeis.
Un saludo.