?
Solved

Globally Show Windows Cursor on Mouse Click

Posted on 2007-07-26
7
Medium Priority
?
197 Views
Last Modified: 2010-04-05
Hi all,

I need to globally be able to right-click on the mouse and show the windows cursor.

Same as: ShowCursor(True);

but Globally (With Globally I mean - in whatever Form I'm in), without having to code OnMouseDown etc... for every form.

Any ideas on how to do this please?

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 4
  • 3
7 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 2000 total points
ID: 19574378
see this example for a local mouse hook (local meaning your own app only):

unit Unit13;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm13 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form13: TForm13;

implementation

var fMouseHook: hHook;

{$R *.dfm}

function MouseProc(nCode: integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
begin
 if nCode >= 0 then
  case wParam of
   WM_LBUTTONDOWN: ShowCursor(true);
  end;

 result := CallNextHookEx(fMouseHook, nCode, wParam, lParam);
end;

procedure TForm13.FormCreate(Sender: TObject);
begin
 fMouseHook := SetWindowsHookEx(WH_MOUSE, @MouseProc, 0, GetWindowThreadProcessId(Application.Handle));
end;

procedure TForm13.FormDestroy(Sender: TObject);
begin
 UnhookWindowsHookEx(fMouseHook);
end;

end.
0
 

Author Comment

by:ST3VO
ID: 19574537
Do I need to include uses unit13 to all forms?

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19574543
no
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ST3VO
ID: 19574608
OK...thanks...i'll give it a shot!!! :o)
0
 

Author Comment

by:ST3VO
ID: 19574802
Perfect!!!! Just changed the WM_LBUTTONDOWN to WM_RBUTTONDOWN for Right Mouse Button!!!

Thanks a million! :o)

-ST3VO


0
 
LVL 19

Expert Comment

by:MerijnB
ID: 19574835
shoot, right mouse button, not left. Missed that one :p
0
 

Author Comment

by:ST3VO
ID: 19574901
No problem! Works perfect and it's a very minor change! Thanks again :o)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question