Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2002, 11:16 AM
Myst Myst is offline
Senior Member
 
Join Date: Feb 2002
Posts: 336
Default Simulating a button click?

Hi, i'm trying to click the "Ok" button on a dialog box by code. It compiles fine but doesn't seem to click the button, or if it does the button doesn't close the dialog box as it should. Heres my code:

procedure TForm1.Button1Click(Sender: TObject);
var
Window: hWnd;
begin
Window := FindWindowEx(FindWindow('#32770ialog',nil),0,'Bu tton',nil);
SendMessage(Window, WM_LBUTTONDOWN, MK_LBUTTON, MakeLParam(5,5));
SendMessage(Window, WM_LBUTTONUP, MK_LBUTTON, MakeLParam(5, 5));
end;

Can anyone tell me why its not working?

Thnx,

--== Arius Myst ==-

MSN: Arius@Slackroot.com
Reply With Quote
  #2  
Old 11-10-2002, 11:25 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Simulating a button click?

If you just want to close a modal form, then set the ModalResult property...
ModalResult := mrOk;


Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #3  
Old 11-10-2002, 11:28 AM
Myst Myst is offline
Senior Member
 
Join Date: Feb 2002
Posts: 336
Default RE: Simulating a button click?

Its an external dialog.

--== Arius Myst ==-

MSN: Arius@Slackroot.com
Reply With Quote
  #4  
Old 11-10-2002, 11:43 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: Simulating a button click?

I realised that just as I sent the first reply. (I couldn't
find an undo button)

Are you sure the handle of the button is correct? (Can you retrieve the button caption for example?)

If I replace the window handle with a button on another form (admitadly, still in the same application) then it works OK, so I suspect the window handle might be wrong.


procedure TForm1.Button3Click(Sender: TObject);
var
Window: hWnd;
begin
// Window := FindWindowEx(FindWindow('#32770ialog', nil), 0, 'Button', nil);

Window := Form2.Button1.Handle;

// SendMessage(Window, CN_COMMAND, VK_RETURN, 0);

SendMessage(Window, WM_LBUTTONDOWN, MK_LBUTTON, MakeLParam(5, 5));
SendMessage(Window, WM_LBUTTONUP, MK_LBUTTON, MakeLParam(5, 5));
end;


Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
Reply With Quote
  #5  
Old 11-10-2002, 12:06 PM
Myst Myst is offline
Senior Member
 
Join Date: Feb 2002
Posts: 336
Default RE: Simulating a button click?

Ahh, yea your right. I'm missing out the parent and went straight to the dialog->button. Thnx man

--== Arius Myst ==-

MSN: Arius@Slackroot.com
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:08 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.