Please help anybody with bug, which I had. So, first remade dll (see above) to this :
library project1;
{$R *.res}
uses windows, messages;
var
SaveExitProc: Pointer;
// Handle the traps
HMouse: hHook = 0;
// Function traps
function Key_HookMouse (code: integer; wParam: integer;
lParam: integer): integer stdcall;
begin
if (code>= 0) and ((wParam = WM_NCLBUTTONUP) or (wParam = WM_LBUTTONUP))
then begin
SendMessage(findwindow('Window','project1'), WM_SYSCOMMAND,SC_MINIMIZE, 0);
SendMessage(findwindow('Window','project1'), WM_SYSCOMMAND,SC_RESTORE, 0);
end;
Result:= CallNextHookEx (HMouse, code, wParam, lParam);
end;
procedure StartMouse;
// Set the trap keyboard
begin
if HMouse = 0 then
HMouse:= SetWindowsHookEx (WH_MOUSE, @ Key_HookMouse,
hInstance, 0);
if HMouse = 0 then
MessageBox (0, 'The trap is not established', 'Error', mb_Ok);
end;
procedure RemoveHookMouse;
// Update mouse traps
begin
if HMouse <> 0 then
begin
UnhookWindowsHookEx (HMouse);
HMouse:= 0
end;
end;
procedure RemoveExit;
// Remove the trap at the end of work
begin
if HMouse <> 0
then UnhookWindowsHookEx (HMouse);
ExitProc:= SaveExitProc;
end;
exports
StartMouse,
RemoveHookMouse;
begin
// Specifying the exit procedure, which lifts the trap
SaveExitProc:= ExitProc;
ExitProc:= @ RemoveExit;
end.
Then place dll to the same folder as project1.exe and start exe.
Open Microsoft Paint. Press Start monitoring left mouse button clicks button. Start draw something in Paint window. You must release left mouse button at least 20 times to see bug. The bug is that application does multiple minimizeing-restoring instead of 1 minimize for 1 left mouse button.
Why does it do that?