Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

using SetSystemCursor properly.

I am still alil mystified as the the proper way to use the SetSystemCursor function and was hoping  one of the experts here could provide me with alil code on how to use it properly...

Basically all I want to do is to click on this little icon I placed in a panel on my program and as long as I keep the mouse button down (even when moving it off my application) the system cursor will change to that icon and when I let go of the mouse button it will change back to the normal system cursor.

I hope I explained my needs well enough but if not then I will try to help anyway I can and thank you for your replies in advance.
0
voodoo22
Asked:
voodoo22
  • 6
  • 3
1 Solution
 
mikelittlewoodCommented:
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Screen.Cursor := crHourGlass;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Screen.Cursor := crDefault;
end;

seemed to work fine for me
0
 
mikelittlewoodCommented:
This will change your cursor to an hourglass. It will stay like that as long as you dont let go of the mouse button.
It seems to work even if not on the application but let me know please.
0
 
voodoo22Author Commented:
that  only seems to work for the cursors that are built into delphi but I need it to work when I load a custom cursor from a resource file.
0
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.

 
mikelittlewoodCommented:
These PAQ's should tell you how to load your cursor from a file
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10019363.html?query=load+cursor+from+file&topics=85
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20685409.html?query=load+cursor+from+file&topics=85


the interesting bits are:
1. By the Image Editor which comes with Delphi, create a new resource file on the same directory of the project. Name it as test.res.
2. Draw a cursor and name it as CURSOR_1.

screen.cursors[1]:=LoadCursor(hInstance, pChar('CURSOR_1'));
0
 
voodoo22Author Commented:
tried that no joy.... what happens is when I click on image1 nothing happens but when I let off the mouse the custom cursor loads and no matter what I do it will not go away when it's over my application but as soon as I leave my app it goes back to the normal cursor again which is obviously not what I am wanting to do.

Code:

Const
crMyCursor = 1;

var
  Form1: TForm1;

implementation

{$R *.dfm}
{$R crf.RES}

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'search_cursor');
  Cursor := crMyCursor;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 Screen.Cursor := crDefault;
end;

end.


Again all I want to do is when I put click and hold down the mouse button it will load my custom cursor and when I let off the mouse button it will go back to the normal cursor. Sounds ez but so far it's been everything but.
0
 
mikelittlewoodCommented:
Try changing to

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Screen.Cursors[crMyCursor] := LoadCursor(HInstance, 'search_cursor');
  Screen.Cursor := crMyCursor;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Screen.Cursor := crDefault;
end;
0
 
mikelittlewoodCommented:
I think Cursor := crMyCursor was the issue.
Should be Screen.Cursor := crMyCursor
0
 
voodoo22Author Commented:
that did the trick thx for the help.
0
 
mikelittlewoodCommented:
Glad I could poiint you in the right direction
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now