Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending data to another application

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi Geniuses!

Can anyone tell me the best way to send data from one application to another. For example, how could I send a filename from one app to another? I've heard you can use wm_CopyData but I'm not sure how to implement it. Any suggestions people?

Clive [infinity]
 
I've been tinkering around with an app that drives another application (not Delphi, not mine) that uses this function:

procedure SendKeys(const text: String);
var
i: Integer;
shift: Boolean;
vk,scancode: Word;
ch: Char;
c,s: Byte;
const
vk_keys: Array[0..9] of Byte =
(VK_HOME,VK_END,VK_UP,VK_DOWN,VK_LEFT,VK_RIGHT,VK_PRIOR,
VK_NEXT,VK_INSERT,VK_DELETE);
vk_shft: Array[0..2] of Byte = (VK_SHIFT,VK_CONTROL,VK_MENU);
flags: Array[false..true] of Integer = (KEYEVENTF_KEYUP, 0);
begin
shift := false;
for i := 1 to Length(text) do
begin
ch := text;
if ch >= #250 then
begin
s := Ord(ch) - 250;
shift := not Odd(s);
c := vk_shft[s shr 1];
scancode := MapVirtualKey(c,0);
Keybd_Event(c,scancode,flags[shift],0);
end
else
begin
vk := 0;
if ch >= #240 then
c := vk_keys[Ord(ch) - 240]
else if ch >= #228 then
c := Ord(ch) - 116 {228 (F1) ==> $70 (vk_F1)}
else if ch < #32 then
c := Ord(ch)
else
begin
vk := VkKeyScan(ch);
c := LoByte(vk);
end;
scancode := MapVirtualKey(c,0);
if not shift and (Hi(vk) > 0) then
Keybd_Event(VK_SHIFT,$2A,0,0);{ $2A = scancode of VK_SHIFT }
Keybd_Event(c,scancode,0,0);
Keybd_Event(c,scancode,KEYEVENTF_KEYUP,0);
if not shift and (Hi(vk) > 0) then
Keybd_Event(VK_SHIFT,$2A,KEYEVENTF_KEYUP,0);
end;
Application.ProcessMessages;
sleep(500);
end;
end;

const
SK_BKSP = #8;
SK_TAB = #9;
SK_ENTER = #13;
{snip lots defined keys}
SK_ALT_DN = #254;
SK_ALT_UP = #255;

This is a piece of the calling code:
MakeWindowActive(MyWindow);
application.ProcessMessages;
SendKeys(SK_ALT_DN +'F');
SendKeys('X');
SendKeys(SK_ALT_UP);
MakeWindowActive(MyWindow2);
SendKeys(SK_ALT_DN +'Y');
SendKeys(SK_ALT_UP);

 
Thanks Scotto but I found an answer which is a bit shorter - I'll post it up as a tip! Clive [infinity]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top