Mouse and Joystick

OnMouseLeave Event needed

From: "Steve Davidson" <sdpixel@wolfenet.com>

All descendants of TComponent send a CM_MOUSEENTER and CM_MOUSELEAVE message when the mouse enters and leaves the bounds of the component. You will need to write a message handler for the respective messages if you wish to respond to them.


procedure CMMouseEnter(var msg:TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
..
..
..
procedure MyComponent.CMMouseEnter(var msg:TMessage);
begin
    inherited;
    {respond to mouse enter}
end;

procedure MyComponent.CMMouseLeave(var msg: TMessage);
begin
    inherited;
    {respond to mouse leave}
end;

Tip: using animated cursors

From: "John F. Goyvaerts" <johnfg@tornado.be>

Hi.

I was told there have been some questions in this newsgroup about animated cursors. I don't know if this was the real issue, but using animated cursors in your applications is very easy.

Here's an example:

(mycursor.ani is an animated cursor file. You can create those with Microsoft's aniedit.exe)


const crMyCursor = 1;

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Load the cursor. Needs to be done only once
  Screen.Cursors[crMyCursor] :=
LoadCursorFromFile('c:\mystuff\mycursor.ani');
  // Use the cursor with this form
  Cursor := crMyCursor;
end;

I hope I've helped out someone with this information.

Building Mouse Hooks

From: David Ullrich <ullrich@math.okstate.edu>


library Hookdemo;

uses

  Beeper in '\DELDEMOS\HOOKDEMO\BEEPER.PAS';


exports
       SetHook index 1,
       UnHookHook index 2,
       HookProc index 3;

begin
   HookedAlready:=False;
end.

, where beeper.pas is like so:


unit Beeper;

interface

uses Wintypes,Winprocs,Messages;

function SetHook:Boolean;export;
function UnHookHook:Boolean;export;
function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;export;

var HookedAlready:Boolean;

implementation

var
   ourHook:HHook;


function SetHook:Boolean;
begin
if HookedAlready then exit;
ourHook:=SetWindowsHookEx(WH_MOUSE,HookProc,HInstance,0);
HookedAlready:=True;
end;

function UnHookHook:Boolean;
begin
UnHookWindowsHookEx(ourHook);
HookedAlready:=False;
end;

function HookProc(Code:integer; wParam: Word; lParam: Longint): Longint;
begin
   if (wParam=WM_LBUTTONDOWN) then MessageBeep(0);
   result:=CallNextHookEx(ourHook,Code,wParam,lParam);
end;

end.

Now if you call the SetHook function from an application there's a beep everytime you press the left mouse button - this continues until you call the UnHookHook function. In an actual application you're supposed to call CallNextHookEx immediately and do nothing else if code < 0 .

acessing the joystick from Delphi

From: "Mark Wilkinson" <markw@peninsula.starway.net.au> Actually, with Delphi 2 its a breeze. The following was taken from working code, so you'll have to adapt it for your own purposes, but it should point you in the right direction.


var
  myjoy: tjoyinfo;
begin
  joygetpos(joystickid1,@myjoy);
  trackbar1.position := myjoy.wypos;
  trackbar2.position := myjoy.wxpos;
  radiobutton1.checked := (myjoy.wbuttons and joy_button1)>0;
  radiobutton2.checked := (myjoy.wbuttons and joy_button2)>0;
end;

Make sure to include MMSYSTEM in your USES clause.
Please email me and tell me if you liked this page.

This page has been created with