Indefrei
asked on
Simulate a keyPressed to other window
Well,
i wanna send a #13 = Return to a foreign program window
i do have the window's handle with a EnumWindowsetc.
the window is just an information, but you have to click an OK-button
i'd like to simulate the pressing or clicking of the return-key.
but i think I have to get the Buttons Handle for this ??
This wouldn't help
g:=findwindow('TheWindow', nil);
d:=Childwindowfrompoint(g, point(50,5 0));
sendmessage(d,wm_char,#13, 0);
so, please, help
Indi
i wanna send a #13 = Return to a foreign program window
i do have the window's handle with a EnumWindowsetc.
the window is just an information, but you have to click an OK-button
i'd like to simulate the pressing or clicking of the return-key.
but i think I have to get the Buttons Handle for this ??
This wouldn't help
g:=findwindow('TheWindow',
d:=Childwindowfrompoint(g,
sendmessage(d,wm_char,#13,
so, please, help
Indi
ASKER
Don't agree with
>>You need to activate the target window first so the keys go to it...
cause
g:=findwindow('Notepad',ni l);
d:=Childwindowfrompoint(g, point(50,5 0));
sendmessage(d,wm_char,ord( 'A'),0);
works well, without activating (whatever you mean with that)
perhaps it's the wrong way, but
i'm just looking for the child's handle
Indi
>>You need to activate the target window first so the keys go to it...
cause
g:=findwindow('Notepad',ni
d:=Childwindowfrompoint(g,
sendmessage(d,wm_char,ord(
works well, without activating (whatever you mean with that)
perhaps it's the wrong way, but
i'm just looking for the child's handle
Indi
if you just want to click a button, then they easiest way is to send a "Button Clicked" command to its parent window.
assume "h_Parent" is the handle of your parent window (that you got using enumwindows or findWindow);
You'll need to know the DialogItemID of the button you want to click. (can be found using WinSight32). If you want to find the DlgID using code, then you can use enumchildwindows (or FindWindowEx).
Say "DlgID" is the ItemID of the button, then you can "Click" the button by using:
h_Btn := GetDlgItem(h_parent, DlgID);
PostMessage( h_Parent, wm_Command, DlgID, MakeLong(h_Btn, BN_Clicked));
assume "h_Parent" is the handle of your parent window (that you got using enumwindows or findWindow);
You'll need to know the DialogItemID of the button you want to click. (can be found using WinSight32). If you want to find the DlgID using code, then you can use enumchildwindows (or FindWindowEx).
Say "DlgID" is the ItemID of the button, then you can "Click" the button by using:
h_Btn := GetDlgItem(h_parent, DlgID);
PostMessage( h_Parent, wm_Command, DlgID, MakeLong(h_Btn, BN_Clicked));
indi ,
if the button has a caption of 'Yes' with the Y has a underline for instance
it is '&Yes' (maybe you know ..
anyway you can do this:
var WName : Array[0..99] of Char;
HH : THandle;
//Search Childs
Function TWCallBackChild(H : THandle; V : Longint) : Bool; stdcall;
begin
GetwindowText(H,@WName[0], 100);
if StrPas(@WName[0]) = '&Yes' then
HH := H;
Result := True;
end;
//search Parents
Function TWCallBack(H : THandle; V : Longint) : Bool; stdcall;
begin
GetwindowText(H,@WName[0], 100);
if StrPas(@WName[0]) = '&Yes' then
begin
HH := H;
end
else
EnumChildWindows(H,@TWCall BackChild, V);
Result := True;
end;
procedure TForm1.Button1Click(Sender : TObject);
var Dummy : Longint;
begin
HH := 0;
EnumWindows(@TWCallBack,Du mmy); //Search through the windows
if HH <> 0 then //if found then press
begin
setforegroundwindow(hh);
sendmessage(HH,bm_click,0, 0);//x_cal ibar
end;
end;
end.
an example is open notepad and type something thenpress the x in corner to close notepad it asks to save "yes" "no" "cancel" buttons..
run the code above and it will press the '&Yes' button
if the button has a caption of 'Yes' with the Y has a underline for instance
it is '&Yes' (maybe you know ..
anyway you can do this:
var WName : Array[0..99] of Char;
HH : THandle;
//Search Childs
Function TWCallBackChild(H : THandle; V : Longint) : Bool; stdcall;
begin
GetwindowText(H,@WName[0],
if StrPas(@WName[0]) = '&Yes' then
HH := H;
Result := True;
end;
//search Parents
Function TWCallBack(H : THandle; V : Longint) : Bool; stdcall;
begin
GetwindowText(H,@WName[0],
if StrPas(@WName[0]) = '&Yes' then
begin
HH := H;
end
else
EnumChildWindows(H,@TWCall
Result := True;
end;
procedure TForm1.Button1Click(Sender
var Dummy : Longint;
begin
HH := 0;
EnumWindows(@TWCallBack,Du
if HH <> 0 then //if found then press
begin
setforegroundwindow(hh);
sendmessage(HH,bm_click,0,
end;
end;
end.
an example is open notepad and type something thenpress the x in corner to close notepad it asks to save "yes" "no" "cancel" buttons..
run the code above and it will press the '&Yes' button
ASKER
Sounds good
with enumchildwindows etc.
try to give a code example, please
I'm back tomorrow
hope to cu
Indi
with enumchildwindows etc.
try to give a code example, please
I'm back tomorrow
hope to cu
Indi
ASKER
Ooops
too slow
didn't expect your presence so late, Barry
thought you are still searching for HIM, he,he
thanks everybody for the comments
check it tomorrow
Indi
too slow
didn't expect your presence so late, Barry
thought you are still searching for HIM, he,he
thanks everybody for the comments
check it tomorrow
Indi
ASKER
ps
>> &Yes
As you can read above
it is a foreign program, means, i even don't know in which language it is written
and it is just an OK button
>> &Yes
As you can read above
it is a foreign program, means, i even don't know in which language it is written
and it is just an OK button
ASKER
I see
The O is Underlined
try that
good night everybody
Indi
The O is Underlined
try that
good night everybody
Indi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
....
Keybd_event
....
You need to activate the target window first so the keys go to it...
Alex