Link to home
Start Free TrialLog in
Avatar of cosminm
cosminm

asked on

Checkbox status

I want to change checked/unchecked a checkbox with a mouse positioned above it. Could you help me with an example?
Avatar of rwilson032697
rwilson032697

Try this:

var
  CPos : TPoint;
begin
  GetCursorPos(CPos);
  if ControlAtPos(CPos) is TComboBox then
    with (ControlAtPos(CPos) as TComboBox) do
      Checked := Not Checked;
end;

Cheers,

Raymond.
Oh cosminm,you are in here!
this is my answer:

var pt:tpoint;
begin
....
  pt:=Form1.ClienttoScreen(point(CheckBox1.Left,CheckBox1.Top));
  SetCursorPos(pt.x+4,pt.y+4);
....
end;

menxin

Avatar of cosminm

ASKER

The problem is that the checkbox is not in my program (is somewhere on the screen)... :(
I posted the q. here because I'm in a hurry and I offer points. :)
Principally you should do something like...

- try to find the window handle of the check-box
  (and that's the tough part of the job)

- send it a message
  State:=SendMessage(HWnd, BM_GETCHECK, 0, 0)
  SendMessage(HWnd, BM_SETCHECK, State, 0)

I have no idea how to get the handle (maybe WindowFromPoint helps)

So long, Roadrunner

ASKER CERTIFIED SOLUTION
Avatar of men xin
men xin
Flag of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cosminm

ASKER

Cool, worked.
I have one more (not burning)...
What are the API for get a string from a button.caption and a edit.text?

In fact I want to made an automation with clicks of a program outside mine...
Is there a component for this propose?
It would be much helpful...
clickbutton?try this

SendMessage(WindowFromPoint(Mouse.CursorPos), wm_lbuttondown, 0, 0);
SendMessage(WindowFromPoint(Mouse.CursorPos), wm_lbuttonup, 0, 0);

and you can send a WM_GETTEXT message to a edit.

menxin