Graphic Delphi

Title: SetCursorPos -- the right way
Question: SetCursorPos (x-coord, y-coord) won't work as it should! How then?
Answer:
I needed to put the cursor on placres on the form and on certain
controls I needed it to be. SetCuyrsorPos(15,67) etc. wouldn't do it.
This is a little demo-project that shows you how to use SetCurssorPos
Omer Yasar Can -- omercan@home.nl
ALI BABA Computn' -- Holland
Code was entered with Delphi 5
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
RadioButton1: TRadioButton;
RadioGroup1: TRadioGroup;
StatusBar1: TStatusBar;
Button1: TButton;
Label1: TLabel;
CheckBox_ClickAfterSet: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Label1Click(Sender: TObject);
procedure RadioButton1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var pt: TPoint;
begin
pt:= Form1.ClientToScreen(Point(5,5));
SetCursorpos( pt.x, pt.y );
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
var pt: TPoint;
begin
case RadioGroup1.ItemIndex of
0: pt:= RadioButton1.ClientToScreen(Point(5,5));
1: pt:= Label1.ClientToScreen(Point(5,5));
2: pt:= Button1.ClientToScreen(Point(5,5));
end;
SetCursorpos( pt.x, pt.y );
if CheckBox_ClickAfterSet.Checked then begin //sumulate click?
mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 );
mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 );
end;
end;
//==============================================================================
procedure TForm1.Button1Click(Sender: TObject);
begin
Form1.Caption := 'Button1 clicked';
end;
procedure TForm1.Label1Click(Sender: TObject);
begin
Form1.Caption := 'Label1 clicked';
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Form1.Caption := 'RadioButton1 ckecked';
end;
//==============================================================================
end.
here the dfm-file:
object Form1: TForm1
Left = 524
Top = 408
Width = 259
Height = 240
Caption = 'Delphi-programming--HOW TO'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 96
Top = 56
Width = 32
Height = 13
Caption = 'Label1'
OnClick = Label1Click
end
object RadioButton1: TRadioButton
Left = 56
Top = 32
Width = 113
Height = 17
Caption = 'RadioButton1'
TabOrder = 0
OnClick = RadioButton1Click
end
object RadioGroup1: TRadioGroup
Left = 0
Top = 88
Width = 185
Height = 105
Caption = 'RadioGroup1'
Items.Strings = (
'RadioButton1'
'Label1'
'Button1')
TabOrder = 1
OnClick = RadioGroup1Click
end
object StatusBar1: TStatusBar
Left = 0
Top = 194
Width = 251
Height = 19
Panels = item
Text = 'SetCursorPos - the right way'
Width = 140
end
item
Text = 'Dir:\SetCursorPos'
Width = 50
end
SimplePanel = False
end
object Button1: TButton
Left = 168
Top = 56
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 3
OnClick = Button1Click
end
object CheckBox_ClickAfterSet: TCheckBox
Left = 96
Top = 136
Width = 81
Height = 25
Caption = '&Click after set'
Checked = True
State = cbChecked
TabOrder = 4
end
end
end the dpr-file:
program SetCursorPos;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.