Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

URGENT - Simulate MouseClick on a specific form

Hi again,

How can I programatically sumulate a mouseclick on a specific form please?



Avatar of MerijnB
MerijnB
Flag of Netherlands image

can you please be more specific what you want to achieve?
Avatar of ST3VO

ASKER

Well...this is what's happening...

I start my application....

Form1:
It loads stuff into memory and I have a Loading Please Wait ... text on it.

Form2:
This Form is a small ToolBar type aligned on the bottom on top of Form1, which is the main form.

All this is fine BUT....The Please Wait ... stays on the form forever and doesn't go to the next level until I Click My mouse on Form1.

Otherwise it would be working fine.

So, for a quick fix if I can just simulate that MouseClick on Form1 ...it would work fine, unless you know another way!

Hope this explaination helps

Thanks

- ST3VO

I assume you create that please-wait-form yourself.

Do you know why the click on the mainform hides this please-wait-form?
What did you try to make the please-wait-form to go away by itself?
Avatar of ST3VO

ASKER

No....The Please Wait Text is on the Main form itself.

It's 3D Programming....and the text is rendered by the engine.

If Form2 doesn't show up it doesn't have a problem BUT when Form2 Shows, then I need to click on Form1 for the rendered Textures to show up.

I think it's a question of focus BUT Form1.Setfocus does not fix it...only me clicking on Form1 does the trick, so that's why I need to do it by code.

Hope this helps further

try

Form1.invalidate
Avatar of ST3VO

ASKER

I Get an Access Violation Error when I try to use it :o(

Isn't it better to just simulate to MouseClick on form1???

ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
Flag of Netherlands 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
if don't mind,

    Can you show some code?
Avatar of ST3VO

ASKER

I'm still getting an access violation error so I suppose that I need to find where to put the code.

I've create a procedure because I didn't want a Buttonclick...

So this is what i've done:

procedure TForm1.SimMouseClick;
var Inputs: array of TInput;
begin
 Mouse.CursorPos := Point(100, 100);

 SetLength(Inputs, 2);

 Inputs[0].Itype := INPUT_MOUSE;
 Inputs[0].mi.dwFlags := MOUSEEVENTF_LEFTDOWN;

 Inputs[1].Itype := INPUT_MOUSE;
 Inputs[1].mi.dwFlags := MOUSEEVENTF_LEFTUP;

 SendInput(2, Inputs[0], SizeOf(TInput));
end;

Then on the Form2...OnShow...I use:  Form1.SimMouseClick;

But I ge an Access Violation Error

Hmmm



Check your form creation order. Is Form1 is your mainform(first creating form)
Avatar of ST3VO

ASKER

Yes it is!

2nd is form2
set a breakpoint, try to figure out what causes the AV
Avatar of ST3VO

ASKER

OK..I'll give it a shot!!!
Avatar of ST3VO

ASKER

The problem seems to be that I need to wait until Form2 is fully loaded until I can call the SimMouseClick procedure.

The question now is .....Got an Idea!!!!!!!!!!!!   I'll get back to you!
Avatar of ST3VO

ASKER

GREAT!!!!!

Got it to work!!!! :o)

The Old Good Try...Finally...

procedure TForm2.FormShow(Sender: TObject);
Var f1H, f1w: Integer;
begin
try
blah...blah...blah
finally
Form1.SimMouseClick;
end;

And it works perfectly now!!!

Great!!!

Thanks guys!!!!

- ST3VO